Skip to content

Commit

Permalink
use click CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
mscheltienne committed Aug 28, 2024
1 parent 0d88210 commit 95088a4
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install package
run: python -m pip install --progress-bar off .[doc]
- name: Display system information
run: nmod_wiki-sys_info --developer
run: nmod-wiki sys-info --developer
- name: Build doc
run: make -C doc html
- name: Prune sphinx environment
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
python -m pip install --progress-bar off --upgrade pip setuptools
python -m pip install --progress-bar off .[test]
- name: Display system information
run: nmod_wiki-sys_info --developer
run: nmod-wiki sys-info --developer
- name: Run pytest
run: pytest nmod_wiki --cov=nmod_wiki --cov-report=xml --cov-config=pyproject.toml
- name: Upload to codecov
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
python -m pip install --progress-bar off .[test]
python -m pip install --progress-bar off --upgrade --pre --only-binary :all: -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --timeout=180 numpy
- name: Display system information
run: nmod_wiki-sys_info --developer
run: nmod-wiki sys-info --developer
- name: Run pytest
run: pytest nmod_wiki --cov=nmod_wiki --cov-report=xml --cov-config=pyproject.toml
- name: Upload to codecov
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stubs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
python -m pip install --progress-bar off --upgrade pip setuptools
python -m pip install --progress-bar off -e .[stubs]
- name: Display system information
run: nmod_wiki-sys_info --developer
run: nmod-wiki sys-info --developer
- name: Generate stub files
run: python tools/stubgen.py
- name: Push stub files
Expand Down
13 changes: 13 additions & 0 deletions nmod_wiki/commands/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import annotations

import click

from .sys_info import run as sys_info


@click.group()
def run() -> None:
"""Main package entry-point.""" # noqa: D401


run.add_command(sys_info)
24 changes: 11 additions & 13 deletions nmod_wiki/commands/sys_info.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import argparse
from __future__ import annotations

import click

from .. import sys_info


def run() -> None:
@click.command(name="sys-info")
@click.option(
"--developer",
help="Display information for optional dependencies.",
is_flag=True,
)
def run(developer: bool) -> None:
"""Run sys_info() command."""
parser = argparse.ArgumentParser(
prog=f"{__package__.split('.')[0]}-sys_info", description="sys_info"
)
parser.add_argument(
"--developer",
help="display information for optional dependencies",
action="store_true",
)
args = parser.parse_args()

sys_info(developer=args.developer)
sys_info(developer=developer)
Empty file.
13 changes: 13 additions & 0 deletions nmod_wiki/commands/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from click.testing import CliRunner

from ..main import run


def test_main():
"""Test the main package entry-point."""
runner = CliRunner()
result = runner.invoke(run)
assert result.exit_code == 0
assert "Main package entry-point" in result.output
assert "Options:" in result.output
assert "Commands:" in result.output
20 changes: 20 additions & 0 deletions nmod_wiki/commands/tests/test_sys_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest
from click.testing import CliRunner

from ..sys_info import run


@pytest.mark.parametrize("developer", [False, True])
def test_sys_info(developer: bool):
"""Test the system information entry-point."""
runner = CliRunner()
result = runner.invoke(run, ["--developer"] if developer else [])
assert result.exit_code == 0
assert "Platform:" in result.output
assert "Python:" in result.output
assert "Executable:" in result.output
assert "Core dependencies" in result.output
if developer:
assert "Optional 'build' dependencies" in result.output
assert "Optional 'style' dependencies" in result.output
assert "Optional 'test' dependencies" in result.output
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ classifiers = [
'Programming Language :: Python :: 3.9',
]
dependencies = [
'click',
'numpy>=1.21',
'packaging',
'psutil',
Expand Down Expand Up @@ -87,7 +88,7 @@ test = [
]

[project.scripts]
nmod_wiki-sys_info = 'nmod_wiki.commands.sys_info:run'
nmod-wiki = 'nmod_wiki.commands.main:run'

[project.urls]
documentation = 'https://github.com/fcbg-hnp-meeg/nmod-wiki'
Expand Down Expand Up @@ -116,7 +117,6 @@ omit = [
'**/__init__.py',
'**/conftest.py',
'**/nmod_wiki/_version.py',
'**/nmod_wiki/commands/*',
'**/nmod_wiki/utils/_fixes.py',
'**/tests/**',
]
Expand Down

0 comments on commit 95088a4

Please sign in to comment.