aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bump_reqs.py50
1 files changed, 0 insertions, 50 deletions
diff --git a/scripts/bump_reqs.py b/scripts/bump_reqs.py
deleted file mode 100644
index 5d253e7..0000000
--- a/scripts/bump_reqs.py
+++ /dev/null
@@ -1,50 +0,0 @@
1#!/usr/bin/env python3
2"""Bump all pinned versions in requirements*.txt to latest from PyPI."""
3
4import json
5import re
6import urllib.request
7from pathlib import Path
8
9REQS = sorted(Path().glob("requirements*.txt"))
10PYPI = "https://pypi.org/pypi/{}/json"
11
12
13def latest_version(package: str) -> str | None:
14 url = PYPI.format(package)
15 try:
16 with urllib.request.urlopen(url, timeout=10) as resp:
17 data = json.load(resp)
18 return data["info"]["version"]
19 except Exception:
20 return None
21
22
23def bump_file(path: Path):
24 lines = path.read_text().splitlines()
25 changed = []
26 for line in lines:
27 m = re.match(r"^([\w-]+(?:\[[\w-]+])?)==[\w.]+$", line)
28 if m:
29 pkg = m.group(1)
30 latest = latest_version(pkg)
31 if latest:
32 changed.append(f"{pkg}=={latest}")
33 if f"{pkg}=={latest}" != line:
34 print(f" {pkg}: {line.split('==')[1]} -> {latest}")
35 else:
36 changed.append(line)
37 print(f" {pkg}: failed to fetch, keeping current")
38 else:
39 changed.append(line)
40 path.write_text("\n".join(changed) + "\n")
41
42
43def main():
44 for req in REQS:
45 print(f"\n{req}:")
46 bump_file(req)
47
48
49if __name__ == "__main__":
50 main()