Skip to content

Commit

Permalink
Fix version parsing for python binary packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Oct 1, 2024
1 parent 6566acc commit 7be3045
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ jobs:
run: | # should take ~30s; writes wheels to wrappers/python/dist
export PAGEFIND_PYTHON_LOG_LEVEL=DEBUG
python -m scripts.build.all_binary_only_wheels \
--git-tag "${{ github.ref_name }}" \
--tag "${{ github.ref_name }}" \
--bin-dir ./vendor
- name: package python api
working-directory: ./wrappers/python
Expand Down
7 changes: 5 additions & 2 deletions wrappers/python/scripts/build/all_binary_only_wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
write_pagefind_bin_only_wheel,
)
from .get_pagefind_release import download, find_bins
from .versioning import process_tag

__candidates = (
"pagefind",
Expand Down Expand Up @@ -87,14 +88,16 @@ def parse_args() -> Args:
if tag_name is None:
raise ValueError("tag_name is None")
assert re.match(
r"^v\d+\.\d+\.\d+(-\w+)?", tag_name
r"^v\d+\.\d+\.\d+(-\w+\.?\d*)?", tag_name
), f"Invalid tag_name: {tag_name}"
check_platforms(certified)

if not dry_run:
dist_dir.rmdir()
dist_dir.mkdir(exist_ok=True)

version = process_tag(tag_name)

for tar_gz in certified:
log.info("Processing %s", tar_gz)
llvm_triple = get_llvm_triple(tar_gz)
Expand All @@ -112,6 +115,6 @@ def parse_args() -> Args:
write_pagefind_bin_only_wheel(
executable=find_bin(temp_dir),
output_dir=dist_dir,
version=tag_name.removeprefix("v"),
version=version,
platform=platform,
)
38 changes: 1 addition & 37 deletions wrappers/python/scripts/build/api_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from argparse import ArgumentParser

from . import python_root, setup_logging
from .versioning import process_tag

pyproject_toml = python_root / "pyproject.toml"

Expand All @@ -16,43 +17,6 @@
cli.add_argument("--tag", required=True, help="The version to build.")
log = logging.getLogger(__name__)


def process_tag(tag: str) -> str:
"""Convert a git tag to a version string compliant with PEP 440.
See https://peps.python.org/pep-0440/#public-version-identifiers
"""
pattern = (
# note that this pattern accepts a superset of the tagging pattern used
# in this repository.
r"^v(?P<major>\d+)"
r"\.(?P<minor>\d+)"
r"\.(?P<patch>\d+)"
r"(-"
r"(?P<prerelease_kind>alpha|beta|rc)"
r"\.?(?P<prerelease_number>\d+)"
")?"
)
parts = re.match(pattern, tag)
if parts is None:
raise ValueError(f"Invalid tag: `{tag}` does not match pattern `{pattern}`")
major = int(parts["major"])
minor = int(parts["minor"])
patch = int(parts["patch"])
suffix = ""

if (prerelease_kind := parts["prerelease_kind"]) is not None:
if prerelease_kind == "rc":
suffix = "rc"
elif prerelease_kind.startswith("alpha"):
suffix = "a"
elif prerelease_kind.startswith("beta"):
suffix = "b"
if (prerelease_number := parts["prerelease_number"]) is not None:
suffix += str(int(prerelease_number))

return f"{major}.{minor}.{patch}{suffix}"


def main() -> None:
setup_logging()
args = cli.parse_args()
Expand Down
36 changes: 36 additions & 0 deletions wrappers/python/scripts/build/versioning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import re

def process_tag(tag: str) -> str:
"""Convert a git tag to a version string compliant with PEP 440.
See https://peps.python.org/pep-0440/#public-version-identifiers
"""
pattern = (
# note that this pattern accepts a superset of the tagging pattern used
# in this repository.
r"^v(?P<major>\d+)"
r"\.(?P<minor>\d+)"
r"\.(?P<patch>\d+)"
r"(-"
r"(?P<prerelease_kind>alpha|beta|rc)"
r"\.?(?P<prerelease_number>\d+)"
")?"
)
parts = re.match(pattern, tag)
if parts is None:
raise ValueError(f"Invalid tag: `{tag}` does not match pattern `{pattern}`")
major = int(parts["major"])
minor = int(parts["minor"])
patch = int(parts["patch"])
suffix = ""

if (prerelease_kind := parts["prerelease_kind"]) is not None:
if prerelease_kind == "rc":
suffix = "rc"
elif prerelease_kind.startswith("alpha"):
suffix = "a"
elif prerelease_kind.startswith("beta"):
suffix = "b"
if (prerelease_number := parts["prerelease_number"]) is not None:
suffix += str(int(prerelease_number))

return f"{major}.{minor}.{patch}{suffix}"

0 comments on commit 7be3045

Please sign in to comment.