-
Notifications
You must be signed in to change notification settings - Fork 50
Set up beginning CI and add YAML check script #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
03975e0
Start of attempt for CMake and python norms test
CoryMartin-NOAA f1353bc
Fix coding norms
CoryMartin-NOAA bf7bd39
Working first unit test
CoryMartin-NOAA 22eb825
ensure GDASApp everywhere
CoryMartin-NOAA 815310b
CMAKE to PROJECT
CoryMartin-NOAA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| name: Check Python Coding Norms | ||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| check_pynorms: | ||
| runs-on: ubuntu-latest | ||
| name: Check Python coding norms with pycodestyle | ||
|
|
||
| steps: | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| pip install --upgrade pip | ||
| pip install pycodestyle | ||
| - name: Checkout | ||
| uses: actions/checkout@v2 | ||
| with: | ||
| path: GDASapp | ||
|
|
||
| - name: Run pycodestyle | ||
| run: | | ||
| cd $GITHUB_WORKSPACE/GDASapp | ||
| pycodestyle -v --config ./.pycodestyle . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: Run Unit Tests | ||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| ctests: | ||
| runs-on: ubuntu-latest | ||
| name: Run Unit Tests with ctest | ||
|
|
||
| steps: | ||
|
|
||
| - name: Checkout | ||
| uses: actions/checkout@v2 | ||
| with: | ||
| path: GDASapp | ||
|
|
||
| - name: Configure with cmake | ||
| run: | | ||
| cd $GITHUB_WORKSPACE/GDASapp | ||
| mkdir build | ||
| cd build | ||
| cmake ../ | ||
|
|
||
| - name: Build GDASapp | ||
| run: | | ||
| cd $GITHUB_WORKSPACE/GDASapp/build | ||
| make | ||
|
|
||
| - name: Run ctest | ||
| run: | | ||
| cd $GITHUB_WORKSPACE/GDASapp/build | ||
| ctest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [pycodestyle] | ||
| count = False | ||
| ignore = E226,E401,E402,W504 | ||
| max-line-length = 160 | ||
| statistics = True | ||
| exclude = Experimental |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| cmake_minimum_required(VERSION 3.10) | ||
|
|
||
| # set the project name | ||
| project(GDAS) | ||
|
|
||
| find_package(Python3 REQUIRED COMPONENTS Interpreter) | ||
|
|
||
| enable_testing() | ||
|
|
||
| add_subdirectory(test) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| add_test(NAME test_check_yaml_keys | ||
| COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/ush/check_yaml_keys.py ${CMAKE_SOURCE_DIR}/test/testinput/check_yaml_keys_ref.yaml ${CMAKE_SOURCE_DIR}/test/testinput/check_yaml_keys_test.yaml | ||
| WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test/) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| app: GDAS | ||
| components: | ||
| - name: atmosphere | ||
| model: FV3 | ||
| - name: ocean | ||
| model: MOM6 | ||
| - name: ice | ||
| model: CICE6 | ||
| - name: aerosols | ||
| model: GOCART | ||
| - name: land | ||
| model: noah |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| app: GDAS | ||
| components: | ||
| - name: atmosphere | ||
| model: FV3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #!/usr/bin/env python3 | ||
| # compare keys between two YAML files | ||
| import argparse | ||
| import logging | ||
| import os | ||
| import yaml | ||
|
|
||
|
|
||
| def check_yaml(YAMLref, YAMLtest, checkValues=False): | ||
| assert os.path.exists(YAMLref), f"File {YAMLref} not found." | ||
| assert os.path.exists(YAMLtest), f"File {YAMLtest} not found." | ||
| logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S') | ||
| logging.info(f'Comparing {YAMLtest} against {YAMLref}...') | ||
| # load reference file | ||
| try: | ||
| with open(YAMLref, 'r') as YAMLref_opened: | ||
| ref_dict = yaml.safe_load(YAMLref_opened) | ||
| except Exception as e: | ||
| logging.error(f'Error occurred when attempting to load: {YAMLref}, error: {e}') | ||
| # load file to test | ||
| try: | ||
| with open(YAMLtest, 'r') as YAMLtest_opened: | ||
| test_dict = yaml.safe_load(YAMLtest_opened) | ||
| except Exception as e: | ||
| logging.error(f'Error occurred when attempting to load: {YAMLtest}, error: {e}') | ||
| # loop through top level of YAML | ||
| compare_dict('', ref_dict, test_dict, checkValues) | ||
|
|
||
|
|
||
| def compare_dict(rootkey, dict1, dict2, checkValues): | ||
| for key, value in dict1.items(): | ||
| keypath = f"{rootkey}/{key}" | ||
| if key not in dict2: | ||
| logging.error(f"'{keypath}' not in test file.") | ||
| else: | ||
| if isinstance(value, dict): | ||
| compare_dict(keypath, value, dict2[key], checkValues) | ||
| elif isinstance(value, list): | ||
| compare_list(keypath, value, dict2[key], checkValues) | ||
| else: | ||
| if checkValues: | ||
| if value != dict2[key]: | ||
| logging.warning(f"{keypath}: {dict2[key]} != {value}") | ||
|
|
||
|
|
||
| def compare_list(rootkey, list1, list2, checkValues): | ||
| if len(list2) != len(list1): | ||
| logging.error(f"{rootkey} len={len(list2)} != {len(list1)}") | ||
| for i, item in enumerate(list1): | ||
| newkey = f"{rootkey}[{i}]" | ||
| if i+1 <= len(list2): | ||
| if isinstance(item, dict) and i+1 <= len(list2): | ||
| compare_dict(newkey, item, list2[i], checkValues) | ||
| elif isinstance(item, list): | ||
| compare_list(newkey, item, list2[i], checkValues) | ||
| else: | ||
| if checkValues: | ||
| if item != list2[i]: | ||
| logging.warning(f"{rootkey}/{i}: {list2[i]} != {item}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('YAMLref', type=str, help='Reference YAML file') | ||
| parser.add_argument('YAMLtest', type=str, help='YAML file to compare to reference') | ||
| parser.add_argument("--checkvalues", help="Check values in addition to keys", | ||
| action="store_true") | ||
| args = parser.parse_args() | ||
| check_yaml(args.YAMLref, args.YAMLtest, args.checkvalues) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Though, I would suggest using
${PROJECT_SOURCE_DIR}instead. The use of which will become clear when GDASApp is included as a project inside another project.Same for
${PROJECT_BINARY_DIR}