|
5 | 5 |
|
6 | 6 | nox.options.reuse_existing_virtualenvs = True |
7 | 7 |
|
8 | | -OUTPUT_DIR = "_build" |
9 | | -docs_dir = os.path.join("_build", "html") |
10 | | -build_command = ["-b", "html", ".", docs_dir] |
| 8 | +## Sphinx related options |
| 9 | + |
| 10 | +# Sphinx output and source directories |
| 11 | +OUTPUT_DIR = pathlib.Path("_build", "html") |
| 12 | +SOURCE_DIR = pathlib.Path(".") |
| 13 | + |
| 14 | +# Sphinx build commands |
| 15 | +SPHINX_BUILD = "sphinx-build" |
| 16 | +SPHINX_AUTO_BUILD = "sphinx-autobuild" |
| 17 | + |
| 18 | +# Sphinx parameters used to build the guide |
| 19 | +BUILD_PARAMETERS = ["-b", "html"] |
| 20 | + |
| 21 | +# Sphinx parameters used to test the build of the guide |
| 22 | +TEST_PARAMETERS = ['-W', '--keep-going', '-E', '-a'] |
| 23 | + |
| 24 | +# Sphinx-autobuild ignore and include parameters |
| 25 | +AUTOBUILD_IGNORE = [ |
| 26 | + "_build", |
| 27 | + "build_assets", |
| 28 | + "tmp", |
| 29 | +] |
| 30 | +AUTOBUILD_INCLUDE = [ |
| 31 | + pathlib.Path("_static", "pyos.css") |
| 32 | +] |
11 | 33 |
|
12 | 34 | @nox.session |
13 | 35 | def docs(session): |
| 36 | + """Build the packaging guide.""" |
14 | 37 | session.install("-e", ".") |
15 | | - cmd = ["sphinx-build"] |
16 | | - cmd.extend(build_command + session.posargs) |
| 38 | + cmd = [SPHINX_BUILD, *BUILD_PARAMETERS, SOURCE_DIR, OUTPUT_DIR, *session.posargs] |
17 | 39 | session.run(*cmd) |
18 | 40 |
|
19 | 41 | @nox.session(name="docs-test") |
20 | 42 | def docs_test(session): |
21 | | - """ |
22 | | - Same as `docs`, but rebuild everything and fail on warnings for testing |
23 | | - """ |
| 43 | + """Build the packaging guide with additional parameters.""" |
24 | 44 | session.install("-e", ".") |
25 | | - cmd = ["sphinx-build"] |
26 | | - cmd.extend(['-W', '--keep-going', '-E', '-a']) |
27 | | - cmd.extend(build_command + session.posargs) |
| 45 | + cmd = [SPHINX_BUILD, *BUILD_PARAMETERS, *TEST_PARAMETERS, SOURCE_DIR, OUTPUT_DIR, *session.posargs] |
28 | 46 | session.run(*cmd) |
29 | 47 |
|
30 | | - |
31 | 48 | @nox.session(name="docs-live") |
32 | 49 | def docs_live(session): |
| 50 | + """Build and launch a local copy of the guide.""" |
33 | 51 | session.install("-e", ".") |
34 | | - |
35 | | - AUTOBUILD_IGNORE = [ |
36 | | - "_build", |
37 | | - "build_assets", |
38 | | - "tmp", |
39 | | - ] |
40 | | - |
41 | | - # Explicitly include custom CSS in each build since |
42 | | - # sphinx doesn't think _static files should change since, |
43 | | - # well, they're static. |
44 | | - # Include these as the final `filenames` argument |
45 | | - |
46 | | - AUTOBUILD_INCLUDE = [ |
47 | | - os.path.join("_static", "pyos.css") |
48 | | - ] |
49 | | - |
50 | | - # ---------------- |
51 | | - # Assemble command |
52 | | - cmd = ["sphinx-autobuild"] |
| 52 | + cmd = [SPHINX_AUTO_BUILD, *BUILD_PARAMETERS, SOURCE_DIR, OUTPUT_DIR, *session.posargs] |
53 | 53 | for folder in AUTOBUILD_IGNORE: |
54 | 54 | cmd.extend(["--ignore", f"*/{folder}/*"]) |
55 | | - |
56 | | - #cmd.extend(build_command) |
57 | | - cmd.extend(build_command + session.posargs) |
58 | | - |
59 | | - # Use positional arguments if we have them |
60 | | - # if len(session.posargs) > 0: |
61 | | - # cmd.extend(session.posargs) |
62 | | - # # Otherwise use default output and include directory |
63 | | - # else: |
64 | | - # cmd.extend(AUTOBUILD_INCLUDE) |
65 | | - |
66 | 55 | session.run(*cmd) |
67 | 56 |
|
68 | | - |
69 | | - |
70 | 57 | @nox.session(name="docs-clean") |
71 | | -def clean_dir(dir_path=docs_dir): |
72 | | - """ |
73 | | - Clean out the docs directory used in the |
74 | | - live build. |
75 | | - """ |
76 | | - dir_path = pathlib.Path(dir_path) |
77 | | - dir_contents = dir_path.glob('*') |
78 | | - |
| 58 | +def clean_dir(session): |
| 59 | + """Clean out the docs directory used in the live build.""" |
| 60 | + session.warn(f"Cleaning out {OUTPUT_DIR}") |
| 61 | + dir_contents = OUTPUT_DIR.glob('*') |
79 | 62 | for content in dir_contents: |
80 | | - print(content) |
| 63 | + session.log(f'removing {content}') |
81 | 64 | if content.is_dir(): |
82 | 65 | shutil.rmtree(content) |
83 | 66 | else: |
|
0 commit comments