Skip to content

Commit 8e36dc8

Browse files
committed
Use a specific venv for specific sphinx versions.
1 parent ecdcd7d commit 8e36dc8

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

build_docs.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@
7070
class Version:
7171
STATUSES = {"EOL", "security-fixes", "stable", "pre-release", "in development"}
7272

73-
def __init__(self, name, branch, status):
73+
def __init__(self, name, branch, status, sphinx_version=None):
7474
if status not in self.STATUSES:
7575
raise ValueError(
7676
"Version status expected to be in {}".format(", ".join(self.STATUSES))
7777
)
7878
self.name = name
7979
self.branch = branch
8080
self.status = status
81+
self.sphinx_version = sphinx_version
8182

8283
@property
8384
def url(self):
@@ -96,7 +97,7 @@ def title(self):
9697
# from the list.
9798
VERSIONS = [
9899
Version("2.7", "2.7", "EOL"),
99-
Version("3.5", "3.5", "security-fixes"),
100+
Version("3.5", "3.5", "security-fixes", sphinx_version="1.8.4"),
100101
Version("3.6", "3.6", "security-fixes"),
101102
Version("3.7", "3.7", "stable"),
102103
Version("3.8", "3.8", "stable"),
@@ -449,6 +450,29 @@ def build_one(
449450
logging.info("Build done for version: %s, language: %s", version.name, language.tag)
450451

451452

453+
def build_venv(build_root, version):
454+
"""Build a venv for the specific version.
455+
This is used to pin old Sphinx versions to old cpython branches.
456+
"""
457+
requirements = ["blurb", "jieba", "python-docs-theme"]
458+
venv_path = os.path.join(build_root, "venv-" + version.sphinx_version)
459+
shell_out(["python3", "-m", "venv", venv_path])
460+
shell_out(
461+
[os.path.join(venv_path, "bin", "python"), "-m", "pip", "install"]
462+
+ requirements
463+
)
464+
shell_out(
465+
[
466+
os.path.join(venv_path, "bin", "python"),
467+
"-m",
468+
"pip",
469+
"install",
470+
"sphinx=={}".format(version.sphinx_version),
471+
]
472+
)
473+
return venv_path
474+
475+
452476
def copy_build_to_webroot(
453477
build_root,
454478
version,
@@ -685,7 +709,7 @@ def main():
685709
if args.www_root:
686710
args.www_root = os.path.abspath(args.www_root)
687711
setup_logging(args.log_directory)
688-
venv = os.path.join(args.build_root, "venv")
712+
default_venv = os.path.join(args.build_root, "venv")
689713
if args.branch:
690714
versions_to_build = [
691715
version
@@ -714,6 +738,10 @@ def main():
714738
scope.set_tag("version", version.name)
715739
scope.set_tag("language", language.tag)
716740
try:
741+
if version.sphinx_version:
742+
venv = build_venv(args.build_root, version)
743+
else:
744+
venv = default_venv
717745
build_one(
718746
version,
719747
args.quick,

0 commit comments

Comments
 (0)