|
22 | 22 |
|
23 | 23 | from __future__ import annotations |
24 | 24 |
|
25 | | -from argparse import ArgumentParser |
| 25 | +from argparse import ArgumentParser, Namespace |
26 | 26 | from collections.abc import Sequence |
27 | 27 | from contextlib import suppress, contextmanager |
28 | 28 | from dataclasses import dataclass |
|
44 | 44 | from string import Template |
45 | 45 | from textwrap import indent |
46 | 46 | from time import perf_counter, sleep |
47 | | -from typing import Iterable |
| 47 | +from typing import Iterable, Literal |
48 | 48 | from urllib.parse import urljoin |
49 | 49 |
|
50 | 50 | import jinja2 |
@@ -487,11 +487,16 @@ def parse_args(): |
487 | 487 | parser = ArgumentParser( |
488 | 488 | description="Runs a build of the Python docs for various branches." |
489 | 489 | ) |
| 490 | + parser.add_argument( |
| 491 | + "--select-output", |
| 492 | + choices=("no-html", "only-html"), |
| 493 | + help="Choose what outputs to build.", |
| 494 | + ) |
490 | 495 | parser.add_argument( |
491 | 496 | "-q", |
492 | 497 | "--quick", |
493 | 498 | action="store_true", |
494 | | - help="Make HTML files only (Makefile rules suffixed with -html).", |
| 499 | + help="Run a quick build (only HTML files).", |
495 | 500 | ) |
496 | 501 | parser.add_argument( |
497 | 502 | "-b", |
@@ -589,23 +594,18 @@ class DocBuilder: |
589 | 594 | cpython_repo: Repository |
590 | 595 | build_root: Path |
591 | 596 | www_root: Path |
| 597 | + select_output: Literal["no-html", "only-html"] | None |
592 | 598 | quick: bool |
593 | 599 | group: str |
594 | 600 | log_directory: Path |
595 | 601 | skip_cache_invalidation: bool |
596 | 602 | theme: Path |
597 | 603 |
|
598 | 604 | @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 | + ) |
609 | 609 |
|
610 | 610 | def run(self, http: urllib3.PoolManager) -> bool: |
611 | 611 | """Build and publish a Python doc, for a language, and a version.""" |
@@ -635,7 +635,7 @@ def run(self, http: urllib3.PoolManager) -> bool: |
635 | 635 | @property |
636 | 636 | def checkout(self) -> Path: |
637 | 637 | """Path to CPython git clone.""" |
638 | | - return self.build_root / "cpython" |
| 638 | + return self.build_root / _checkout_name(self.select_output) |
639 | 639 |
|
640 | 640 | def clone_translation(self): |
641 | 641 | self.translation_repo.update() |
@@ -703,15 +703,13 @@ def build(self): |
703 | 703 |
|
704 | 704 | if self.version.status == "EOL": |
705 | 705 | 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" |
715 | 713 | logging.info("Running make %s", maketarget) |
716 | 714 | python = self.venv / "bin" / "python" |
717 | 715 | sphinxbuild = self.venv / "bin" / "sphinx-build" |
@@ -820,28 +818,18 @@ def copy_build_to_webroot(self, http: urllib3.PoolManager) -> None: |
820 | 818 | ";", |
821 | 819 | ] |
822 | 820 | ) |
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: |
845 | 833 | logging.debug("Copying dist files.") |
846 | 834 | run( |
847 | 835 | [ |
@@ -1153,7 +1141,8 @@ def build_docs(args) -> bool: |
1153 | 1141 | del args.languages |
1154 | 1142 | all_built_successfully = True |
1155 | 1143 | 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), |
1157 | 1146 | ) |
1158 | 1147 | while todo: |
1159 | 1148 | version, language = todo.pop() |
@@ -1208,13 +1197,28 @@ def build_docs(args) -> bool: |
1208 | 1197 | return all_built_successfully |
1209 | 1198 |
|
1210 | 1199 |
|
| 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 | + |
1211 | 1206 | def main(): |
1212 | 1207 | """Script entry point.""" |
1213 | 1208 | args = parse_args() |
1214 | 1209 | setup_logging(args.log_directory) |
1215 | 1210 |
|
| 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: |
1216 | 1220 | try: |
1217 | | - lock = zc.lockfile.LockFile(HERE / "build_docs.lock") |
| 1221 | + lock = zc.lockfile.LockFile(HERE / lockfile_name) |
1218 | 1222 | except zc.lockfile.LockError: |
1219 | 1223 | logging.info("Another builder is running... dying...") |
1220 | 1224 | return EX_FAILURE |
|
0 commit comments