Skip to content
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

Split main into separate function and add entry point #83

Merged
merged 10 commits into from
Aug 21, 2024
6 changes: 5 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
- name: Install conda package
shell: bash -l {0}
run: |
conda install -c conda-forge -c accessnri -c coecms -c file://${{ env.ARTIFACT_LOCATION }} um2nc
conda install -c file://${{ env.ARTIFACT_LOCATION }} -c conda-forge -c accessnri -c coecms um2nc

- name: List installed packages
shell: bash -l {0}
Expand All @@ -93,6 +93,10 @@ jobs:
shell: bash -l {0}
run: pylint --extension-pkg-whitelist=netCDF4 --ignored-modules=umpost -E umpost

- name: Entrypoint test
shell: bash -l {0}
run: esm1p5_convert_nc --help

- name: Run tests
shell: bash -l {0}
run: python -m pytest --cov=umpost --cov-report=xml -s test
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ dependencies = [
"f90nml",
]

[project.scripts]
esm1p5_convert_nc = "umpost.conversion_driver_esm1p5:main"

[tool.versioneer]
VCS = "git"
style = "pep440"
Expand Down
Empty file added umpost/__init__.py
Empty file.
28 changes: 20 additions & 8 deletions umpost/conversion_driver_esm1p5.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,26 +295,33 @@ def safe_removal(succeeded, failed):
return succeeded_inputs - failed_inputs


if __name__ == "__main__":
def parse_args():
"""
Parse arguments given as list (args)
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"current_output_dir", help="ESM1.5 output directory to be converted", type=str
"current_output_dir", help="ESM1.5 output directory to be converted",
type=str
)
parser.add_argument("--quiet", "-q", action="store_true",
help=(
"Report only final exception type and message for allowed"
"exceptions raised during conversion when flag is included."
"Otherwise report full stack trace."
"Report only final exception type and message for "
"allowed exceptions raised during conversion when "
"flag is included. Otherwise report full "
"stack trace."
)
)
parser.add_argument("--delete-ff", "-d", action="store_true",
help="Delete fields files upon successful conversion."
)
args = parser.parse_args()

current_output_dir = args.current_output_dir
return parser.parse_args()


successes, failures = convert_esm1p5_output_dir(current_output_dir)
def main():
args = parse_args()
successes, failures = convert_esm1p5_output_dir(args.current_output_dir)

# Report results to user
for success_message in format_successes(successes):
Expand All @@ -326,3 +333,8 @@ def safe_removal(succeeded, failed):
# Remove files that appear only as successful conversions
for path in safe_removal(successes, failures):
os.remove(path)


if __name__ == "__main__":

main()
Loading