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

Need main functions or similar for entry points in conda #81

Closed
aidanheerdegen opened this issue Aug 21, 2024 · 4 comments
Closed

Need main functions or similar for entry points in conda #81

aidanheerdegen opened this issue Aug 21, 2024 · 4 comments

Comments

@aidanheerdegen
Copy link
Member

aidanheerdegen commented Aug 21, 2024

The conda deployment supports creating nice entry points, e.g. the ability to just call um2nc from the command line. For this to work e'll need main or similar functions defined, as entry points need to point at a function.

See this related PR where entry points were removed because there were no suitable functions:

#74 (comment)

I started using the pattern shown below as a pretty standard approach in case it's useful

https://github.com/ACCESS-NRI/ncigrafana/blob/master/ncigrafana/parse_lquota.py#L146-L174

The corresponding entry point definition is

https://github.com/ACCESS-NRI/ncigrafana/blob/master/setup.cfg#L34

The point of this approach was to allow for the argument parsing to be tested independently of the call to main, and also allows for testing main directly in pytest, without the need for an entrypoint script (though I don't believe I actually had those tests in this case ... )

@aidanheerdegen
Copy link
Member Author

@blimlim if you want/need a post-processing script to be accessible as a command you should specify the requirements in this issue.

@blimlim
Copy link
Collaborator

blimlim commented Aug 21, 2024

It would be great to have the post-processing script available as a command. Specifically we'd want an entry point to the __main__ block in conversion_driver_esm1p5.py

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"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."
)
)
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
successes, failures = convert_esm1p5_output_dir(current_output_dir)
# Report results to user
for success_message in format_successes(successes):
print(success_message)
for failure_message in format_failures(failures, args.quiet):
warnings.warn(failure_message)
if args.delete_ff:
# Remove files that appear only as successful conversions
for path in safe_removal(successes, failures):
os.remove(path)

Which hopefully should be pretty straightforward to adapt with the pattern in your example. Should I add a PR doing this?

@truth-quark
Copy link
Collaborator

@aidanheerdegen are you happy this issue is complete with #83 and #86 ?

@aidanheerdegen
Copy link
Member Author

Yep! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants