Skip to content

Commit 30b1fc3

Browse files
Thiago C. D'ÁvilaClaudio Jolowicz
andauthored
Add docs-build session (#498)
* Add docs-build session * Install sphinx * Code review * clean_build_path return type * Rerun checks * Test session fix * Fix update documentation * Code review 2 * Update test workflow and sessions docs * Documentation review * CI: Do not run docs session in generated project Co-authored-by: Claudio Jolowicz <[email protected]>
1 parent 79910cd commit 30b1fc3

File tree

4 files changed

+58
-40
lines changed

4 files changed

+58
-40
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ jobs:
7373
- name: Run test suite using Nox
7474
run: nox --force-color
7575
working-directory: hypermodern-python
76-
- name: Build project documentation
77-
run: nox --force-color --session=docs
78-
working-directory: hypermodern-python
7976
- name: Install dependencies using Poetry
8077
run: poetry install --ansi
8178
working-directory: hypermodern-python

docs/guide.rst

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,18 +1048,19 @@ The following table gives an overview of the available Nox sessions:
10481048
:class: hypermodern-table
10491049
:widths: auto
10501050

1051-
========================================== ================================= ================== =========
1052-
Session Description Python Default
1053-
========================================== ================================= ================== =========
1054-
:ref:`coverage <The coverage session>` Report coverage with Coverage.py_ ``3.8``
1055-
:ref:`docs <The docs session>` Build Sphinx_ documentation ``3.8``
1056-
:ref:`mypy <The mypy session>` Type-check with mypy_ ``3.6`` … ``3.8`` ✓
1057-
:ref:`pre-commit <The pre-commit session>` Lint with pre-commit_ ``3.8`` ✓
1058-
:ref:`safety <The safety session>` Scan dependencies with Safety_ ``3.8`` ✓
1059-
:ref:`tests <The tests session>` Run tests with pytest_ ``3.6`` … ``3.8`` ✓
1060-
:ref:`typeguard <The typeguard session>` Type-check with Typeguard_ ``3.6`` … ``3.8`` ✓
1061-
:ref:`xdoctest <The xdoctest session>` Run examples with xdoctest_ ``3.6`` … ``3.8``
1062-
========================================== ================================= ================== =========
1051+
========================================== ===================================== ================== =========
1052+
Session Description Python Default
1053+
========================================== ===================================== ================== =========
1054+
:ref:`coverage <The coverage session>` Report coverage with Coverage.py_ ``3.8``
1055+
:ref:`docs <The docs session>` Build and serve Sphinx_ documentation ``3.8``
1056+
:ref:`docs-build <The docs-build session>` Build Sphinx_ documentation ``3.8`` ✓
1057+
:ref:`mypy <The mypy session>` Type-check with mypy_ ``3.6`` … ``3.8`` ✓
1058+
:ref:`pre-commit <The pre-commit session>` Lint with pre-commit_ ``3.8`` ✓
1059+
:ref:`safety <The safety session>` Scan dependencies with Safety_ ``3.8`` ✓
1060+
:ref:`tests <The tests session>` Run tests with pytest_ ``3.6`` … ``3.8`` ✓
1061+
:ref:`typeguard <The typeguard session>` Type-check with Typeguard_ ``3.6`` … ``3.8`` ✓
1062+
:ref:`xdoctest <The xdoctest session>` Run examples with xdoctest_ ``3.6`` … ``3.8``
1063+
========================================== ===================================== ================== =========
10631064

10641065

10651066
.. _The docs session:
@@ -1073,23 +1074,16 @@ Build the documentation using the Nox session ``docs``:
10731074
10741075
$ nox --session=docs
10751076
1076-
The docs session runs the command ``sphinx-build``
1077-
to generate the HTML documentation from the Sphinx directory.
1078-
1079-
In `interactive mode`__---such
1080-
as when invoking Nox from a terminal---sphinx-autobuild_ is used instead.
1081-
This tool has several advantages
1082-
when you are editing the documentation files:
1083-
1084-
__ https://nox.thea.codes/en/stable/usage.html#forcing-non-interactive-behavior
1077+
The docs session runs the command ``sphinx-autobuild`` to generate the HTML documentation from the Sphinx directory.
1078+
This tool has several advantages over ``sphinx-build`` when you are editing the documentation files:
10851079

10861080
- It rebuilds the documentation whenever a change is detected.
10871081
- It spins up a web server with live reloading.
10881082
- It opens the location of the web server in your browser.
10891083

10901084
.. _sphinx-autobuild: https://github.com/GaretJax/sphinx-autobuild
10911085

1092-
Use the ``--`` separator to pass additional options to either tool.
1086+
Use the ``--`` separator to pass additional options.
10931087
For example, to treat warnings as errors and run in nit-picky mode:
10941088

10951089
.. code:: console
@@ -1099,6 +1093,19 @@ For example, to treat warnings as errors and run in nit-picky mode:
10991093
This Nox session always runs with the current major release of Python.
11001094

11011095

1096+
.. _The docs-build session:
1097+
1098+
The docs-build session
1099+
----------------------
1100+
1101+
The ``docs-build`` session runs the command ``sphinx-build`` to generate the HTML documentation from the Sphinx directory.
1102+
1103+
This session is meant to be run as a part of automated checks.
1104+
Use the interactive ``docs`` session instead while you're editing the documentation.
1105+
1106+
This Nox session always runs with the current major release of Python.
1107+
1108+
11021109
.. _The mypy session:
11031110

11041111
The mypy session
@@ -2275,7 +2282,7 @@ __ https://help.github.com/en/actions/automating-your-workflow-with-github-actio
22752282
:ref:`tests <The tests session>` Ubuntu 3.8, 3.7, 3.6
22762283
:ref:`tests <The tests session>` Windows 3.8
22772284
:ref:`tests <The tests session>` macOS 3.8
2278-
:ref:`docs <The docs session>` Ubuntu 3.8
2285+
:ref:`docs-build <The docs-build session>` Ubuntu 3.8
22792286
========================================== ====================== ===============
22802287

22812288
The workflow uploads the generated documentation as a `workflow artifact`__.

{{cookiecutter.project_name}}/.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- { python-version: 3.8, os: windows-latest, session: "tests" }
2424
- { python-version: 3.8, os: macos-latest, session: "tests" }
2525
- { python-version: 3.8, os: ubuntu-latest, session: "typeguard" }
26-
- { python-version: 3.8, os: ubuntu-latest, session: "docs" }
26+
- { python-version: 3.8, os: ubuntu-latest, session: "docs-build" }
2727

2828
env:
2929
NOXSESSION: {{ "${{ matrix.session }}" }}
@@ -81,7 +81,7 @@ jobs:
8181
nox --force-color --python=${{ "{{" }} matrix.python-version {{ "}}" }}
8282
8383
- name: Upload documentation
84-
if: matrix.session == 'docs'
84+
if: matrix.session == 'docs-build'
8585
uses: actions/upload-artifact@v2
8686
with:
8787
name: docs

{{cookiecutter.project_name}}/noxfile.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111

1212
package = "{{cookiecutter.package_name}}"
1313
python_versions = ["3.8", "3.7", "3.6"]
14-
nox.options.sessions = "pre-commit", "safety", "mypy", "tests", "typeguard"
14+
nox.options.sessions = (
15+
"pre-commit",
16+
"safety",
17+
"mypy",
18+
"tests",
19+
"typeguard",
20+
"docs-build",
21+
)
1522

1623

1724
class Poetry:
@@ -254,22 +261,29 @@ def xdoctest(session: Session) -> None:
254261
session.run("python", "-m", "xdoctest", package, *args)
255262

256263

257-
@nox.session(python="3.8")
258-
def docs(session: Session) -> None:
264+
@nox.session(name="docs-build", python="3.8")
265+
def docs_build(session: Session) -> None:
259266
"""Build the documentation."""
260267
args = session.posargs or ["docs", "docs/_build"]
268+
install_package(session)
269+
install(session, "sphinx")
270+
271+
build_dir = Path("docs", "_build")
272+
if build_dir.exists():
273+
shutil.rmtree(build_dir)
261274

262-
if session.interactive and not session.posargs:
263-
args.insert(0, "--open-browser")
275+
session.run("sphinx-build", *args)
264276

265-
builddir = Path("docs", "_build")
266-
if builddir.exists():
267-
shutil.rmtree(builddir)
268277

278+
@nox.session(python="3.8")
279+
def docs(session: Session) -> None:
280+
"""Build and serve the documentation with live reloading on file changes."""
281+
args = session.posargs or ["--open-browser", "docs", "docs/_build"]
269282
install_package(session)
270283
install(session, "sphinx", "sphinx-autobuild")
271284

272-
if session.interactive:
273-
session.run("sphinx-autobuild", *args)
274-
else:
275-
session.run("sphinx-build", *args)
285+
build_dir = Path("docs", "_build")
286+
if build_dir.exists():
287+
shutil.rmtree(build_dir)
288+
289+
session.run("sphinx-autobuild", *args)

0 commit comments

Comments
 (0)