Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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/app-creation.rst
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>
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"
Copy link
Contributor

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 or cmi without -v or -h? Let's test that and make sure it behaves in a nice friendly way.

Copy link
Contributor Author

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.

shall we also have one that is just cmi (for lazy people). It can run the same function.

Yeah we can do that!


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

Expand Down
3 changes: 2 additions & 1 deletion src/diffpy/cmi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Copy link
Contributor

Choose a reason for hiding this comment

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

modulare?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
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


Copy link
Contributor

Choose a reason for hiding this comment

The 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

    parser = argparse.ArgumentParser(
        description="help/usage message"
    )
    parser.add_argument(
        "--version",
        action="store_true"
        help="Show the program's version number and exit",
    )
   args = parser.parse_args()
   if args.version:
      print("version message")
   else:
       print("help/intro message")

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

Choose a reason for hiding this comment

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

how about "is a complex modelling...."

Sadly, this terminology never got widely adopted. Many people call it "multi-modal analysis" so we could say something like: "Welcome to diffpy.cmi, a complex modeling infrastructurel for multi-modal analysis of scientific data form different sources.

It is a highly flexible....."

It is not for nanostructure analysis, it can be used for anything....even predicting stock prices. We can say something like that, but mention that modules currently exist for studies of structure from PDF and SAS data, with mroe to be added later. sthg like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sbillinge Okay got it. I copy/pasted this from the current diffpy-cmi documentation fyi. I'll add these changes

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

Choose a reason for hiding this comment

The 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....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

precommit does a cr for the parenths but i removed the lines

Options:
-V, --version Show version and exit
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sbillinge I capitalized because -v typically stands for verbose. I don't think it matters too much so we could change it to -v or simply remove the short-hand and require users to do --version. I feel like when I'm looking for a package version i always type --version anyways.

Copy link
Contributor

Choose a reason for hiding this comment

The 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():
from diffpy.cmi.version import __version__
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this import not at the top of the file? Also, don't we have a version.py? Is there a reason we are defining a new one?

Copy link
Contributor Author

@cadenmyers13 cadenmyers13 Jul 2, 2025

Choose a reason for hiding this comment

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

Yeah this should be fine at the top of the file as well. I'll move it.

Also, don't we have a version.py?

yeah in version.py, __version__ is defined and returns the version number. This just imports that version from the file so we aren't defining a new one.

Copy link
Contributor

Choose a reason for hiding this comment

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

so we aren't defining a new one.

but I see def version(): which seems to contradict your comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see what youre saying, I'll change the function name


print(f"diffpy-cmi {__version__}")


def main():
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

please do this work using argparse

Copy link
Contributor Author

Choose a reason for hiding this comment

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