@@ -238,6 +238,8 @@ In order to use <https://readthedocs.org> to build, host, and preview your
238238documentation, you must have a ` .readthedocs.yaml ` file {% rr RTD100 %} like
239239this:
240240
241+ {% tabs %} {% tab uv-sphinx uv + Sphinx %}
242+
241243<!-- [[[cog
242244with code_fence("yaml"):
243245 print(readthedocs_yaml)
@@ -252,7 +254,31 @@ version: 2
252254build :
253255 os : ubuntu-22.04
254256 tools :
255- python : " 3.11"
257+ python : " 3.12"
258+ commands :
259+ - asdf plugin add uv
260+ - asdf install uv latest
261+ - asdf global uv latest
262+ - uv venv
263+ - uv pip install .[docs]
264+ - .venv/bin/python -m sphinx -T -b html -d docs/_build/doctrees -D
265+ language=en docs $READTHEDOCS_OUTPUT/html
266+ ` ` `
267+ <!-- prettier-ignore-end -->
268+ <!-- [[[end]]] -->
269+
270+ {% endtab %} {% tab pip-sphinx pip + Sphinx %}
271+
272+ ` ` ` yaml
273+ # Read the Docs configuration file
274+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
275+
276+ version : 2
277+
278+ build :
279+ os : ubuntu-22.04
280+ tools :
281+ python : " 3.12"
256282sphinx :
257283 configuration : docs/conf.py
258284
@@ -263,8 +289,8 @@ python:
263289 extra_requirements :
264290 - docs
265291` ` `
266- <!-- prettier-ignore-end -->
267- <!-- [[[end]]] -->
292+
293+ {% endtab %} {% endtabs %}
268294
269295This sets the Read the Docs config version (2 is required) {% rr RTD101 %}.
270296
@@ -291,50 +317,39 @@ with code_fence("python"):
291317@nox.session(reuse_venv=True)
292318def docs(session: nox.Session) -> None:
293319 """
294- Build the docs. Pass "--serve" to serve. Pass "-b linkcheck" to check links .
320+ Build the docs. Pass --non-interactive to avoid serving. First positional argument is the target directory .
295321 """
296322
297323 parser = argparse.ArgumentParser()
298- parser.add_argument("--serve", action="store_true", help="Serve after building")
299324 parser.add_argument(
300325 "-b", dest="builder", default="html", help="Build target (default: html)"
301326 )
327+ parser.add_argument("output", nargs="?", help="Output directory")
302328 args, posargs = parser.parse_known_args(session.posargs)
329+ serve = args.builder == "html" and session.interactive
303330
304- if args.builder != "html" and args.serve:
305- session.error("Must not specify non-HTML builder with --serve")
306-
307- extra_installs = ["sphinx-autobuild"] if args.serve else []
308-
309- session.install("-e.[docs]", *extra_installs)
310- session.chdir("docs")
311-
312- if args.builder == "linkcheck":
313- session.run(
314- "sphinx-build", "-b", "linkcheck", ".", "_build/linkcheck", *posargs
315- )
316- return
331+ session.install("-e.[docs]", "sphinx-autobuild")
317332
318333 shared_args = (
319334 "-n", # nitpicky mode
320335 "-T", # full tracebacks
321336 f"-b={args.builder}",
322- ". ",
323- f" _build/{args.builder}",
337+ "docs ",
338+ args.output or f"docs/ _build/{args.builder}",
324339 *posargs,
325340 )
326341
327- if args. serve:
328- session.run("sphinx-autobuild", *shared_args)
342+ if serve:
343+ session.run("sphinx-autobuild", "--open-browser", *shared_args)
329344 else:
330345 session.run("sphinx-build", "--keep-going", *shared_args)
331346` ` `
332347<!-- prettier-ignore-end -->
333348<!-- [[[end]]] -->
334349
335350This is a more complex Nox job just because it's taking some options (the
336- ability to build and serve instead of just build, and the ability to select the
337- builder). The first portion is just setting up argument parsing . Then it does
351+ ability to build and serve instead of just build). The first portion is just
352+ setting up argument parsing so we can serve if building `html` . Then it does
338353some conditional installs based on arguments (sphinx-autobuild is only needed if
339354serving). It does an editable install of your package so that you can skip the
340355install steps with `-R` and still get updated documentation.
@@ -367,15 +382,14 @@ def build_api_docs(session: nox.Session) -> None:
367382 """
368383
369384 session.install("sphinx")
370- session.chdir("docs")
371385 session.run(
372386 "sphinx-apidoc",
373387 "-o",
374- "api/",
388+ "docs/ api/",
375389 "--module-first",
376390 "--no-toc",
377391 "--force",
378- "../ src/<package-name-here>",
392+ "src/<package-name-here>",
379393 )
380394` ` `
381395<!-- prettier-ignore-end -->
@@ -429,3 +443,5 @@ If you want to use Markdown instead of notebooks, you can use jupytext (see
429443[sphinx-autodoc2] : https://sphinx-autodoc2.readthedocs.io/
430444[`sphinx.ext.napoleon`] : https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
431445<!-- prettier-ignore-end -->
446+
447+ <script src="{% link assets/js/tabs.js %}"></script>
0 commit comments