-
Notifications
You must be signed in to change notification settings - Fork 66
Add script to check fortran vs metadata without a host model #558
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
91 changes: 91 additions & 0 deletions
91
scripts/fortran_tools/offline_check_fortran_vs_metadata.py
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,91 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| """ | ||
| Recursively compare all fortran and metadata files in user-supplied directory, and report any problems | ||
| USAGE: | ||
| ./offline_check_fortran_vs_metadata.py --directory <full path to directory with scheme files> (--debug) | ||
| """ | ||
|
|
||
|
|
||
| import sys | ||
| import os | ||
| import glob | ||
| import logging | ||
| import argparse | ||
| import site | ||
| # Enable imports from parent directory | ||
| site.addsitedir(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
|
|
||
| # CCPP framework imports | ||
|
gold2718 marked this conversation as resolved.
|
||
| from framework_env import CCPPFrameworkEnv | ||
| from fortran_tools import parse_fortran_file | ||
| from metadata_table import parse_metadata_file | ||
| from ccpp_capgen import find_associated_fortran_file | ||
| from ccpp_capgen import parse_scheme_files | ||
| from parse_tools import init_log, set_log_level | ||
| from parse_tools import register_fortran_ddt_name | ||
| from parse_tools import CCPPError, ParseInternalError | ||
|
|
||
| _LOGGER = init_log(os.path.basename(__file__)) | ||
| _DUMMY_RUN_ENV = CCPPFrameworkEnv(_LOGGER, ndict={'host_files':'', | ||
| 'scheme_files':'', | ||
| 'suites':''}) | ||
|
|
||
| def find_files_to_compare(directory): | ||
| metadata_files = [] | ||
| for file in glob.glob(os.path.join(directory,'**','*.meta'), recursive=True): | ||
| metadata_files.append(file) | ||
| # end for | ||
| return metadata_files | ||
|
|
||
| def compare_fortran_and_metadata(scheme_directory, run_env): | ||
| ## Check for files | ||
| metadata_files = find_files_to_compare(scheme_directory) | ||
| # Perform checks | ||
| parse_scheme_files(metadata_files, run_env, skip_ddt_check=True) | ||
|
|
||
| def parse_command_line(arguments, description): | ||
| """Parse command-line arguments""" | ||
| parser = argparse.ArgumentParser(description=description, | ||
| formatter_class=argparse.RawTextHelpFormatter) | ||
| parser.add_argument("--directory", type=str, required=True, | ||
| metavar='top-level directory to analyze - REQUIRED', | ||
| help="""Full path to scheme directory""") | ||
| parser.add_argument("--debug", action='store_true', default=False, | ||
| help="""turn on debug mode for additional verbosity""") | ||
| pargs = parser.parse_args(arguments) | ||
| return pargs | ||
|
|
||
| def _main_func(): | ||
| """Parse command line, then parse indicated host, scheme, and suite files. | ||
| Finally, generate code to allow host model to run indicated CCPP suites.""" | ||
| pargs = parse_command_line(sys.argv[1:], __doc__) | ||
| logger = _LOGGER | ||
| if pargs.debug: | ||
| set_log_level(logger, logging.DEBUG) | ||
| else: | ||
| set_log_level(logger, logging.INFO) | ||
| # end if | ||
| compare_fortran_and_metadata(pargs.directory, _DUMMY_RUN_ENV) | ||
| print('All checks passed!') | ||
|
|
||
| ############################################################################### | ||
|
|
||
| if __name__ == "__main__": | ||
| try: | ||
| _main_func() | ||
| sys.exit(0) | ||
| except ParseInternalError as pie: | ||
| _LOGGER.exception(pie) | ||
| sys.exit(-1) | ||
| except CCPPError as ccpp_err: | ||
| if _LOGGER.getEffectiveLevel() <= logging.DEBUG: | ||
| _LOGGER.exception(ccpp_err) | ||
| else: | ||
| _LOGGER.error(ccpp_err) | ||
| # end if | ||
| sys.exit(1) | ||
| finally: | ||
| logging.shutdown() | ||
| # end try | ||
|
|
||
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
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
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.