|
9 | 9 | from invoke import task
|
10 | 10 | from invoke.collection import Collection
|
11 | 11 | from invoke.context import Context
|
| 12 | +from invoke.exceptions import UnexpectedExit |
12 | 13 | from pathlib import Path
|
13 | 14 | from typing import List, Optional
|
14 | 15 | from subprocess import run
|
@@ -36,22 +37,30 @@ def all_exist(files: List[str] = None, directories: List[str] = None) -> bool:
|
36 | 37 | @task()
|
37 | 38 | def docs_build(ctx: Context, ignore_warnings: bool = False):
|
38 | 39 | """Build the documentation using Sphinx."""
|
39 |
| - warn = "-W" if not ignore_warnings else "" |
40 |
| - nitpicky = "-n" if not ignore_warnings else "" |
| 40 | + cmd = [] |
| 41 | + cmd += "python -m sphinx build".split() |
| 42 | + cmd += ["--color"] # color output |
| 43 | + cmd += ["-b", "html"] # generate html |
| 44 | + if not ignore_warnings: |
| 45 | + cmd += ["-W"] # warnings as errors |
| 46 | + cmd += ["-n"] # nitpicky mode |
41 | 47 |
|
42 | 48 | doc_dir = Path("docs/_build")
|
43 | 49 | doc_dir.mkdir(exist_ok=True, parents=True)
|
44 |
| - print("Building documentation...") |
45 |
| - |
46 |
| - ctx.run( |
47 |
| - f"python -m sphinx build {warn} {nitpicky} --color -E -b html docs {doc_dir}" |
48 |
| - ) |
49 |
| - |
50 |
| - print("-" * 80) |
51 |
| - print("Documentation is built and available at:") |
52 |
| - print(f" file://{doc_dir.resolve()}/index.html") |
53 |
| - print("You can copy and paste this URL into your browser.") |
54 |
| - print("-" * 80) |
| 50 | + cmd += ["docs", doc_dir.as_posix()] # add source and output directories |
| 51 | + |
| 52 | + try: |
| 53 | + ctx.run(" ".join(cmd), echo=True) |
| 54 | + print("-" * 80) |
| 55 | + print("Documentation is built and available at:") |
| 56 | + print(f" file://{doc_dir.resolve()}/index.html") |
| 57 | + print("You can copy and paste this URL into your browser.") |
| 58 | + except UnexpectedExit: |
| 59 | + print("-" * 80) |
| 60 | + print("Documentation build failed. Here are some tips:") |
| 61 | + print(" - Check the Sphinx output for errors and warnings.") |
| 62 | + print(" - Try running `invoke docs.clean` to remove cached files.") |
| 63 | + print(" - Try running with `--ignore-warnings` to ignore warnings.") |
55 | 64 |
|
56 | 65 |
|
57 | 66 | @task
|
|
0 commit comments