Skip to content

Commit

Permalink
Generate command-line documentation with sphinx-click (#608)
Browse files Browse the repository at this point in the history
* Add sphinx-click 2.5.0

* Add sphinx-click 2.5.0 to docs/requirements.txt

* Configure Sphinx to use sphinx-click

* Install sphinx-click in docs and docs-build sessions

* Update Usage section in README.rst

* Add Usage page to Sphinx documentation

* Include Usage page in TOC tree

* Do not include Usage section from README.rst

* Link to Usage page from README.rst

* Document sphinx-click feature in README.rst

* Document sphinx-click dependency in User Guide

* Document usage.rst file in User Guide

Co-Authored-By: Thiago C. D'Ávila <thiagocavila@gmail.com>
  • Loading branch information
cjolowicz and Thiago C. D'Ávila committed Oct 12, 2020
1 parent 4307969 commit 7b405ef
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Features
- Security audit with Bandit_ and Safety_
- Check documentation examples with xdoctest_
- Generate API documentation with autodoc_ and napoleon_
- Generate command-line reference with sphinx-click_

The template supports Python 3.6, 3.7, 3.8, and 3.9.

Expand Down Expand Up @@ -320,6 +321,7 @@ on the *Issues* tab of your GitHub repository,
.. _pre-commit: https://pre-commit.com/
.. _pyenv: https://github.com/pyenv/pyenv
.. _pytest: https://docs.pytest.org/en/latest/
.. _sphinx-click: https://sphinx-click.readthedocs.io/
.. _xdoctest: https://github.com/Erotemic/xdoctest

.. references-end
6 changes: 6 additions & 0 deletions docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,11 @@ The documentation files in the ``docs`` directory are built using Sphinx_:
It is generated from docstrings and type annotations in the source code,
using the autodoc_ and napoleon_ extensions.

``usage.rst``
The command-line reference for your project.
It is generated by inspecting the click_ entry-point in your package,
using the sphinx-click_ extension.

The ``docs`` directory contains two more files:

``conf.py``
Expand Down Expand Up @@ -751,6 +756,7 @@ See the table below for an overview of the dependencies of generated projects:
safety_ Checks installed dependencies for known vulnerabilities
sphinx_ Python documentation generator
sphinx-autobuild_ Watch a Sphinx directory and rebuild the documentation when a change is detected
sphinx-click_ Sphinx extension that automatically documents click applications
sphinx-rtd-theme_ Read the Docs theme for Sphinx
typeguard_ Run-time type checker for Python
xdoctest_ A rewrite of the builtin doctest module
Expand Down
3 changes: 2 additions & 1 deletion {{cookiecutter.project_name}}/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ You can install *{{cookiecutter.friendly_name}}* via pip_ from PyPI_:
Usage
-----

* TODO
Please see the `Command-line Reference <Usage_>`_ for details.


Contributing
Expand Down Expand Up @@ -100,3 +100,4 @@ This project was generated from `@cjolowicz`_'s `Hypermodern Python Cookiecutter
.. _pip: https://pip.pypa.io/
.. github-only
.. _Contributor Guide: CONTRIBUTING.rst
.. _Usage: https://{{cookiecutter.project_name}}.readthedocs.io/en/latest/usage.html
7 changes: 6 additions & 1 deletion {{cookiecutter.project_name}}/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
project = "{{cookiecutter.friendly_name}}"
author = "{{cookiecutter.author}}"
copyright = f"{datetime.now().year}, {author}"
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx_rtd_theme"]
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx_click",
"sphinx_rtd_theme",
]
autodoc_typehints = "description"
html_theme = "sphinx_rtd_theme"
2 changes: 2 additions & 0 deletions {{cookiecutter.project_name}}/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
:end-before: github-only

.. _Contributor Guide: contributing.html
.. _Usage: usage.html

.. toctree::
:hidden:
:maxdepth: 1

usage
reference
contributing
Code of Conduct <codeofconduct>
Expand Down
1 change: 1 addition & 0 deletions {{cookiecutter.project_name}}/docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
sphinx==3.2.1
sphinx-click==2.5.0
sphinx-rtd-theme==0.5.0
6 changes: 6 additions & 0 deletions {{cookiecutter.project_name}}/docs/usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Usage
=====

.. click:: {{cookiecutter.package_name}}.__main__:main
:prog: {{cookiecutter.project_name}}
:nested: full
4 changes: 2 additions & 2 deletions {{cookiecutter.project_name}}/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def docs_build(session: Session) -> None:
"""Build the documentation."""
args = session.posargs or ["docs", "docs/_build"]
session.install(".")
session.install("sphinx", "sphinx-rtd-theme")
session.install("sphinx", "sphinx-click", "sphinx-rtd-theme")

build_dir = Path("docs", "_build")
if build_dir.exists():
Expand All @@ -177,7 +177,7 @@ def docs(session: Session) -> None:
"""Build and serve the documentation with live reloading on file changes."""
args = session.posargs or ["--open-browser", "docs", "docs/_build"]
session.install(".")
session.install("sphinx", "sphinx-autobuild", "sphinx-rtd-theme")
session.install("sphinx", "sphinx-autobuild", "sphinx-click", "sphinx-rtd-theme")

build_dir = Path("docs", "_build")
if build_dir.exists():
Expand Down
18 changes: 17 additions & 1 deletion {{cookiecutter.project_name}}/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions {{cookiecutter.project_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ darglint = "^1.5.5"
reorder-python-imports = "^2.3.5"
pre-commit-hooks = "^3.2.0"
sphinx-rtd-theme = "^0.5.0"
sphinx-click = "^2.5.0"
Pygments = "^2.7.1"

[tool.poetry.scripts]
Expand Down

0 comments on commit 7b405ef

Please sign in to comment.