-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
upgrade_all.py
38 lines (30 loc) · 1.03 KB
/
upgrade_all.py
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
from __future__ import annotations
import argparse
import configparser
import json
import subprocess
import sys
import urllib.request
from collections.abc import Sequence
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--packages-ini", default="packages.ini")
args = parser.parse_args(argv)
cfg = configparser.ConfigParser()
assert cfg.read(args.packages_ini)
pkgs_latest = dict(k.split("==", 1) for k in cfg.sections())
todo = []
for k, v in pkgs_latest.items():
resp = urllib.request.urlopen(f"https://pypi.org/pypi/{k}/json")
contents = json.load(resp)
if contents["info"]["version"] != v:
todo.append(k)
if todo:
print(f"upgrading {', '.join(todo)}...")
cmd = (sys.executable, "-m", "add_pkg", "--", "-r/dev/stdin")
subprocess.run(cmd, input="\n".join(todo).encode()).returncode
else:
print("up to date!")
return 0
if __name__ == "__main__":
raise SystemExit(main())