forked from pyOpenSci/python-package-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoxfile.py
84 lines (67 loc) · 1.99 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import pathlib
import shutil
import nox
nox.options.reuse_existing_virtualenvs = True
OUTPUT_DIR = "_build"
docs_dir = os.path.join("_build", "html")
build_command = ["-b", "html", ".", docs_dir]
@nox.session
def docs(session):
session.install("-e", ".")
cmd = ["sphinx-build"]
cmd.extend(build_command + session.posargs)
session.run(*cmd)
@nox.session(name="docs-test")
def docs_test(session):
"""
Same as `docs`, but rebuild everything and fail on warnings for testing
"""
session.install("-e", ".")
cmd = ["sphinx-build"]
cmd.extend(['-W', '--keep-going', '-E', '-a'])
cmd.extend(build_command + session.posargs)
session.run(*cmd)
@nox.session(name="docs-live")
def docs_live(session):
session.install("-e", ".")
AUTOBUILD_IGNORE = [
"_build",
"build_assets",
"tmp",
]
# Explicitly include custom CSS in each build since
# sphinx doesn't think _static files should change since,
# well, they're static.
# Include these as the final `filenames` argument
AUTOBUILD_INCLUDE = [
os.path.join("_static", "pyos.css")
]
# ----------------
# Assemble command
cmd = ["sphinx-autobuild"]
for folder in AUTOBUILD_IGNORE:
cmd.extend(["--ignore", f"*/{folder}/*"])
#cmd.extend(build_command)
cmd.extend(build_command + session.posargs)
# Use positional arguments if we have them
# if len(session.posargs) > 0:
# cmd.extend(session.posargs)
# # Otherwise use default output and include directory
# else:
# cmd.extend(AUTOBUILD_INCLUDE)
session.run(*cmd)
@nox.session(name="docs-clean")
def clean_dir(dir_path=docs_dir):
"""
Clean out the docs directory used in the
live build.
"""
dir_path = pathlib.Path(dir_path)
dir_contents = dir_path.glob('*')
for content in dir_contents:
print(content)
if content.is_dir():
shutil.rmtree(content)
else:
os.remove(content)