-
Notifications
You must be signed in to change notification settings - Fork 61
Adding fortitude #150
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
Open
mo-lucy-gordon
wants to merge
7
commits into
MetOffice:main
Choose a base branch
from
mo-lucy-gordon:adding_fortitude
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Adding fortitude #150
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0fbd0d7
added fortitude to test suite and a rule
mo-lucy-gordon 2520a91
updated copyrights
mo-lucy-gordon 025a473
updated to fix PEP8 violations
mo-lucy-gordon 25ecd7e
signed contributors page
mo-lucy-gordon ecaf676
corrected message formatting
mo-lucy-gordon c72afdf
Merge branch 'main' into adding_fortitude
mo-lucy-gordon b943adf
removed test from other sites
mo-lucy-gordon 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
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,13 @@ | ||
| ############################################################################## | ||
| # (c) Crown copyright Met Office. All rights reserved. | ||
| # The file LICENCE, distributed with this code, contains details of the terms | ||
| # under which the code may be used. | ||
| ############################################################################## | ||
|
|
||
| [check] | ||
|
|
||
| file-extensions= ["f90", "F90", "X90", "x90", "pf"] #check these file types | ||
|
|
||
| select = ["S101"] | ||
|
|
||
| output-format = "grouped" #group results by file |
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,13 @@ | ||
| ############################################################################## | ||
| # (c) Crown copyright Met Office. All rights reserved. | ||
| # The file LICENCE, distributed with this code, contains details of the terms | ||
| # under which the code may be used. | ||
| ############################################################################## | ||
|
|
||
| [check] | ||
|
|
||
| file-extensions= ["f90", "F90", "X90", "x90", "pf"] #check these file types | ||
|
|
||
| select = ["S101"] | ||
|
|
||
| output-format = "grouped" #group results by file |
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,2 @@ | ||
| [command] | ||
| default=$CYLC_WORKFLOW_RUN_DIR/bin/fortitude_launcher.py -s $SOURCE_ROOT/lfric_apps |
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,87 @@ | ||
| #!/usr/bin/env python3 | ||
| ############################################################################## | ||
| # (c) Crown copyright Met Office. All rights reserved. | ||
| # The file LICENCE, distributed with this code, contains details of the terms | ||
| # under which the code may be used. | ||
| ############################################################################## | ||
|
|
||
| """ | ||
| Launch fortitude on list of directories. Run on all and print outputs. | ||
| Fail if any style changes required. | ||
| """ | ||
|
|
||
| import sys | ||
| import os | ||
| import subprocess | ||
| import argparse | ||
|
|
||
|
|
||
| def launch_fortitude(config_path, app_path): | ||
| """ | ||
| Launch fortitude as a subprocess command and check the output | ||
| """ | ||
|
|
||
| command = f"fortitude --config-file {config_path} check {app_path}" | ||
| result = subprocess.run(command.split(), capture_output=True, text=True) | ||
|
|
||
| print(result.stdout) | ||
| return result | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser( | ||
| description="Run fortitude on all applications. If " | ||
| "application/fortitude.toml exists use that file, otherwise " | ||
| "use one in rose-stem/app/check_fortitude_linter/file. " | ||
| "Print output, raise error if any changes required." | ||
| ) | ||
| parser.add_argument( | ||
| "-s", | ||
| "--source", | ||
| help="The top level of lfric_apps directory.", | ||
| required=True, | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| failed_apps = {} | ||
|
|
||
| for top_dir in ["applications", "science"]: | ||
| applications = os.listdir(os.path.join(args.source, top_dir)) | ||
| for app in applications: | ||
| print(f"Running on {app}\n") | ||
| app_path = os.path.join(args.source, top_dir, app) | ||
| config_path = os.path.join(app_path, "fortitude.toml") | ||
| if not os.path.exists(os.path.join(config_path)): | ||
| print("Using universal config (toml) file." | ||
| " (Some apps use their own config file.)") | ||
| config_path = os.path.join( | ||
| args.source, | ||
| "rose-stem", | ||
| "app", | ||
| "check_fortitude_linter", | ||
| "file", | ||
| "fortitude.toml", | ||
| ) | ||
| result = launch_fortitude(config_path, app_path) | ||
| if result.returncode: | ||
| # prints the app run on if there are errors of any kind | ||
| print(f"Checking: {app} \n", file=sys.stderr) | ||
| if not result.stderr: | ||
| # prints if no other/config errors are found | ||
| print("Found lint errors:", file=sys.stderr) | ||
| # prints the lint errors | ||
| print(result.stdout, file=sys.stderr) | ||
| if result.stderr: | ||
| # prints if there are other/config errors | ||
| print("Found non-lint errors: \n", file=sys.stderr) | ||
| # prints the other/config errors | ||
| print(result.stderr, "\n\n\n", file=sys.stderr) | ||
| failed_apps[app] = result.stderr | ||
|
|
||
| if failed_apps: | ||
| error_message = "" | ||
| print("\n\n\nSummary: Fortitude found errors in" | ||
| " the following repositories:\n", file=sys.stderr) | ||
| for failed in failed_apps: | ||
| error_message += f"{failed}\n" | ||
| sys.exit(error_message) | ||
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
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.
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.
This should probably be a positional argument as it's required. You can force that by removing the
-sargument and changing--sourceto justsource. Then you'll need to remove the-sfrom the call in the rose-app.conf