Skip to content

Commit 5d26f06

Browse files
authored
Add --select-output (#199)
1 parent 2d438bf commit 5d26f06

File tree

2 files changed

+53
-47
lines changed

2 files changed

+53
-47
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/www/
44
# temporary lock file created while building the docs
55
build_docs.lock
6+
build_docs_archives.lock
7+
build_docs_html.lock
68

79

810
# Created by https://www.gitignore.io/api/python

build_docs.py

+51-47
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from __future__ import annotations
2424

25-
from argparse import ArgumentParser
25+
from argparse import ArgumentParser, Namespace
2626
from collections.abc import Sequence
2727
from contextlib import suppress, contextmanager
2828
from dataclasses import dataclass
@@ -44,7 +44,7 @@
4444
from string import Template
4545
from textwrap import indent
4646
from time import perf_counter, sleep
47-
from typing import Iterable
47+
from typing import Iterable, Literal
4848
from urllib.parse import urljoin
4949

5050
import jinja2
@@ -487,11 +487,16 @@ def parse_args():
487487
parser = ArgumentParser(
488488
description="Runs a build of the Python docs for various branches."
489489
)
490+
parser.add_argument(
491+
"--select-output",
492+
choices=("no-html", "only-html"),
493+
help="Choose what outputs to build.",
494+
)
490495
parser.add_argument(
491496
"-q",
492497
"--quick",
493498
action="store_true",
494-
help="Make HTML files only (Makefile rules suffixed with -html).",
499+
help="Run a quick build (only HTML files).",
495500
)
496501
parser.add_argument(
497502
"-b",
@@ -589,23 +594,18 @@ class DocBuilder:
589594
cpython_repo: Repository
590595
build_root: Path
591596
www_root: Path
597+
select_output: Literal["no-html", "only-html"] | None
592598
quick: bool
593599
group: str
594600
log_directory: Path
595601
skip_cache_invalidation: bool
596602
theme: Path
597603

598604
@property
599-
def full_build(self):
600-
"""Tell if a full build is needed.
601-
602-
A full build is slow; it builds pdf, txt, epub, texinfo, and
603-
archives everything.
604-
605-
A partial build only builds HTML and does not archive, it's
606-
fast.
607-
"""
608-
return not self.quick and not self.language.html_only
605+
def html_only(self):
606+
return (
607+
self.select_output == "only-html" or self.quick or self.language.html_only
608+
)
609609

610610
def run(self, http: urllib3.PoolManager) -> bool:
611611
"""Build and publish a Python doc, for a language, and a version."""
@@ -635,7 +635,7 @@ def run(self, http: urllib3.PoolManager) -> bool:
635635
@property
636636
def checkout(self) -> Path:
637637
"""Path to CPython git clone."""
638-
return self.build_root / "cpython"
638+
return self.build_root / _checkout_name(self.select_output)
639639

640640
def clone_translation(self):
641641
self.translation_repo.update()
@@ -703,15 +703,13 @@ def build(self):
703703

704704
if self.version.status == "EOL":
705705
sphinxopts.append("-D html_context.outdated=1")
706-
maketarget = (
707-
"autobuild-"
708-
+ (
709-
"dev"
710-
if self.version.status in ("in development", "pre-release")
711-
else "stable"
712-
)
713-
+ ("" if self.full_build else "-html")
714-
)
706+
707+
if self.version.status in ("in development", "pre-release"):
708+
maketarget = "autobuild-dev"
709+
else:
710+
maketarget = "autobuild-stable"
711+
if self.html_only:
712+
maketarget += "-html"
715713
logging.info("Running make %s", maketarget)
716714
python = self.venv / "bin" / "python"
717715
sphinxbuild = self.venv / "bin" / "sphinx-build"
@@ -820,28 +818,18 @@ def copy_build_to_webroot(self, http: urllib3.PoolManager) -> None:
820818
";",
821819
]
822820
)
823-
if self.full_build:
824-
run(
825-
[
826-
"rsync",
827-
"-a",
828-
"--delete-delay",
829-
"--filter",
830-
"P archives/",
831-
str(self.checkout / "Doc" / "build" / "html") + "/",
832-
target,
833-
]
834-
)
835-
else:
836-
run(
837-
[
838-
"rsync",
839-
"-a",
840-
str(self.checkout / "Doc" / "build" / "html") + "/",
841-
target,
842-
]
843-
)
844-
if self.full_build:
821+
run(
822+
[
823+
"rsync",
824+
"-a",
825+
"--delete-delay",
826+
"--filter",
827+
"P archives/",
828+
str(self.checkout / "Doc" / "build" / "html") + "/",
829+
target,
830+
]
831+
)
832+
if not self.quick:
845833
logging.debug("Copying dist files.")
846834
run(
847835
[
@@ -1153,7 +1141,8 @@ def build_docs(args) -> bool:
11531141
del args.languages
11541142
all_built_successfully = True
11551143
cpython_repo = Repository(
1156-
"https://github.com/python/cpython.git", args.build_root / "cpython"
1144+
"https://github.com/python/cpython.git",
1145+
args.build_root / _checkout_name(args.select_output),
11571146
)
11581147
while todo:
11591148
version, language = todo.pop()
@@ -1208,13 +1197,28 @@ def build_docs(args) -> bool:
12081197
return all_built_successfully
12091198

12101199

1200+
def _checkout_name(select_output: str | None) -> str:
1201+
if select_output is not None:
1202+
return f"cpython-{select_output}"
1203+
return "cpython"
1204+
1205+
12111206
def main():
12121207
"""Script entry point."""
12131208
args = parse_args()
12141209
setup_logging(args.log_directory)
12151210

1211+
if args.select_output is None:
1212+
build_docs_with_lock(args, "build_docs.lock")
1213+
elif args.select_output == "no-html":
1214+
build_docs_with_lock(args, "build_docs_archives.lock")
1215+
elif args.select_output == "only-html":
1216+
build_docs_with_lock(args, "build_docs_html.lock")
1217+
1218+
1219+
def build_docs_with_lock(args: Namespace, lockfile_name: str) -> int:
12161220
try:
1217-
lock = zc.lockfile.LockFile(HERE / "build_docs.lock")
1221+
lock = zc.lockfile.LockFile(HERE / lockfile_name)
12181222
except zc.lockfile.LockError:
12191223
logging.info("Another builder is running... dying...")
12201224
return EX_FAILURE

0 commit comments

Comments
 (0)