Skip to content
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

Allow passing multiple branches to build via CLI #235

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
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
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -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__.:
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.x"
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,3 +34,10 @@ jobs:
- name: Tox tests
run: |
uvx --with tox-uv tox -e py

- name: Upload coverage
uses: codecov/[email protected]
with:
flags: ${{ matrix.os }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
token: ${{ secrets.CODECOV_ORG_TOKEN }}
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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).

Expand All @@ -12,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`.
hugovk marked this conversation as resolved.
Show resolved Hide resolved
hugovk marked this conversation as resolved.
Show resolved Hide resolved


# Check current version
Expand Down
17 changes: 11 additions & 6 deletions build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
62 changes: 62 additions & 0 deletions tests/test_build_docs_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from build_docs import Version


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"),
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")]


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"),
]
13 changes: 12 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading