Skip to content

feat: create app to get diffpy.cmi version #18

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/create-app.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Add CLI to return diffpy.cmi version

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ 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"

[tool.setuptools.dynamic]
dependencies = {file = ["requirements/pip.txt"]}

Expand Down
5 changes: 4 additions & 1 deletion src/diffpy/cmi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
# 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
Expand Down
53 changes: 53 additions & 0 deletions src/diffpy/cmi/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import getopt
import sys


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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link is broken right now, but in the future this will be the link we use


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__

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()
Loading