forked from pypa/packaging.python.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_uv_build_version.py
More file actions
56 lines (49 loc) · 1.91 KB
/
Copy pathupdate_uv_build_version.py
File metadata and controls
56 lines (49 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "httpx>=0.28.1,<0.29",
# "packaging>=25.0",
# ]
# ///
import re
from pathlib import Path
import httpx
from packaging.utils import parse_wheel_filename
from packaging.version import Version
def main():
response = httpx.get(
"https://pypi.org/simple/uv-build/",
headers={"Accept": "application/vnd.pypi.simple.v1+json"},
)
response.raise_for_status()
data = response.json()
current_release = None
for file in data["files"]:
if not file["filename"].endswith(".whl"):
continue
_name, version, _build, _tags = parse_wheel_filename(file["filename"])
if version.is_prerelease:
continue
if current_release is None or version > current_release:
current_release = version
[major, minor, _patch] = current_release.release
if major != 0:
raise NotImplementedError("The script needs to be updated for uv 1.x")
upper_bound = Version(f"{major}.{minor + 1}.{0}")
repository_root = Path(__file__).parent.parent
existing = repository_root.joinpath("source/shared/build-backend-tabs.rst").read_text()
replacement = f'requires = ["uv_build >= {current_release}, <{upper_bound}"]'
searcher = re.compile(re.escape('requires = ["uv_build') + ".*" + re.escape('"]'))
if not searcher.search(existing):
raise RuntimeError("Could not `uv-build` entry")
updated = searcher.sub(replacement, existing)
if existing != updated:
print("Updating source/shared/build-backend-tabs.rst")
Path("source/shared/build-backend-tabs.rst").write_text(updated)
print(f"::set-output name=version::{current_release}")
print(f"::set-output name=updated::true")
else:
print("Already up-to-date source/shared/build-backend-tabs.rst")
print(f"::set-output name=updated::false")
if __name__ == '__main__':
main()