Skip to content

Commit

Permalink
Fixes for less used options of "mepo clone" (#335)
Browse files Browse the repository at this point in the history
* Fixed a couple of bugs

1. shutil is required if --registry is passed
2. The function checkout_all_repos has the arg branch passed to it, not args, so use that instead

* Added a test for mepo clone --allrepos

* Added test for mepo clone --registry

* Added Changelong entry, fixed test, made formatter happy

* Bumped version

* Fixed typo in Changelog

* Fixed test for checking version
  • Loading branch information
pchakraborty authored Jan 3, 2025
1 parent 72d2a6f commit 26fc827
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 4 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [2.2.1] - 2025-01-03

### Fixed

- Fixed bugs in the lesser used options of `mepo clone`, `allrepos` and `registry`


### Added

- Added tests for `mepo clone --allrepos` and `mepo clone --registry`


## [2.2.0] - 2024-12-24


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "mepo"
version = "2.2.0"
version = "2.2.1"
description = "A tool for managing (m)ultiple r(epo)s"
authors = [{name="GMAO SI Team", email="[email protected]"}]
dependencies = [
Expand Down
5 changes: 3 additions & 2 deletions src/mepo/command/clone.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil
import pathlib
from urllib.parse import urlparse
from types import SimpleNamespace
Expand Down Expand Up @@ -119,7 +120,7 @@ def checkout_all_repos(allcomps, branch):
if branch is None:
raise RuntimeError("`allrepos` option must be used with a branch/tag.")
for comp in allcomps:
branch_y = colors.YELLOW + args.branch + colors.RESET
branch_y = colors.YELLOW + branch + colors.RESET
print(f"Checking out {branch_y} in {comp.name}")
git = GitRepository(comp.remote, comp.local)
git.checkout(args.branch)
git.checkout(branch)
52 changes: 52 additions & 0 deletions tests/input/external-components.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
GEOSfvdycore:
fixture: true
develop: main

env:
local: ./@env
remote: https://github.com/GEOS-ESM/ESMA_env.git
tag: v4.29.1
develop: main

cmake:
local: ./@cmake
remote: https://github.com/GEOS-ESM/ESMA_cmake.git
tag: v3.55.0
develop: develop

ecbuild:
local: ./@cmake/@ecbuild
remote: https://github.com/GEOS-ESM/ecbuild.git
tag: geos/v1.4.0

GMAO_Shared:
local: ./src/Shared/@GMAO_Shared
remote: https://github.com/GEOS-ESM/GMAO_Shared.git
branch: mepo-testing-do-not-delete
sparse: ./config/GMAO_Shared.sparse
develop: main

GEOS_Util:
local: ./src/Shared/@GMAO_Shared/@GEOS_Util
remote: https://github.com/GEOS-ESM/GEOS_Util.git
tag: v2.1.3
develop: main

FMS:
local: ./src/Shared/@FMS
remote: https://github.com/GEOS-ESM/FMS.git
tag: geos/2019.01.02+noaff.10
develop: geos/release/2019.01

FVdycoreCubed_GridComp:
local: ./src/Components/@FVdycoreCubed_GridComp
remote: https://github.com/GEOS-ESM/FVdycoreCubed_GridComp.git
branch: develop
develop: develop

fvdycore:
local: ./src/Components/@FVdycoreCubed_GridComp/@fvdycore
remote: https://github.com/GEOS-ESM/GFDL_atmos_cubed_sphere.git
branch: geos/develop
develop: geos/develop

1 change: 1 addition & 0 deletions tests/output/output_branch_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ ecbuild | * (HEAD detached at geos/v1.3.0)
| remotes/origin/feature/netcdf4-cmake
| remotes/origin/geos/main
| remotes/origin/master
| remotes/origin/mepo-testing-do-not-delete
| remotes/origin/release/stable
62 changes: 62 additions & 0 deletions tests/test_mepo_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

FIXTURE_NAME = "GEOSfvdycore-mepo-testing"
FIXTURE_URL = f"https://github.com/pchakraborty/{FIXTURE_NAME}.git"
TEST_DIR = os.path.dirname(os.path.realpath(__file__))


def get_mepo_status():
Expand Down Expand Up @@ -89,3 +90,64 @@ def test_mepo_clone_url_branch_directory():
status_output = get_mepo_status()
assert status_output == saved_output
shutil.rmtree(DIRECTORY)


def test_mepo_clone_url_branch_allrepos():
if os.path.isdir(FIXTURE_NAME):
shutil.rmtree(FIXTURE_NAME)
args = SimpleNamespace(
style="prefix",
registry=None,
url=FIXTURE_URL,
branch="mepo-testing-do-not-delete",
directory=None,
partial="blobless",
allrepos=True,
)
mepo_clone.run(args)
saved_output = """Checking status...
GEOSfvdycore | (b) mepo-testing-do-not-delete
env | (b) mepo-testing-do-not-delete
cmake | (b) mepo-testing-do-not-delete
ecbuild | (b) mepo-testing-do-not-delete
GMAO_Shared | (b) mepo-testing-do-not-delete
GEOS_Util | (b) mepo-testing-do-not-delete
FMS | (b) mepo-testing-do-not-delete
FVdycoreCubed_GridComp | (b) mepo-testing-do-not-delete
fvdycore | (b) mepo-testing-do-not-delete
"""
with contextlib_chdir(FIXTURE_NAME):
status_output = get_mepo_status()
assert status_output == saved_output
shutil.rmtree(FIXTURE_NAME)


def test_mepo_clone_url_external_registry():
if os.path.isdir(FIXTURE_NAME):
shutil.rmtree(FIXTURE_NAME)
args = SimpleNamespace(
style="prefix",
registry=os.path.join(TEST_DIR, "input/external-components.yaml"),
url=FIXTURE_URL,
branch="mepo-testing-do-not-delete",
directory=None,
partial="blobless",
allrepos=False,
)
mepo_clone.run(args)
saved_output = """Checking status...
GEOSfvdycore | (b) mepo-testing-do-not-delete
| external-components.yaml: \x1b[31muntracked file\x1b[0m
env | (t) v4.29.1 (DH)
cmake | (t) v3.55.0 (DH)
ecbuild | (t) geos/v1.4.0 (DH)
GMAO_Shared | (b) mepo-testing-do-not-delete
GEOS_Util | (t) v2.1.3 (DH)
FMS | (t) geos/2019.01.02+noaff.10 (DH)
FVdycoreCubed_GridComp | (b) develop
fvdycore | (b) geos/develop
"""
with contextlib_chdir(FIXTURE_NAME):
status_output = get_mepo_status()
assert status_output == saved_output
shutil.rmtree(FIXTURE_NAME)
2 changes: 1 addition & 1 deletion tests/test_mepo_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def test_reset(self):
self.__class__.__mepo_clone()

def test_mepo_version(self):
self.assertEqual(get_mepo_version(), "2.2.0")
self.assertEqual(get_mepo_version(), "2.2.1")

def tearDown(self):
pass
Expand Down

0 comments on commit 26fc827

Please sign in to comment.