Skip to content

Add --select-output #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/www/
# temporary lock file created while building the docs
build_docs.lock
build_docs_archives.lock
build_docs_html.lock


# Created by https://www.gitignore.io/api/python
Expand Down
85 changes: 41 additions & 44 deletions build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from string import Template
from textwrap import indent
from time import perf_counter, sleep
from typing import Iterable
from typing import Iterable, Literal
from urllib.parse import urljoin

import jinja2
Expand Down Expand Up @@ -487,11 +487,16 @@ def parse_args():
parser = ArgumentParser(
description="Runs a build of the Python docs for various branches."
)
parser.add_argument(
"--select-output",
choices=("no-html", "only-html"),
help="Choose what outputs to build.",
)
parser.add_argument(
"-q",
"--quick",
action="store_true",
help="Make HTML files only (Makefile rules suffixed with -html).",
help="Run a quick build (only HTML files).",
)
parser.add_argument(
"-b",
Expand Down Expand Up @@ -589,23 +594,18 @@ class DocBuilder:
cpython_repo: Repository
build_root: Path
www_root: Path
select_output: Literal["no-html", "only-html"] | None
quick: bool
group: str
log_directory: Path
skip_cache_invalidation: bool
theme: Path

@property
def full_build(self):
"""Tell if a full build is needed.

A full build is slow; it builds pdf, txt, epub, texinfo, and
archives everything.

A partial build only builds HTML and does not archive, it's
fast.
"""
return not self.quick and not self.language.html_only
def html_only(self):
return (
self.select_output == "only-html" or self.quick or self.language.html_only
)

def run(self, http: urllib3.PoolManager) -> bool:
"""Build and publish a Python doc, for a language, and a version."""
Expand Down Expand Up @@ -698,15 +698,13 @@ def build(self):

if self.version.status == "EOL":
sphinxopts.append("-D html_context.outdated=1")
maketarget = (
"autobuild-"
+ (
"dev"
if self.version.status in ("in development", "pre-release")
else "stable"
)
+ ("" if self.full_build else "-html")
)

if self.version.status in ("in development", "pre-release"):
maketarget = "autobuild-dev"
else:
maketarget = "autobuild-stable"
if self.html_only:
maketarget += "-html"
logging.info("Running make %s", maketarget)
python = self.venv / "bin" / "python"
sphinxbuild = self.venv / "bin" / "sphinx-build"
Expand Down Expand Up @@ -815,28 +813,18 @@ def copy_build_to_webroot(self, http: urllib3.PoolManager) -> None:
";",
]
)
if self.full_build:
run(
[
"rsync",
"-a",
"--delete-delay",
"--filter",
"P archives/",
str(self.checkout / "Doc" / "build" / "html") + "/",
target,
]
)
else:
run(
[
"rsync",
"-a",
str(self.checkout / "Doc" / "build" / "html") + "/",
target,
]
)
if self.full_build:
run(
[
"rsync",
"-a",
"--delete-delay",
"--filter",
"P archives/",
str(self.checkout / "Doc" / "build" / "html") + "/",
target,
]
)
if not self.quick:
logging.debug("Copying dist files.")
run(
[
Expand Down Expand Up @@ -1201,8 +1189,17 @@ def main():
args = parse_args()
setup_logging(args.log_directory)

if args.select_output is None:
build_docs_with_lock(args, "build_docs.lock")
elif args.select_output == "no-html":
build_docs_with_lock(args, "build_docs_archives.lock")
elif args.select_output == "only-html":
build_docs_with_lock(args, "build_docs_html.lock")


def build_docs_with_lock(args, lockfile_name):
try:
lock = zc.lockfile.LockFile(HERE / "build_docs.lock")
lock = zc.lockfile.LockFile(HERE / lockfile_name)
except zc.lockfile.LockError:
logging.info("Another builder is running... dying...")
return EX_FAILURE
Expand Down