Skip to content

Commit 01d096a

Browse files
authored
Use a specific venv for specific sphinx versions. (#92)
1 parent 0f1296e commit 01d096a

4 files changed

Lines changed: 42 additions & 47 deletions

File tree

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
This repository contains scripts for automatically building the Python
22
documentation on [docs.python.org](https://docs.python.org).
33

4+
45
# How to test it?
56

6-
$ mkdir -p www logs build_root
7-
$ python3 -m venv build_root/venv/
8-
$ build_root/venv/bin/python -m pip install -r requirements.txt
9-
$ python3 ./build_docs.py --quick --build-root build_root --www-root www --log-directory logs --group $(id -g) --skip-cache-invalidation
7+
The following command should build all maintained versions and
8+
translations in ``./www``, beware it can take a few hours:
9+
10+
$ python3 ./build_docs.py --quick --build-root ./build_root --www-root ./www --log-directory ./logs --group $(id -g) --skip-cache-invalidation
11+
12+
If you don't need to build all translations of all branches, add
13+
``--language en --branch master``.
1014

1115

1216
# Check current version

build_docs.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
sentry_sdk.init()
5959

6060
VERSION = "19.0"
61-
61+
DEFAULT_SPHINX_VERSION = "2.3.1"
6262

6363
if not hasattr(shlex, "join"):
6464
# Add shlex.join if missing (pre 3.8)
@@ -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=DEFAULT_SPHINX_VERSION):
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):
@@ -93,11 +94,13 @@ def title(self):
9394
)
9495

9596
# EOL and security-fixes are not automatically built, no need to remove them
96-
# from the list.
97+
# from the list, this way we can still rebuild them manually as needed.
98+
# Please pin the sphinx_versions of EOL and security-fixes, as we're not maintaining
99+
# their doc, they don't follow Sphinx deprecations.
97100
VERSIONS = [
98-
Version("2.7", "2.7", "EOL"),
99-
Version("3.5", "3.5", "security-fixes"),
100-
Version("3.6", "3.6", "security-fixes"),
101+
Version("2.7", "2.7", "EOL", sphinx_version="2.3.1"),
102+
Version("3.5", "3.5", "security-fixes", sphinx_version="1.8.4"),
103+
Version("3.6", "3.6", "security-fixes", sphinx_version="2.3.1"),
101104
Version("3.7", "3.7", "stable"),
102105
Version("3.8", "3.8", "stable"),
103106
Version("3.9", "3.9", "pre-release"),
@@ -455,6 +458,25 @@ def build_one(
455458
logging.info("Build done for version: %s, language: %s", version.name, language.tag)
456459

457460

461+
def build_venv(build_root, version):
462+
"""Build a venv for the specific version.
463+
This is used to pin old Sphinx versions to old cpython branches.
464+
"""
465+
requirements = [
466+
"blurb",
467+
"jieba",
468+
"python-docs-theme",
469+
"sphinx=={}".format(version.sphinx_version),
470+
]
471+
venv_path = os.path.join(build_root, "venv-with-sphinx-" + version.sphinx_version)
472+
shell_out(["python3", "-m", "venv", venv_path])
473+
shell_out(
474+
[os.path.join(venv_path, "bin", "python"), "-m", "pip", "install"]
475+
+ requirements
476+
)
477+
return venv_path
478+
479+
458480
def copy_build_to_webroot(
459481
build_root,
460482
version,
@@ -469,6 +491,7 @@ def copy_build_to_webroot(
469491
logging.info(
470492
"Publishing start for version: %s, language: %s", version.name, language.tag
471493
)
494+
Path(www_root).mkdir(parents=True, exist_ok=True)
472495
checkout = os.path.join(
473496
build_root, version.name, "cpython-{lang}".format(lang=language.tag)
474497
)
@@ -670,6 +693,7 @@ def setup_logging(log_directory):
670693
if sys.stderr.isatty():
671694
logging.basicConfig(format="%(levelname)s:%(message)s", stream=sys.stderr)
672695
else:
696+
Path(log_directory).mkdir(parents=True, exist_ok=True)
673697
handler = logging.handlers.WatchedFileHandler(
674698
os.path.join(log_directory, "docsbuild.log")
675699
)
@@ -691,7 +715,6 @@ def main():
691715
if args.www_root:
692716
args.www_root = os.path.abspath(args.www_root)
693717
setup_logging(args.log_directory)
694-
venv = os.path.join(args.build_root, "venv")
695718
if args.branch:
696719
versions_to_build = [
697720
version
@@ -720,6 +743,7 @@ def main():
720743
scope.set_tag("version", version.name)
721744
scope.set_tag("language", language.tag)
722745
try:
746+
venv = build_venv(args.build_root, version)
723747
build_one(
724748
version,
725749
args.quick,

requirements.in

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
blurb
2-
jieba
3-
python-docs-theme
4-
requests
51
sentry-sdk
6-
sphinx==2.3.1

requirements.txt

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,6 @@
44
#
55
# pip-compile requirements.in
66
#
7-
alabaster==0.7.12 # via sphinx
8-
babel==2.7.0 # via sphinx
9-
blurb==1.0.7 # via -r requirements.in (line 1)
10-
certifi==2019.11.28 # via requests, sentry-sdk
11-
chardet==3.0.4 # via requests
12-
docutils==0.15.2 # via sphinx
13-
idna==2.8 # via requests
14-
imagesize==1.1.0 # via sphinx
15-
jieba==0.42.1 # via -r requirements.in (line 2)
16-
jinja2==2.10.3 # via sphinx
17-
markupsafe==1.1.1 # via jinja2
18-
packaging==19.2 # via sphinx
19-
pygments==2.5.2 # via sphinx
20-
pyparsing==2.4.5 # via packaging
21-
python-docs-theme==2020.1 # via -r requirements.in (line 3)
22-
pytz==2019.3 # via babel
23-
requests==2.22.0 # via -r requirements.in (line 4), sphinx
24-
sentry-sdk==0.13.5 # via -r requirements.in (line 5)
25-
six==1.13.0 # via packaging
26-
snowballstemmer==2.0.0 # via sphinx
27-
sphinx==2.3.1 # via -r requirements.in (line 6)
28-
sphinxcontrib-applehelp==1.0.1 # via sphinx
29-
sphinxcontrib-devhelp==1.0.1 # via sphinx
30-
sphinxcontrib-htmlhelp==1.0.2 # via sphinx
31-
sphinxcontrib-jsmath==1.0.1 # via sphinx
32-
sphinxcontrib-qthelp==1.0.2 # via sphinx
33-
sphinxcontrib-serializinghtml==1.1.3 # via sphinx
34-
urllib3==1.25.7 # via requests, sentry-sdk
35-
36-
# The following packages are considered to be unsafe in a requirements file:
37-
# setuptools
7+
certifi==2020.6.20 # via sentry-sdk
8+
sentry-sdk==0.15.1 # via -r requirements.in
9+
urllib3==1.25.9 # via sentry-sdk

0 commit comments

Comments
 (0)