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
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
29 changes: 23 additions & 6 deletions umpost/conversion_driver_esm1p5.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


import os
import sys
import collections
import re
import f90nml
Expand Down Expand Up @@ -295,25 +296,36 @@ def safe_removal(succeeded, failed):
return succeeded_inputs - failed_inputs


if __name__ == "__main__":
def parse_args(args):
truth-quark marked this conversation as resolved.
Show resolved Hide resolved
"""
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()

return parser.parse_args()


def main():
args = parse_args(sys.argv[1:])
truth-quark marked this conversation as resolved.
Show resolved Hide resolved

current_output_dir = args.current_output_dir

# Run conversion
successes, failures = convert_esm1p5_output_dir(current_output_dir)
truth-quark marked this conversation as resolved.
Show resolved Hide resolved

# Report results to user
Expand All @@ -326,3 +338,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