Skip to content

Commit

Permalink
add cli docs with sphinx-click (#82)
Browse files Browse the repository at this point in the history
This adds auto-generated docs for the wsinfer cli. This commit also
renames the subcommand cli function names, to account for
click-contrib/sphinx-click#74
  • Loading branch information
kaczmarj authored Jan 22, 2023
1 parent 4e64a75 commit e190c6e
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 15 deletions.
3 changes: 3 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. click:: wsinfer.cli.cli:cli
:prog: wsinfer
:nested: full
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"sphinx.ext.intersphinx", # for links
"sphinx.ext.napoleon", # for google style docstrings
"autoapi.extension", # to document the wsinfer api
"sphinx_click", # to document click command line
]

autoapi_type = "python"
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ on whole slide images.

Installing <installing>
User Guide <user_guide>
CLI <cli>


.. |img-tissue| image:: images/brca-tissue.png
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pydata-sphinx-theme
sphinx-autoapi
sphinx-click
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ docs =
pydata-sphinx-theme
sphinx
sphinx-autoapi
sphinx-click

[options.entry_points]
console_scripts =
Expand Down
20 changes: 10 additions & 10 deletions wsinfer/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import click

# from .. import __version__
from .convert_csv_to_geojson import cli as _cli_convert_to_geojson
from .convert_csv_to_sbubmi import cli as _cli_convert_to_sbubmi
from .infer import cli as _cli_inference
from .list_models_and_weights import cli as _cli_list_models_weights
from .patch import cli as _cli_patch
from .convert_csv_to_geojson import togeojson
from .convert_csv_to_sbubmi import tosbu
from .infer import run
from .list_models_and_weights import list
from .patch import patch


# We use invoke_without_command=True so that 'wsinfer' on its own can be used for
Expand All @@ -17,8 +17,8 @@ def cli():
pass


cli.add_command(_cli_inference, name="run")
cli.add_command(_cli_convert_to_geojson, name="togeojson")
cli.add_command(_cli_convert_to_sbubmi, name="tosbu")
cli.add_command(_cli_patch, name="patch")
cli.add_command(_cli_list_models_weights, name="list")
cli.add_command(run)
cli.add_command(togeojson)
cli.add_command(tosbu)
cli.add_command(patch)
cli.add_command(list)
2 changes: 1 addition & 1 deletion wsinfer/cli/convert_csv_to_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def convert(input, output) -> None:
"output",
type=click.Path(exists=False, path_type=Path, resolve_path=True),
)
def cli(*, results_dir: Path, output: Path):
def togeojson(*, results_dir: Path, output: Path):
"""Convert model outputs to GeoJSON format.
GeoJSON files can be used with pathology viewers like QuPath.
Expand Down
2 changes: 1 addition & 1 deletion wsinfer/cli/convert_csv_to_sbubmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def get_color(row: pd.Series):
default=4,
help="Number of processes to use when `--make-color-text` is enabled.",
)
def cli(
def tosbu(
*,
results_dir: Path,
output: Path,
Expand Down
2 changes: 1 addition & 1 deletion wsinfer/cli/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def get_stdout(args) -> str:
help="Use a dense grid of patch coordinates. Patches will be present even if no"
" tissue is present",
)
def cli(
def run(
ctx: click.Context,
*,
wsi_dir: Path,
Expand Down
2 changes: 1 addition & 1 deletion wsinfer/cli/list_models_and_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@click.command()
def cli():
def list():
"""Show all available models and weights."""
models_weights = models.list_all_models_and_weights()

Expand Down
2 changes: 1 addition & 1 deletion wsinfer/cli/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
type=float,
help="Patch spacing in micrometers per pixel.",
)
def cli(
def patch(
source: str,
step_size: Optional[int],
patch_size: int,
Expand Down

0 comments on commit e190c6e

Please sign in to comment.