Skip to content

Commit

Permalink
refactor: Convert command-line interface to click instead of argparse (
Browse files Browse the repository at this point in the history
…#54)

* refactor: convert to click from argparse

* test: correct the tests so that results are returned

* refactor: put back version and copyright cli options and test them

* test: change path to join abspath
  • Loading branch information
dbhart authored Oct 12, 2024
1 parent 4afdc91 commit 323c99b
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 387 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/executable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Standalone Executable

on:
push:
tags:
- '*'

permissions:
contents: read

jobs:
build_wheels:
name: Build executable 📦 for windows
runs-on: windows-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit

- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1

- name: Set up Python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
with:
python-version: 3.11

- name: Install development dependencies
run: |
python3 -m pip install -r requirements-exe.txt
python3 setup.py build_ext -i
python3 setup.py py2exe >> $GITHUB_STEP_SUMMARY
- uses: actions/upload-artifact@604373da6381bf24206979c74d06a550515601b9 # v4.4.1
with:
name: standalone
path: dist/*.exe
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"sphinx.ext.intersphinx",
"sphinx.ext.githubpages",
"sphinx_design",
"sphinxarg.ext",
"sphinx_click",
"sphinxcontrib.bibtex",
]

Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ sphinx_design==0.6.1
sphinxcontrib-bibtex==2.6.3
breathe==4.35.0
exhale==0.3.7
sphinx-argparse==0.5.2
sphinx-click==6.0.0
17 changes: 4 additions & 13 deletions docs/um/running-sansmic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@ The following include all available output options, but note that not all option
available if you have not installed the appropriate packages (see Advanced Installation).


``sansmic``
-----------

.. argparse::
:module: sansmic.app
:func: _main_parser
.. _sansmic:
.. click:: sansmic.app:run
:prog: sansmic




``sansmic-convert``
-------------------

.. argparse::
:module: sansmic.app
:func: _convert_parser
.. _sansmic-convert:
.. click:: sansmic.app:convert
:prog: sansmic-convert
22 changes: 10 additions & 12 deletions examples/basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -57,7 +57,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -77,7 +77,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -109,7 +109,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -133,7 +133,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -149,7 +149,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -244,7 +244,7 @@
"## Running from the command line\n",
"Jupyter is not a great way to demonstrate how to run sansmic from the command line; however, it is still possible to do so. The following code simulates the execution of the following command:\n",
"\n",
"``sansmic old.dat -o cmdlineTest --no-json --no-hdf``\n",
"``sansmic old.dat -o cmdlineTest --no-hdf``\n",
"\n",
"Try adding \"-v\" or \"-vv\" at the end of the list to see the difference."
]
Expand All @@ -258,16 +258,14 @@
"import sansmic.app\n",
"\n",
"\n",
"\n",
"resultsCmdLine = sansmic.app.main(\n",
"resultsCmdLine = sansmic.app.run(\n",
" [\n",
" \"old.dat\",\n",
" \"-o\",\n",
" \"cmdlineTest\",\n",
" \"--no-json\",\n",
" \"--no-hdf\",\n",
" ],\n",
" ret=True,\n",
" standalone_mode=False,\n",
")"
]
},
Expand All @@ -294,7 +292,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
{ name = "SANSMIC Authors (see AUTHORS.md)" },
]
maintainers = [{ name = "David Hart", email = "[email protected]" }]
dependencies = ["numpy", "pandas", 'tomli; python_version < "3.11"']
dependencies = ["numpy", "pandas", 'tomli; python_version < "3.11"', "click"]
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: BSD License",
Expand Down Expand Up @@ -47,7 +47,7 @@ docs = [
'sphinxcontrib-bibtex',
'breathe',
'exhale',
'sphinx-argparse',
'sphinx-click',
]

[project.urls]
Expand All @@ -56,7 +56,7 @@ Issues = "https://github.com/sandialabs/sansmic/issues"
Repository = "https://github.com/sandialabs/sansmic.git"

[project.scripts]
sansmic = "sansmic.app:main"
sansmic = "sansmic.app:run"
sansmic-convert = "sansmic.app:convert"

[build-system]
Expand Down Expand Up @@ -124,11 +124,11 @@ default = "semantic-release <semantic-release>"
[tool.semantic_release.commit_parser_options]
allowed_tags = [
# Non-source code changes (no change to version; omit from CHANGELOG by default)
"build", # Changes to build system or external dependencies (omit from CHANGELOG - manually add if needed)
"ci", # Changes to CI configuration files and scripts (omit from CHANGELOG - manually add if needed)
"chore", # Other changes that don't touch the source code (omit from CHANGELOG - manually add if needed)
"build", # Changes to build system or external dependencies (omit from CHANGELOG - manually add if needed)
"ci", # Changes to CI configuration files and scripts (omit from CHANGELOG - manually add if needed)
"chore", # Other changes that don't touch the source code (omit from CHANGELOG - manually add if needed)
# Changes to test suites (no change to version; include in CHANGELOG by default)
"test", # Adding missing tests or correcting existing tests (does not change package code)
"test", # Adding missing tests or correcting existing tests (does not change package code)
# Changes to source code (possible change to version; include in CHANGELOG by default)
"fix", # A bug fix (a patch-level version change)
"perf", # A code change that improves performance (at-least patch-level, possibly minor version change)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ numpy==2.1.2
pandas==2.2.3
pybind11==2.13.6
setuptools==75.1.0
click==8.1.7
Loading

0 comments on commit 323c99b

Please sign in to comment.