8
8
9
9
import argparse
10
10
import json
11
+ import re
11
12
import subprocess
12
13
from hashlib import sha256
13
14
from pathlib import Path
21
22
PYTHON_VERSIONS = PROJECT_ROOT / "docker" / "build_scripts" / "python_versions.json"
22
23
23
24
25
+ def get_sha256 (url : str ) -> str :
26
+ response = requests .get (url , stream = True )
27
+ response .raise_for_status ()
28
+ sha256sum = sha256 ()
29
+ for chunk in response .iter_content (chunk_size = 1024 * 4 ):
30
+ sha256sum .update (chunk )
31
+ return sha256sum .hexdigest ()
32
+
33
+
24
34
def update_pypy_version (releases , py_spec , pp_spec , tag , arch , version_dict , updates ):
25
35
pypy_arch = {"x86_64" : "x64" }.get (arch , arch )
26
36
current_version = None
@@ -42,14 +52,9 @@ def update_pypy_version(releases, py_spec, pp_spec, tag, arch, version_dict, upd
42
52
continue
43
53
message = f"updating { tag } { arch } to { r ['pypy_version' ]} "
44
54
print (message )
45
- response = requests .get (file ["download_url" ], stream = True )
46
- response .raise_for_status ()
47
- sha256sum = sha256 ()
48
- for chunk in response .iter_content (chunk_size = 1024 * 4 ):
49
- sha256sum .update (chunk )
50
55
version_dict ["version" ] = str (r ["pypy_version" ])
51
56
version_dict ["download_url" ] = file ["download_url" ]
52
- version_dict ["sha256" ] = sha256sum . hexdigest ( )
57
+ version_dict ["sha256" ] = get_sha256 ( file [ "download_url" ] )
53
58
updates .append (message )
54
59
break
55
60
@@ -88,13 +93,76 @@ def update_pypy_versions(versions, updates):
88
93
)
89
94
90
95
96
+ def update_graalpy_version (releases , graalpy_spec , tag , arch , version_dict , updates ):
97
+ graalpy_arch = {"x86_64" : "amd64" }.get (arch , arch )
98
+ current_version = None
99
+ if "version" in version_dict :
100
+ current_version = Version (version_dict ["version" ])
101
+ for r in releases :
102
+ version = Version (r ["tag_name" ].split ('-' )[1 ])
103
+ if current_version is not None and current_version >= version :
104
+ continue
105
+ if not graalpy_spec .contains (version ):
106
+ continue
107
+ asset_found = False
108
+ for asset in r ["assets" ]:
109
+ if asset ["name" ] == f"graalpy-{ version } -linux-{ graalpy_arch } .tar.gz" :
110
+ asset_found = True
111
+ break
112
+ if not asset_found :
113
+ continue
114
+ message = f"updating { tag } { arch } to { version } "
115
+ print (message )
116
+ version_dict ["version" ] = str (version )
117
+ version_dict ["download_url" ] = asset ["browser_download_url" ]
118
+ version_dict ["sha256" ] = get_sha256 (asset ["browser_download_url" ])
119
+ updates .append (message )
120
+ break
121
+
122
+
123
+ def get_next_page_link (response ):
124
+ link = response .headers .get ("link" )
125
+ if link :
126
+ for part in re .split (r"\s*,\s*" , link ):
127
+ split = re .split (r"\s*;\s*" , part )
128
+ url = split [0 ][1 :- 1 ]
129
+ for param in split [1 :]:
130
+ if re .match (r'rel="?next"?' , param ):
131
+ return url
132
+
133
+
134
+ def update_graalpy_versions (versions , updates ):
135
+ releases = []
136
+ url = "https://api.github.com/repos/oracle/graalpython/releases"
137
+ while url :
138
+ response = requests .get (url )
139
+ response .raise_for_status ()
140
+ releases += response .json ()
141
+ url = get_next_page_link (response )
142
+ for tag in versions :
143
+ if not tag .startswith ("graalpy" ):
144
+ continue
145
+ _ , abi_tag = tag .split ("-" )
146
+ graalpy_ver , _ , _ = abi_tag .split ("_" )
147
+ assert graalpy_ver .startswith ("graalpy" )
148
+ graalpy_ver = graalpy_ver [len ("graalpy" ):]
149
+ graalpy_major = int (graalpy_ver [:2 ])
150
+ graalpy_minor = int (graalpy_ver [2 :])
151
+ graalpy_spec = Specifier (f"=={ graalpy_major } .{ graalpy_minor } .*" )
152
+ for arch in versions [tag ]:
153
+ update_graalpy_version (
154
+ releases , graalpy_spec , tag , arch , versions [tag ][arch ], updates
155
+ )
156
+
157
+
91
158
def main ():
92
159
parser = argparse .ArgumentParser ()
93
160
parser .add_argument ("--dry-run" , dest = "dry_run" , action = "store_true" , help = "dry run" )
94
161
args = parser .parse_args ()
95
162
versions = json .loads (PYTHON_VERSIONS .read_text ())
96
163
updates = []
97
164
update_pypy_versions (versions , updates )
165
+ update_graalpy_versions (versions , updates )
98
166
if not args .dry_run :
99
167
PYTHON_VERSIONS .write_text (json .dumps (versions , indent = 2 ))
100
168
if updates :
0 commit comments