From 3eb7be3d6ef7268c7e378e5e9077b200c7453a99 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:26:03 +0200 Subject: [PATCH 1/5] Add a test for Version.filter for single version --- tests/test_build_docs_version.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/test_build_docs_version.py diff --git a/tests/test_build_docs_version.py b/tests/test_build_docs_version.py new file mode 100644 index 0000000..293388c --- /dev/null +++ b/tests/test_build_docs_version.py @@ -0,0 +1,19 @@ +from build_docs import Version + + +def test_filter() -> None: + # Arrange + versions = [ + Version("3.14", status="feature"), + Version("3.13", status="bugfix"), + Version("3.12", status="bugfix"), + Version("3.11", status="security"), + Version("3.10", status="security"), + Version("3.9", status="security"), + ] + + # Act + filtered = Version.filter(versions, "3.13") + + # Assert + assert filtered == [Version("3.13", status="security")] From 978b8ec464876141f2e05504b12d28763ea9fd81 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:28:39 +0200 Subject: [PATCH 2/5] Measure test coverage --- .coveragerc | 7 +++++++ .github/workflows/lint.yml | 2 ++ .github/workflows/test.yml | 9 +++++++++ README.md | 5 +++++ tox.ini | 13 ++++++++++++- 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..0f12707 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,7 @@ +# .coveragerc to control coverage.py + +[report] +# Regexes for lines to exclude from consideration +exclude_also = + # Don't complain if non-runnable code isn't run: + if __name__ == .__main__.: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d553e49..70ff819 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,6 +15,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + persist-credentials: false - uses: actions/setup-python@v5 with: python-version: "3.x" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d74e607..e70970e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + persist-credentials: false - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 @@ -32,3 +34,10 @@ jobs: - name: Tox tests run: | uvx --with tox-uv tox -e py + + - name: Upload coverage + uses: codecov/codecov-action@v5.1.1 + with: + flags: ${{ matrix.os }} + name: ${{ matrix.os }} Python ${{ matrix.python-version }} + token: ${{ secrets.CODECOV_ORG_TOKEN }} diff --git a/README.md b/README.md index 767014c..502e968 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +# docsbuild-scripts + +[![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) +[![Codecov](https://codecov.io/gh/python/docsbuild-scripts/branch/main/graph/badge.svg)](https://codecov.io/gh/python/docsbuild-scripts) + This repository contains scripts for automatically building the Python documentation on [docs.python.org](https://docs.python.org). diff --git a/tox.ini b/tox.ini index 40a034d..4b05170 100644 --- a/tox.ini +++ b/tox.ini @@ -12,8 +12,19 @@ skip_install = true deps = -r requirements.txt pytest + pytest-cov +pass_env = + FORCE_COLOR +set_env = + COVERAGE_CORE = sysmon commands = - {envpython} -m pytest {posargs} + {envpython} -m pytest \ + --cov . \ + --cov tests \ + --cov-report html \ + --cov-report term \ + --cov-report xml \ + {posargs} [testenv:lint] skip_install = true From 67842fdf8f5e9e6223e6eae63ad137cf27fccf65 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:31:34 +0200 Subject: [PATCH 3/5] Add a test for Version.filter with default branch --- tests/test_build_docs_version.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/test_build_docs_version.py b/tests/test_build_docs_version.py index 293388c..5908f4d 100644 --- a/tests/test_build_docs_version.py +++ b/tests/test_build_docs_version.py @@ -1,7 +1,29 @@ from build_docs import Version -def test_filter() -> None: +def test_filter_default() -> None: + # Arrange + versions = [ + Version("3.14", status="feature"), + Version("3.13", status="bugfix"), + Version("3.12", status="bugfix"), + Version("3.11", status="security"), + Version("3.10", status="security"), + Version("3.9", status="security"), + ] + + # Act + filtered = Version.filter(versions) + + # Assert + assert filtered == [ + Version("3.14", status="feature"), + Version("3.13", status="bugfix"), + Version("3.12", status="bugfix"), + ] + + +def test_filter_one() -> None: # Arrange versions = [ Version("3.14", status="feature"), From 6f913e3bfb8f2513b04c968e0344997f31458295 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:54:08 +0200 Subject: [PATCH 4/5] Allow passing multiple branches build via CLI --- README.md | 2 +- build_docs.py | 17 +++++++++++------ tests/test_build_docs_version.py | 23 ++++++++++++++++++++++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 502e968..2cfd702 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ python3 ./build_docs.py --quick --build-root ./build_root --www-root ./www --log ``` If you don't need to build all translations of all branches, add -`--language en --branch main`. +`--language en --branches main`. # Check current version diff --git a/build_docs.py b/build_docs.py index f14cc2b..1441e22 100755 --- a/build_docs.py +++ b/build_docs.py @@ -139,16 +139,19 @@ def title(self): return f"Python {self.name} ({self.status})" @staticmethod - def filter(versions, branch=None): + def filter(versions, branches=None): """Filter the given versions. - If *branch* is given, only *versions* matching *branch* are returned. + If *branches* is given, only *versions* matching *branches* are returned. Else all live versions are returned (this means no EOL and no security-fixes branches). """ - if branch: - return [v for v in versions if branch in (v.name, v.branch_or_tag)] + if branches: + return [ + v for v in versions if v.name in branches or v.branch_or_tag in branches + ] + return [v for v in versions if v.status not in ("EOL", "security-fixes")] @staticmethod @@ -518,9 +521,11 @@ def parse_args(): ) parser.add_argument( "-b", - "--branch", + "--branch", # Deprecated + "--branches", + nargs="*", metavar="3.12", - help="Version to build (defaults to all maintained branches).", + help="Versions to build (defaults to all maintained branches).", ) parser.add_argument( "-r", diff --git a/tests/test_build_docs_version.py b/tests/test_build_docs_version.py index 5908f4d..eb5178a 100644 --- a/tests/test_build_docs_version.py +++ b/tests/test_build_docs_version.py @@ -35,7 +35,28 @@ def test_filter_one() -> None: ] # Act - filtered = Version.filter(versions, "3.13") + filtered = Version.filter(versions, ["3.13"]) # Assert assert filtered == [Version("3.13", status="security")] + + +def test_filter_multiple() -> None: + # Arrange + versions = [ + Version("3.14", status="feature"), + Version("3.13", status="bugfix"), + Version("3.12", status="bugfix"), + Version("3.11", status="security"), + Version("3.10", status="security"), + Version("3.9", status="security"), + ] + + # Act + filtered = Version.filter(versions, ["3.13", "3.14"]) + + # Assert + assert filtered == [ + Version("3.14", status="feature"), + Version("3.13", status="security"), + ] From 23df845151f798633c4621d20262cb19dcdbd2ea Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:46:58 +0200 Subject: [PATCH 5/5] Correct --language to --languages in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2cfd702..137261d 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ python3 ./build_docs.py --quick --build-root ./build_root --www-root ./www --log ``` If you don't need to build all translations of all branches, add -`--language en --branches main`. +`--languages en --branches main`. # Check current version