Skip to content

Commit

Permalink
Allow passing multiple branches build via CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Dec 8, 2024
1 parent 67842fd commit 6f913e3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
23 changes: 22 additions & 1 deletion tests/test_build_docs_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]

0 comments on commit 6f913e3

Please sign in to comment.