-
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
31a0e67
pre-commit: line length fix
cadenmyers13 ce68bce
feat: CLI in pyproject.toml
cadenmyers13 8c8a09f
feat: add app file for CLI
cadenmyers13 540769b
chore: news
cadenmyers13 2cd8244
chore: move import to the top and edit description
cadenmyers13 7e6880c
change test.txt to tests.txt based on new skpkg syntax
cadenmyers13 79b4309
doc: change test to tests in docs
cadenmyers13 7efdf61
bug: change version() to print_version()
cadenmyers13 2408c82
feat: add cmi to pyproject.toml for CLI
cadenmyers13 ae124b4
feat: add new function for invalid input and remove -V flag
cadenmyers13 7170b07
chore: fix modulare in short description across 3 files
cadenmyers13 a247ec6
feat: migration main() to argparse
cadenmyers13 89328df
feat: use argsparse description feature
cadenmyers13 fd40eed
change diffpy-cmi to diffpy.cmi
cadenmyers13 b156607
style: remove extra lines
cadenmyers13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ authors = [ | |
maintainers = [ | ||
{ name="Simon Billinge", email="[email protected]" }, | ||
] | ||
description = "Complex modeling infrastructure: a modulare framework for multi-modal modeling of scientific data." | ||
description = "Complex modeling infrastructure: a modular framework for multi-modal modeling of scientific data." | ||
keywords = ['modelling', 'regression', 'diffraction', 'PDF', 'complex-modeling'] | ||
readme = "README.rst" | ||
requires-python = ">=3.11, <3.14" | ||
|
@@ -48,6 +48,10 @@ include = ["*"] # package names should match these glob patterns (["*"] by defa | |
exclude = [] # exclude packages matching these glob patterns (empty by default) | ||
namespaces = false # to disable scanning PEP 420 namespaces (true by default) | ||
|
||
[project.scripts] | ||
diffpy-cmi = "diffpy.cmi.app:main" | ||
cmi = "diffpy.cmi.app:main" | ||
|
||
[tool.setuptools.dynamic] | ||
dependencies = {file = ["requirements/pip.txt"]} | ||
|
||
|
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import argparse | ||
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 full 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 | ||
|
||
Usage: | ||
diffpy-cmi [--version] [--help] | ||
|
||
Options: | ||
--version Show version and exit | ||
-h, --help Show this message and exit | ||
""" | ||
) | ||
|
||
|
||
def short_usage(): | ||
"""Print brief usage message for invalid input.""" | ||
print( | ||
"Usage: diffpy-cmi [--version] [--help]\nUse --help to see more.", | ||
file=sys.stderr, | ||
) | ||
|
||
|
||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def print_version(): | ||
print(f"diffpy-cmi {__version__}") | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
prog="diffpy-cmi", | ||
add_help=False, | ||
) | ||
parser.add_argument( | ||
"--version", action="store_true", help="Show version and exit" | ||
) | ||
parser.add_argument( | ||
"-h", "--help", action="store_true", help="Show this message and exit" | ||
) | ||
args, unknown = parser.parse_known_args() | ||
if unknown: | ||
print( | ||
f"Error: unrecognized arguments: {' '.join(unknown)}", | ||
file=sys.stderr, | ||
) | ||
short_usage() | ||
sys.exit(1) | ||
if args.help: | ||
usage() | ||
return | ||
if args.version: | ||
print_version() | ||
return | ||
# Default behavior (no args) | ||
usage() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!