Skip to content

Commit 45c143b

Browse files
committed
Cleaned up the current noxfile.py
1 parent f9edf88 commit 45c143b

File tree

1 file changed

+36
-53
lines changed

1 file changed

+36
-53
lines changed

noxfile.py

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,79 +5,62 @@
55

66
nox.options.reuse_existing_virtualenvs = True
77

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+
]
1133

1234
@nox.session
1335
def docs(session):
36+
"""Build the packaging guide."""
1437
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]
1739
session.run(*cmd)
1840

1941
@nox.session(name="docs-test")
2042
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."""
2444
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]
2846
session.run(*cmd)
2947

30-
3148
@nox.session(name="docs-live")
3249
def docs_live(session):
50+
"""Build and launch a local copy of the guide."""
3351
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]
5353
for folder in AUTOBUILD_IGNORE:
5454
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-
6655
session.run(*cmd)
6756

68-
69-
7057
@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('*')
7962
for content in dir_contents:
80-
print(content)
63+
session.log(f'removing {content}')
8164
if content.is_dir():
8265
shutil.rmtree(content)
8366
else:

0 commit comments

Comments
 (0)