Move main CLI functionality into `docstub run` subcommand by lagru · Pull Request #49 · scientific-python/docstub · GitHub
Skip to content
Merged
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
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
38 changes: 27 additions & 11 deletions doc/command_line.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
# Command line reference

Running
```
docstub --help
## Command `docstub`

<!--- The following block is checked by the test suite --->
<!--- begin cli-docstub --->

```plain
Usage: docstub [OPTIONS] COMMAND [ARGS]...

Generate Python stub files from docstrings.

Options:
--version Show the version and exit.
-h, --help Show this message and exit.

Commands:
run Generate Python stub files.
```
will print

<!--- end cli-docstub --->


## Command `docstub run`

<!--- The following block is checked by the test suite --->
<!--- begin command-line-help --->
<!--- begin cli-docstub-run --->

```plain
Usage: docstub [OPTIONS] PACKAGE_PATH
Usage: docstub run [OPTIONS] PACKAGE_PATH

Generate Python stub files with type annotations from docstrings.
Generate Python stub files.

Given a path `PACKAGE_PATH` to a Python package, generate stub files for it.
Type descriptions in docstrings will be used to fill in missing inline type
Given a `PACKAGE_PATH` to a Python package, generate stub files for it. Type
descriptions in docstrings will be used to fill in missing inline type
annotations or to override them.

Options:
--version Show the version and exit.
-o, --out-dir PATH Set output directory explicitly. Stubs will be directly
written into that directory while preserving the
directory structure under `PACKAGE_PATH`. Otherwise,
Expand All @@ -38,4 +54,4 @@ Options:
-h, --help Show this message and exit.
```

<!--- end command-line-help --->
<!--- end cli-docstub-run --->
2 changes: 1 addition & 1 deletion doc/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def example_metric(image, *, mask=None, sigma=1.0, method='standard'):
Feeding this input to docstub with

```shell
docstub example.py
docstub run example.py
```

will create `example.pyi` in the same directory
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test = [
Home = "https://github.com/lagru/docstub"

[project.scripts]
docstub = "docstub.__main__:main"
docstub = "docstub.__main__:cli"


[tool.setuptools_scm]
Expand Down
4 changes: 2 additions & 2 deletions src/docstub/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._cli import main
from ._cli import cli

if __name__ == "__main__":
main()
cli()
18 changes: 13 additions & 5 deletions src/docstub/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,19 @@ def report_execution_time():
click.echo(f"Finished in {formated_duration}")


# Preserve click.command below to keep type checker happy
# docstub: off
@click.command()
@click.group()
# docstub: on
@click.version_option(__version__)
@click.help_option("-h", "--help")
def cli():
"""Generate Python stub files from docstrings."""


# Preserve click.command below to keep type checker happy
# docstub: off
@cli.command()
# docstub: on
@click.argument("root_path", type=click.Path(exists=True), metavar="PACKAGE_PATH")
@click.option(
"-o",
Expand Down Expand Up @@ -174,10 +182,10 @@ def report_execution_time():
@click.option("-v", "--verbose", count=True, help="Print more details (repeatable).")
@click.help_option("-h", "--help")
@report_execution_time()
def main(root_path, out_dir, config_paths, group_errors, allow_errors, verbose):
"""Generate Python stub files with type annotations from docstrings.
def run(root_path, out_dir, config_paths, group_errors, allow_errors, verbose):
"""Generate Python stub files.

Given a path `PACKAGE_PATH` to a Python package, generate stub files for it.
Given a `PACKAGE_PATH` to a Python package, generate stub files for it.
Type descriptions in docstrings will be used to fill in missing inline type
annotations or to override them.
\f
Expand Down
2 changes: 1 addition & 1 deletion tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Test_KnownImport:
def test_dot_in_alias(self):
with pytest.raises(ValueError, match=".*can't contain a '\.'"):
with pytest.raises(ValueError, match=r".*can't contain a '\.'"):
KnownImport(import_name="foo.bar.baz", import_alias="bar.baz")


Expand Down
19 changes: 12 additions & 7 deletions tests/test_doc.py