Skip to content

Commit 408f8dc

Browse files
committed
Allow to build from either a branch, or a tag.
1 parent b9ea6e5 commit 408f8dc

File tree

1 file changed

+65
-17
lines changed

1 file changed

+65
-17
lines changed

build_docs.py

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,23 @@ class Version:
6363
def __init__(
6464
self,
6565
name,
66-
branch,
66+
*,
67+
branch=None,
68+
tag=None,
6769
status,
6870
sphinx_version,
69-
sphinxopts=[],
71+
sphinxopts=(),
7072
):
7173
if status not in self.STATUSES:
7274
raise ValueError(
7375
"Version status expected to be in {}".format(", ".join(self.STATUSES))
7476
)
7577
self.name = name
76-
self.branch = branch
78+
if branch is not None and tag is not None:
79+
raise ValueError("Please build a version from either a branch or a tag.")
80+
if branch is None and tag is None:
81+
raise ValueError("Please build a version with at least a branch or a tag.")
82+
self.branch_or_tag = branch or tag
7783
self.status = status
7884
self.sphinx_version = sphinx_version
7985
self.sphinxopts = list(sphinxopts)
@@ -117,7 +123,7 @@ def filter(versions, branch=None):
117123
security-fixes branches).
118124
"""
119125
if branch:
120-
return [v for v in versions if branch in (v.name, v.branch)]
126+
return [v for v in versions if branch in (v.name, v.branch_or_tag)]
121127
return [v for v in versions if v.status not in ("EOL", "security-fixes")]
122128

123129
@staticmethod
@@ -135,18 +141,58 @@ def current_dev(versions):
135141

136142
# EOL and security-fixes are not automatically built, no need to remove them
137143
# from the list, this way we can still rebuild them manually as needed.
138-
# Please pin the sphinx_versions of EOL and security-fixes, as we're not maintaining
139-
# their doc, they don't follow Sphinx deprecations.
144+
#
145+
# Please keep the list in reverse-order for ease of editing.
140146
VERSIONS = [
141-
Version("2.7", "2.7", "EOL", sphinx_version="2.3.1"),
142-
Version("3.5", "3.5", "EOL", sphinx_version="1.8.4"),
143-
Version("3.6", "3.6", "EOL", sphinx_version="2.3.1"),
144-
Version("3.7", "3.7", "security-fixes", sphinx_version="2.3.1"),
145-
Version("3.8", "3.8", "security-fixes", sphinx_version="2.4.4"),
146-
Version("3.9", "3.9", "stable", sphinx_version="2.4.4"),
147-
Version("3.10", "3.10", "stable", sphinx_version="3.2.1", sphinxopts=["-j4"]),
148147
Version(
149-
"3.11", "main", "in development", sphinx_version="4.2.0", sphinxopts=["-j4"]
148+
"3.11",
149+
branch="origin/main",
150+
status="in development",
151+
sphinx_version="4.2.0",
152+
sphinxopts=["-j4"],
153+
),
154+
Version(
155+
"3.10",
156+
branch="origin/3.10",
157+
status="stable",
158+
sphinx_version="3.2.1",
159+
sphinxopts=["-j4"],
160+
),
161+
Version(
162+
"3.9",
163+
branch="origin/3.9",
164+
status="stable",
165+
sphinx_version="2.4.4",
166+
),
167+
Version(
168+
"3.8",
169+
branch="origin/3.8",
170+
status="security-fixes",
171+
sphinx_version="2.4.4",
172+
),
173+
Version(
174+
"3.7",
175+
branch="origin/3.7",
176+
status="security-fixes",
177+
sphinx_version="2.3.1",
178+
),
179+
Version(
180+
"3.6",
181+
tag="3.6",
182+
status="EOL",
183+
sphinx_version="2.3.1",
184+
),
185+
Version(
186+
"3.5",
187+
tag="3.5",
188+
status="EOL",
189+
sphinx_version="1.8.4",
190+
),
191+
Version(
192+
"2.7",
193+
tag="2.7",
194+
status="EOL",
195+
sphinx_version="2.3.1",
150196
),
151197
]
152198

@@ -251,7 +297,7 @@ def git_clone(repository, directory, branch_or_tag=None):
251297
raise AssertionError("Not a git repository.")
252298
run(["git", "-C", directory, "fetch"])
253299
if branch_or_tag:
254-
run(["git", "-C", directory, "reset", "--hard", branch_or_tag])
300+
run(["git", "-C", directory, "reset", "--hard", branch_or_tag, "--"])
255301
run(["git", "-C", directory, "clean", "-dfqx"])
256302
except (subprocess.CalledProcessError, AssertionError):
257303
if os.path.exists(directory):
@@ -260,7 +306,7 @@ def git_clone(repository, directory, branch_or_tag=None):
260306
os.makedirs(directory, mode=0o775)
261307
run(["git", "clone", repository, directory])
262308
if branch_or_tag:
263-
run(["git", "-C", directory, "reset", "--hard", branch_or_tag])
309+
run(["git", "-C", directory, "reset", "--hard", branch_or_tag, "--"])
264310

265311

266312
def version_to_tuple(version):
@@ -637,7 +683,9 @@ def build(self):
637683
if self.version.status == "EOL":
638684
sphinxopts.append("-D html_context.outdated=1")
639685
git_clone(
640-
"https://github.com/python/cpython.git", self.checkout, self.version.branch
686+
"https://github.com/python/cpython.git",
687+
self.checkout,
688+
self.version.branch_or_tag,
641689
)
642690
maketarget = (
643691
"autobuild-"

0 commit comments

Comments
 (0)