Skip to content

Commit

Permalink
Merge pull request #219 from GEOS-ESM/develop
Browse files Browse the repository at this point in the history
Merge develop into main for release
  • Loading branch information
mathomp4 authored Mar 25, 2022
2 parents 16ab05a + 540ad29 commit d8d2abc
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 49 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/mepo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ jobs:
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
timeout-minutes: 1

- name: Run unit tests
run: python mepo.d/utest/test_mepo_commands.py -v
run: python3 mepo.d/utest/test_mepo_commands.py -v
timeout-minutes: 2
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

## [1.41.0] - 2022-03-25

### Changed

- Changed the default behavior of `compare` to only show differing repos. Use `--all` to see all repos
- Add `--nocolor` option to `status` and `compare` (for unit testing)
- Add `--wrap` option to `compare` (for unit testing)
- Updated unit tests for new `compare` behavior

## [1.40.0] - 2022-01-12

### Fixed
Expand Down
19 changes: 18 additions & 1 deletion mepo.d/cmdline/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def __status(self):
'--ignore-permissions',
action = 'store_true',
help = 'Tells command to ignore changes in file permissions.')
status.add_argument(
'--nocolor',
action = 'store_true',
help = 'Tells status to not display colors.')

def __restore_state(self):
restore_state = self.subparsers.add_parser(
Expand Down Expand Up @@ -296,8 +300,21 @@ def __pull_all(self):
def __compare(self):
compare = self.subparsers.add_parser(
'compare',
description = 'Compare current and original states of all components',
description = 'Compare current and original states of all components. '
'Will only show differing repos unless --all is passed in',
aliases=mepoconfig.get_command_alias('compare'))
compare.add_argument(
'--all',
action = 'store_true',
help = 'Show all repos, not only differing repos')
compare.add_argument(
'--nocolor',
action = 'store_true',
help = 'Tells command to not display colors.')
compare.add_argument(
'--wrap',
action = 'store_true',
help = 'Tells command to ignore terminal size and wrap')

def __whereis(self):
whereis = self.subparsers.add_parser(
Expand Down
41 changes: 33 additions & 8 deletions mepo.d/command/compare/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,24 @@

def run(args):
allcomps = MepoState.read_state()
max_namelen, max_origlen = calculate_header_lengths(allcomps)
print_header(max_namelen, max_origlen)

if not any_differing_repos(allcomps):
print(f'No repositories have changed')
else:
max_namelen, max_origlen = calculate_header_lengths(allcomps)
print_header(max_namelen, max_origlen)
for comp in allcomps:
git = GitRepository(comp.remote, comp.local)
curr_ver = version_to_string(git.get_version(),git)
orig_ver = version_to_string(comp.version,git)

# This command is to try and work with git tag oddities
curr_ver = sanitize_version_string(orig_ver,curr_ver,git)

print_cmp(comp.name, orig_ver, curr_ver, max_namelen, max_origlen, args.all, args.nocolor, args.wrap)

def any_differing_repos(allcomps):

for comp in allcomps:
git = GitRepository(comp.remote, comp.local)
curr_ver = version_to_string(git.get_version(),git)
Expand All @@ -18,7 +34,10 @@ def run(args):
# This command is to try and work with git tag oddities
curr_ver = sanitize_version_string(orig_ver,curr_ver,git)

print_cmp(comp.name, orig_ver, curr_ver, max_namelen, max_origlen)
if curr_ver not in orig_ver:
return True

return False

def calculate_header_lengths(allcomps):
names = []
Expand All @@ -37,13 +56,18 @@ def print_header(max_namelen, max_origlen):
print(FMTHEAD.format("Repo","Original","Current"))
print(FMTHEAD.format("-"*80,"-"*max_origlen,"-"*7))

def print_cmp(name, orig, curr, name_width, orig_width):
def print_cmp(name, orig, curr, name_width, orig_width, all_repos=False, nocolor=False, wrap=False):
name_blank = ''
#if orig not in curr:
if curr not in orig:
name = colors.RED + name + colors.RESET
name_blank = colors.RED + name_blank + colors.RESET
name_width += len(colors.RED) + len(colors.RESET)
if not nocolor:
name = colors.RED + name + colors.RESET
name_blank = colors.RED + name_blank + colors.RESET
name_width += len(colors.RED) + len(colors.RESET)
else:
# This only prints differing repos unless --all is passed in
if not all_repos:
return
FMT_VAL = (name_width, name_width, orig_width)

FMT0 = '{:<%s.%ss} | {:<%ss} | {:<s}' % FMT_VAL
Expand All @@ -52,8 +76,9 @@ def print_cmp(name, orig, curr, name_width, orig_width):

columns, lines = get_terminal_size(fallback=(80,20))

if len(FMT0.format(name, orig, curr)) > columns:
if (not wrap) and (len(FMT0.format(name, orig, curr)) > columns):
print(FMT1.format(name, orig + ' ...'))
print(FMT2.format(name_blank, '...', curr))
else:
print(FMT0.format(name, orig, curr))

11 changes: 6 additions & 5 deletions mepo.d/command/status/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def run(args):
pool = mp.Pool()
atexit.register(pool.close)
result = pool.starmap(check_component_status, [(comp, args.ignore_permissions) for comp in allcomps])
print_status(allcomps, result)
print_status(allcomps, result, args.nocolor)

def check_component_status(comp, ignore):
git = GitRepository(comp.remote, comp.local)
Expand All @@ -32,7 +32,7 @@ def check_component_status(comp, ignore):

return (curr_ver, internal_state_branch_name, git.check_status(ignore))

def print_status(allcomps, result):
def print_status(allcomps, result, nocolor=False):
orig_width = len(max([comp.name for comp in allcomps], key=len))
for index, comp in enumerate(allcomps):
time.sleep(0.025)
Expand All @@ -42,9 +42,10 @@ def print_status(allcomps, result):
if current_version.split()[1] == comp.version.name:
component_name = comp.name
width = orig_width
# Check to see if the current tag/branch is the same as the original...
# if the above check didn't succeed, we are different.
elif internal_state_branch_name not in comp.version.name:
# Check to see if the current tag/branch is the same as the
# original... if the above check didn't succeed, we are
# different and we colorize if asked for
elif (internal_state_branch_name not in comp.version.name) and not nocolor:
component_name = colors.RED + comp.name + colors.RESET
width = orig_width + len(colors.RED) + len(colors.RESET)
else:
Expand Down
16 changes: 8 additions & 8 deletions mepo.d/utest/input/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,48 @@ GEOSfvdycore:
env:
local: ./@env
remote: ../ESMA_env.git
tag: v3.2.1
tag: v3.13.0
develop: main

cmake:
local: ./@cmake
remote: ../ESMA_cmake.git
tag: v3.4.2
tag: v3.12.0
develop: develop

ecbuild:
local: ./@cmake/@ecbuild
remote: ../ecbuild.git
tag: geos/v1.0.6
tag: geos/v1.2.0

GMAO_Shared:
local: ./src/Shared/@GMAO_Shared
remote: ../GMAO_Shared.git
tag: v1.4.1
tag: v1.5.3
sparse: ./config/GMAO_Shared.sparse
develop: main

MAPL:
local: ./src/Shared/@MAPL
remote: ../MAPL.git
tag: v2.7.0
tag: v2.19.0
develop: develop

FMS:
local: ./src/Shared/@FMS
remote: ../FMS.git
tag: geos/2019.01.02+noaff.7
tag: geos/2019.01.02+noaff.8
develop: geos/release/2019.01

FVdycoreCubed_GridComp:
local: ./src/Components/@FVdycoreCubed_GridComp
remote: ../FVdycoreCubed_GridComp.git
tag: v1.2.15
tag: v1.6.0
develop: develop

fvdycore:
local: ./src/Components/@FVdycoreCubed_GridComp/@fvdycore
remote: ../GFDL_atmos_cubed_sphere.git
tag: geos/v1.1.6
tag: geos/v1.3.0
develop: geos/develop

5 changes: 5 additions & 0 deletions mepo.d/utest/output/compare_brief_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Repo | Original | Current
---------------------- | -------------------------------- | -------
env | (t) v3.13.0 (DH) | (b) main
cmake | (t) v3.12.0 (DH) | (b) develop
fvdycore | (t) geos/v1.3.0 (DH) | (b) geos/develop
11 changes: 11 additions & 0 deletions mepo.d/utest/output/compare_full_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Repo | Original | Current
---------------------- | -------------------------------- | -------
GEOSfvdycore | (t) v1.5.0 (DH) | (t) v1.5.0 (DH)
env | (t) v3.13.0 (DH) | (b) main
cmake | (t) v3.12.0 (DH) | (b) develop
ecbuild | (t) geos/v1.2.0 (DH) | (t) geos/v1.2.0 (DH)
GMAO_Shared | (t) v1.5.3 (DH) | (t) v1.5.3 (DH)
MAPL | (t) v2.19.0 (DH) | (t) v2.19.0 (DH)
FMS | (t) geos/2019.01.02+noaff.8 (DH) | (t) geos/2019.01.02+noaff.8 (DH)
FVdycoreCubed_GridComp | (t) v1.6.0 (DH) | (t) v1.6.0 (DH)
fvdycore | (t) geos/v1.3.0 (DH) | (b) geos/develop
11 changes: 0 additions & 11 deletions mepo.d/utest/output/compare_no_change.txt

This file was deleted.

18 changes: 9 additions & 9 deletions mepo.d/utest/output/status_output.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Checking status...
GEOSfvdycore | (t) v1.2.7 (DH)
env | (t) v3.2.1 (DH)
cmake | (t) v3.4.2 (DH)
ecbuild | (t) geos/v1.0.6 (DH)
GMAO_Shared | (t) v1.4.1 (DH)
MAPL | (t) v2.7.0 (DH)
FMS | (t) geos/2019.01.02+noaff.7 (DH)
FVdycoreCubed_GridComp | (t) v1.2.15 (DH)
fvdycore | (t) geos/v1.1.6 (DH)
GEOSfvdycore | (t) v1.5.0 (DH)
env | (b) main
cmake | (b) develop
ecbuild | (t) geos/v1.2.0 (DH)
GMAO_Shared | (t) v1.5.3 (DH)
MAPL | (t) v2.19.0 (DH)
FMS | (t) geos/2019.01.02+noaff.8 (DH)
FVdycoreCubed_GridComp | (t) v1.6.0 (DH)
fvdycore | (b) geos/develop
43 changes: 37 additions & 6 deletions mepo.d/utest/test_mepo_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@

from input import args

from command.init import init as mepo_init
from command.clone import clone as mepo_clone
from command.list import list as mepo_list
from command.status import status as mepo_status
from command.init import init as mepo_init
from command.clone import clone as mepo_clone
from command.list import list as mepo_list
from command.status import status as mepo_status
from command.compare import compare as mepo_compare
from command.develop import develop as mepo_develop

class TestMepoCommands(unittest.TestCase):

maxDiff=None

@classmethod
def __checkout_fixture(cls):
remote = 'https://github.com/GEOS-ESM/{}.git'.format(cls.fixture)
Expand All @@ -34,13 +38,13 @@ def setUpClass(cls):
cls.input_dir = os.path.join(THIS_DIR, 'input')
cls.output_dir = os.path.join(THIS_DIR, 'output')
cls.fixture = 'GEOSfvdycore'
cls.tag = 'v1.2.7'
cls.tag = 'v1.5.0'
cls.tmpdir = os.path.join(THIS_DIR, 'tmp')
cls.fixture_dir = os.path.join(cls.tmpdir, cls.fixture)
if os.path.isdir(cls.fixture_dir):
shutil.rmtree(cls.fixture_dir)
cls.__checkout_fixture()
cls.__copy_config_file()
#cls.__copy_config_file()
args.config = 'components.yaml'
args.style = 'prefix'
os.chdir(cls.fixture_dir)
Expand All @@ -50,6 +54,10 @@ def setUpClass(cls):
args.branch = None
args.directory = None
mepo_clone.run(args)
# In order to better test compare, we need to do *something*
args.comp_name = ['env','cmake','fvdycore']
args.quiet = False
mepo_develop.run(args)

def setUp(self):
pass
Expand All @@ -65,12 +73,35 @@ def test_list(self):
def test_status(self):
sys.stdout = output = StringIO()
args.ignore_permissions=False
args.nocolor=True
mepo_status.run(args)
sys.stdout = sys.__stdout__
with open(os.path.join(self.__class__.output_dir, 'status_output.txt'), 'r') as fin:
saved_output = fin.read()
self.assertEqual(output.getvalue(), saved_output)

def test_compare_brief(self):
sys.stdout = output = StringIO()
args.all=False
args.nocolor=True
args.wrap=True
mepo_compare.run(args)
sys.stdout = sys.__stdout__
with open(os.path.join(self.__class__.output_dir, 'compare_brief_output.txt'), 'r') as fin:
saved_output = fin.read()
self.assertEqual(output.getvalue(), saved_output)

def test_compare_full(self):
sys.stdout = output = StringIO()
args.all=True
args.nocolor=True
args.wrap=True
mepo_compare.run(args)
sys.stdout = sys.__stdout__
with open(os.path.join(self.__class__.output_dir, 'compare_full_output.txt'), 'r') as fin:
saved_output = fin.read()
self.assertEqual(output.getvalue(), saved_output)

def tearDown(self):
pass

Expand Down

0 comments on commit d8d2abc

Please sign in to comment.