-
Notifications
You must be signed in to change notification settings - Fork 1
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 6 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.""" | ||
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. modulare? 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. Typo must've been made when package was created, Ive fixed that everywhere its found |
||
|
||
# package version | ||
from diffpy.cmi.version import __version__ # noqa | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import getopt | ||
import sys | ||
|
||
from diffpy.cmi.version import __version__ | ||
|
||
|
||
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( | ||
"""\ | ||
|
||
Welcome to diffpy-CMI, a complex modeling infrastructure | ||
designed for multi-modal analysis of scientific data. | ||
While broadly applicable to a wide range of problems, | ||
including those beyond materials science, diffpy-CMI currently | ||
provides robust tools for modeling atomic structure based on | ||
Pair Distribution Function (PDF) and Small-Angle Scattering (SAS) data. | ||
Its modular Python architecture enables extensible workflows, | ||
with additional capabilities continually being developed. | ||
|
||
Docs: https://www.diffpy.org/diffpy.cmi | ||
|
||
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. is pre-commit doing this or can we close up these blank lines? Currently, this is a bit too spread out for my liking.... 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. precommit does a cr for the parenths but i removed the lines |
||
Usage: | ||
diffpy-cmi [--version] [--help] | ||
|
||
Options: | ||
-V, --version Show version and exit | ||
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. why is the V capitalized? Is that some standard coming from Python? If not, let's lower-case it. 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. @sbillinge I capitalized because 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. yes, let's remove the shortcut to remove confusion |
||
-h, --help Show this message and exit | ||
""" | ||
) | ||
|
||
|
||
def version(): | ||
print(f"diffpy-cmi {__version__}") | ||
|
||
|
||
def main(): | ||
try: | ||
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. please do this work using argparse 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. done |
||
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-cmi
orcmi
without-v
or-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-cmi
also returns the same thing as the-h
command.Yeah we can do that!