-
Notifications
You must be signed in to change notification settings - Fork 5
feat: create app for diffpy.cmi CLI #20
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
Changes from 4 commits
31a0e67
ce68bce
8c8a09f
540769b
2cd8244
7e6880c
79b4309
7efdf61
2408c82
ae124b4
7170b07
a247ec6
89328df
fd40eed
b156607
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| **Added:** | ||
|
|
||
| * Add CLI to return diffpy.cmi version and help page. | ||
|
|
||
| **Changed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Removed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,8 @@ | |
| # See LICENSE.rst for license information. | ||
| # | ||
| ############################################################################## | ||
| """Complex modeling infrastructure: a modulare framework for multi-modal modeling of scientific data.""" | ||
| """Complex modeling infrastructure: | ||
| a modulare framework for multi-modal modeling of scientific data.""" | ||
|
||
|
|
||
| # package version | ||
| from diffpy.cmi.version import __version__ # noqa | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import getopt | ||
| import sys | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the reason to use argparse is that it does most of this work for you. It will print usage and help so you don't need those functions. Something like should do everything you want |
||
| def usage(): | ||
| """Print short help message.""" | ||
| print( | ||
| """\ | ||
| DiffPy-CMI is our complex modeling framework. It is a highly flexible library | ||
|
||
| of Python modules for robust modeling of nanostructures in crystals, | ||
| nanomaterials, and amorphous materials. | ||
| Docs: https://www.diffpy.org/diffpy.cmi | ||
| Usage: | ||
| diffpy-cmi [--version] [--help] | ||
|
||
| Options: | ||
| -V, --version Show version and exit | ||
|
||
| -h, --help Show this message and exit | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def version(): | ||
| from diffpy.cmi.version import __version__ | ||
|
||
|
|
||
sbillinge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| print(f"diffpy-cmi {__version__}") | ||
|
|
||
|
|
||
| def main(): | ||
| try: | ||
|
||
| opts, args = getopt.gnu_getopt(sys.argv[1:], "hV", ["help", "version"]) | ||
| except getopt.GetoptError as err: | ||
| print(f"Error: {err}", file=sys.stderr) | ||
| usage() | ||
| sys.exit(1) | ||
|
|
||
| for opt, _ in opts: | ||
| if opt in ("-h", "--help"): | ||
| usage() | ||
| return | ||
| elif opt in ("-V", "--version"): | ||
| version() | ||
| return | ||
|
|
||
| # Default behavior (if no arguments) | ||
| usage() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
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.
shall we also have one that is just
cmi(for lazy people). It can run the same function.Also, what happens if you just type
diffpy-cmiorcmiwithout-vor-h? Let's test that and make sure it behaves in a nice friendly way.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.
@sbillinge just typing
diffpy-cmialso returns the same thing as the-hcommand.Yeah we can do that!