|
| 1 | +# /// script |
| 2 | +# requires-python = ">= 3.12" |
| 3 | +# dependencies = [ |
| 4 | +# "httpx>=0.28.1,<0.29", |
| 5 | +# "packaging>=25.0", |
| 6 | +# ] |
| 7 | +# /// |
| 8 | +import os |
| 9 | +import re |
| 10 | +from pathlib import Path |
| 11 | + |
| 12 | +import httpx |
| 13 | +from packaging.utils import parse_wheel_filename |
| 14 | +from packaging.version import Version |
| 15 | + |
| 16 | + |
| 17 | +def main(): |
| 18 | + response = httpx.get( |
| 19 | + "https://pypi.org/simple/uv-build/", |
| 20 | + headers={"Accept": "application/vnd.pypi.simple.v1+json"}, |
| 21 | + ) |
| 22 | + response.raise_for_status() |
| 23 | + data = response.json() |
| 24 | + current_release = None |
| 25 | + for file in data["files"]: |
| 26 | + if not file["filename"].endswith(".whl"): |
| 27 | + continue |
| 28 | + _name, version, _build, _tags = parse_wheel_filename(file["filename"]) |
| 29 | + if version.is_prerelease: |
| 30 | + continue |
| 31 | + if current_release is None or version > current_release: |
| 32 | + current_release = version |
| 33 | + |
| 34 | + [major, minor, _patch] = current_release.release |
| 35 | + if major != 0: |
| 36 | + raise NotImplementedError("The script needs to be updated for uv 1.x") |
| 37 | + upper_bound = Version(f"{major}.{minor + 1}.0") |
| 38 | + |
| 39 | + repository_root = Path(__file__).parent.parent |
| 40 | + existing = repository_root.joinpath( |
| 41 | + "source/shared/build-backend-tabs.rst" |
| 42 | + ).read_text() |
| 43 | + replacement = f'requires = ["uv_build >= {current_release}, <{upper_bound}"]' |
| 44 | + searcher = re.compile(re.escape('requires = ["uv_build') + ".*" + re.escape('"]')) |
| 45 | + if not searcher.search(existing): |
| 46 | + raise RuntimeError("Could not `uv-build` entry") |
| 47 | + updated = searcher.sub(replacement, existing) |
| 48 | + |
| 49 | + if existing != updated: |
| 50 | + print("Updating source/shared/build-backend-tabs.rst") |
| 51 | + Path("source/shared/build-backend-tabs.rst").write_text(updated) |
| 52 | + if github_output := os.environ.get("GITHUB_OUTPUT"): |
| 53 | + with open(github_output, "a") as f: |
| 54 | + f.write(f"version={current_release}\n") |
| 55 | + f.write("updated=true\n") |
| 56 | + else: |
| 57 | + print("Already up-to-date source/shared/build-backend-tabs.rst") |
| 58 | + if github_output := os.environ.get("GITHUB_OUTPUT"): |
| 59 | + with open(github_output, "a") as f: |
| 60 | + f.write("updated=false\n") |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + main() |
0 commit comments