From 4b041d2b521b014115d461abbc45b68a8160d43c Mon Sep 17 00:00:00 2001 From: js2264 Date: Thu, 1 Aug 2024 19:45:26 +0200 Subject: [PATCH] feat: kickstart cli --- docs/source/api.rst | 4 ++-- docs/source/conf.py | 2 +- pyproject.toml | 1 + src/momics/__init__.py | 2 ++ src/momics/{Momics.py => api.py} | 0 src/momics/cli/__init__.py | 27 +++++++++++++++++++++++++++ src/momics/cli/dump.py | 21 +++++++++++++++++++++ tests/{test_main.py => test_api.py} | 0 8 files changed, 54 insertions(+), 3 deletions(-) rename src/momics/{Momics.py => api.py} (100%) create mode 100644 src/momics/cli/__init__.py create mode 100644 src/momics/cli/dump.py rename tests/{test_main.py => test_api.py} (100%) diff --git a/docs/source/api.rst b/docs/source/api.rst index feeb3df..acb7f31 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -3,10 +3,10 @@ API ==== -momics.Momics +momics.api ------------- -.. automodule:: momics.Momics +.. automodule:: momics.api :members: :undoc-members: :show-inheritance: diff --git a/docs/source/conf.py b/docs/source/conf.py index 937e949..4ceaa3a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -58,12 +58,12 @@ # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output -html_theme = "furo" # html_theme = "pydata_sphinx_theme" html_static_path = ["_static"] htmlhelp_basename = "momicsdoc" html_last_updated_fmt = "%b %d, %Y" html_title = "momics" +html_theme = "furo" html_theme_options = { "source_repository": "https://github.com/js2264/momics/", "source_branch": "devel", diff --git a/pyproject.toml b/pyproject.toml index 660d878..82e15b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ dependencies = [ "numpy", "pandas", "pyarrow>=1.0", + "click>=7", ] [project.urls] diff --git a/src/momics/__init__.py b/src/momics/__init__.py index 1cd2fdb..2210c08 100644 --- a/src/momics/__init__.py +++ b/src/momics/__init__.py @@ -9,9 +9,11 @@ """ +from .api import Momics from .version import __format_version__, __version__ __all__ = [ "__version__", "__format_version__", + "Momics", ] diff --git a/src/momics/Momics.py b/src/momics/api.py similarity index 100% rename from src/momics/Momics.py rename to src/momics/api.py diff --git a/src/momics/cli/__init__.py b/src/momics/cli/__init__.py new file mode 100644 index 0000000..ce3442b --- /dev/null +++ b/src/momics/cli/__init__.py @@ -0,0 +1,27 @@ +import click + +from ..version import __version__ + +CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]} + + +class UnsortedGroup(click.Group): + """A click Group that lists commands in the order they were added.""" + + def list_commands(self, ctx): + return list(self.commands) + + +@click.version_option(__version__, "-V", "--version") +@click.group(context_settings=CONTEXT_SETTINGS, cls=UnsortedGroup) +def cli(): + """ + Type -h or --help after any subcommand for more information. + + """ + + +# Load and register cli subcommands +from . import ( # noqa: E402,F401 + dump, +) diff --git a/src/momics/cli/dump.py b/src/momics/cli/dump.py new file mode 100644 index 0000000..90239e6 --- /dev/null +++ b/src/momics/cli/dump.py @@ -0,0 +1,21 @@ +import click + +from .. import api +from . import cli + + +@cli.command() +@click.argument("momics", metavar="MOMICS_PATH") +@click.option( + "--table", + "-t", + help="Which table to dump.", + type=click.Choice(["chroms", "tracks"]), + default="chroms", + show_default=True, +) +def dump(momics, table): + if table == "tracks": + print(api.Momics(momics).tracks()) + if table == "chroms": + print(api.Momics(momics).chroms()) diff --git a/tests/test_main.py b/tests/test_api.py similarity index 100% rename from tests/test_main.py rename to tests/test_api.py