Skip to content

Commit 2113fd7

Browse files
authored
Allow passing multiple branches to build via CLI (#235)
1 parent 946b6bc commit 2113fd7

File tree

6 files changed

+104
-11
lines changed

6 files changed

+104
-11
lines changed

Diff for: .coveragerc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# .coveragerc to control coverage.py
2+
3+
[report]
4+
# Regexes for lines to exclude from consideration
5+
exclude_also =
6+
# Don't complain if non-runnable code isn't run:
7+
if __name__ == .__main__.:

Diff for: .github/workflows/test.yml

+7
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ jobs:
3333
- name: Tox tests
3434
run: |
3535
uvx --with tox-uv tox -e py
36+
37+
- name: Upload coverage
38+
uses: codecov/codecov-action@v5
39+
with:
40+
flags: ${{ matrix.os }}
41+
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
42+
token: ${{ secrets.CODECOV_ORG_TOKEN }}

Diff for: README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# docsbuild-scripts
2+
3+
[![GitHub Actions status](https://github.com/python/docsbuild-scripts/actions/workflows/test.yml/badge.svg)](https://github.com/python/docsbuild-scripts/actions/workflows/test.yml)
4+
[![Codecov](https://codecov.io/gh/python/docsbuild-scripts/branch/main/graph/badge.svg)](https://codecov.io/gh/python/docsbuild-scripts)
5+
16
This repository contains scripts for automatically building the Python
27
documentation on [docs.python.org](https://docs.python.org).
38

@@ -12,7 +17,7 @@ python3 ./build_docs.py --quick --build-root ./build_root --www-root ./www --log
1217
```
1318

1419
If you don't need to build all translations of all branches, add
15-
`--language en --branch main`.
20+
`--languages en --branches main`.
1621

1722

1823
## Check current version

Diff for: build_docs.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,17 @@ def from_json(cls, data) -> Versions:
8787
)
8888
return cls(versions)
8989

90-
def filter(self, branch: str = "") -> Sequence[Version]:
90+
def filter(self, branches: Sequence[str] = ()) -> Sequence[Version]:
9191
"""Filter the given versions.
9292
93-
If *branch* is given, only *versions* matching *branch* are returned.
93+
If *branches* is given, only *versions* matching *branches* are returned.
9494
9595
Else all live versions are returned (this means no EOL and no
9696
security-fixes branches).
9797
"""
98-
if branch:
99-
return [v for v in self if branch in (v.name, v.branch_or_tag)]
98+
if branches:
99+
branches = frozenset(branches)
100+
return [v for v in self if {v.name, v.branch_or_tag} & branches]
100101
return [v for v in self if v.status not in {"EOL", "security-fixes"}]
101102

102103
@property
@@ -936,9 +937,10 @@ def parse_args():
936937
)
937938
parser.add_argument(
938939
"-b",
939-
"--branch",
940+
"--branches",
941+
nargs="*",
940942
metavar="3.12",
941-
help="Version to build (defaults to all maintained branches).",
943+
help="Versions to build (defaults to all maintained branches).",
942944
)
943945
parser.add_argument(
944946
"-r",
@@ -972,7 +974,6 @@ def parse_args():
972974
)
973975
parser.add_argument(
974976
"--languages",
975-
"--language",
976977
nargs="*",
977978
help="Language translation, as a PEP 545 language tag like"
978979
" 'fr' or 'pt-br'. "
@@ -1046,10 +1047,10 @@ def build_docs(args: argparse.Namespace) -> bool:
10461047
# This runs languages in config.toml order and versions newest first.
10471048
todo = [
10481049
(version, language)
1049-
for version in versions.filter(args.branch)
1050+
for version in versions.filter(args.branches)
10501051
for language in reversed(languages.filter(args.languages))
10511052
]
1052-
del args.branch
1053+
del args.branches
10531054
del args.languages
10541055

10551056
build_succeeded = set()

Diff for: tests/test_build_docs_versions.py

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from build_docs import Versions, Version
2+
3+
4+
def test_filter_default() -> None:
5+
# Arrange
6+
versions = Versions([
7+
Version("3.14", status="feature"),
8+
Version("3.13", status="bugfix"),
9+
Version("3.12", status="bugfix"),
10+
Version("3.11", status="security"),
11+
Version("3.10", status="security"),
12+
Version("3.9", status="security"),
13+
])
14+
15+
# Act
16+
filtered = versions.filter()
17+
18+
# Assert
19+
assert filtered == [
20+
Version("3.14", status="feature"),
21+
Version("3.13", status="bugfix"),
22+
Version("3.12", status="bugfix"),
23+
]
24+
25+
26+
def test_filter_one() -> None:
27+
# Arrange
28+
versions = Versions([
29+
Version("3.14", status="feature"),
30+
Version("3.13", status="bugfix"),
31+
Version("3.12", status="bugfix"),
32+
Version("3.11", status="security"),
33+
Version("3.10", status="security"),
34+
Version("3.9", status="security"),
35+
])
36+
37+
# Act
38+
filtered = versions.filter(["3.13"])
39+
40+
# Assert
41+
assert filtered == [Version("3.13", status="security")]
42+
43+
44+
def test_filter_multiple() -> None:
45+
# Arrange
46+
versions = Versions([
47+
Version("3.14", status="feature"),
48+
Version("3.13", status="bugfix"),
49+
Version("3.12", status="bugfix"),
50+
Version("3.11", status="security"),
51+
Version("3.10", status="security"),
52+
Version("3.9", status="security"),
53+
])
54+
55+
# Act
56+
filtered = versions.filter(["3.13", "3.14"])
57+
58+
# Assert
59+
assert filtered == [
60+
Version("3.14", status="feature"),
61+
Version("3.13", status="security"),
62+
]

Diff for: tox.ini

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@ skip_install = true
1212
deps =
1313
-r requirements.txt
1414
pytest
15+
pytest-cov
16+
pass_env =
17+
FORCE_COLOR
18+
set_env =
19+
COVERAGE_CORE = sysmon
1520
commands =
16-
{envpython} -m pytest {posargs}
21+
{envpython} -m pytest \
22+
--cov . \
23+
--cov tests \
24+
--cov-report html \
25+
--cov-report term \
26+
--cov-report xml \
27+
{posargs}
1728

1829
[testenv:lint]
1930
skip_install = true

0 commit comments

Comments
 (0)