| 1 |
|
| 2 |
|
| 3 |
""" |
| 4 |
Verify the versions.json file that describes the valid downloads. |
| 5 |
- all the files should be valid |
| 6 |
- the other fields should have valid values |
| 7 |
- the pypy_version should be in the repo tags |
| 8 |
|
| 9 |
By default will download https://buildbot.pypy.org/pypy/versions.json parse it, and |
| 10 |
check against the files in https://downloads.python.org/pypy/ |
| 11 |
Can be run as check_versions.py <filename>, in which case it will check the files in |
| 12 |
https://buildbot.pypy.org/mirror/ |
| 13 |
""" |
| 14 |
|
| 15 |
import json |
| 16 |
from urllib import request, error |
| 17 |
import sys |
| 18 |
import time |
| 19 |
|
| 20 |
|
| 21 |
def assert_equal(a, b): |
| 22 |
if a != b: |
| 23 |
raise ValueError(f"'{a}' != '{b}'") |
| 24 |
|
| 25 |
|
| 26 |
def assert_different(a, b): |
| 27 |
if a == b: |
| 28 |
raise ValueError(f"'{a}' == '{b}'") |
| 29 |
|
| 30 |
|
| 31 |
def assert_in(a, b): |
| 32 |
if a not in b: |
| 33 |
raise ValueError(f"'{a}' not in '{b}'") |
| 34 |
|
| 35 |
|
| 36 |
pypy_versions = { |
| 37 |
'7.3.22': {'python_version': ['3.11.15', '2.7.18'], |
| 38 |
'date': '2026-04-28', |
| 39 |
}, |
| 40 |
'7.3.21': {'python_version': ['3.11.15', '2.7.18'], |
| 41 |
'date': '2026-03-13', |
| 42 |
}, |
| 43 |
'7.3.20': {'python_version': ['3.11.13', '2.7.18'], |
| 44 |
'date': '2025-07-04', |
| 45 |
}, |
| 46 |
'7.3.19': {'python_version': ['3.11.11', '3.10.16', '2.7.18'], |
| 47 |
'date': '2025-02-26', |
| 48 |
}, |
| 49 |
'7.3.18': {'python_version': ['3.11.11', '3.10.16', '2.7.18'], |
| 50 |
'date': '2025-02-06', |
| 51 |
}, |
| 52 |
'7.3.17': {'python_version': ['3.10.14', '2.7.18'], |
| 53 |
'date': '2024-08-28', |
| 54 |
}, |
| 55 |
'7.3.16': {'python_version': ['3.10.14', '3.9.19', '2.7.18'], |
| 56 |
'date': '2024-04-24', |
| 57 |
}, |
| 58 |
'7.3.15': {'python_version': ['3.10.13', '3.9.18', '2.7.18'], |
| 59 |
'date': '2024-01-15', |
| 60 |
}, |
| 61 |
'7.3.14': {'python_version': ['3.10.13', '3.9.18', '2.7.18'], |
| 62 |
'date': '2023-12-25', |
| 63 |
}, |
| 64 |
'7.3.13': {'python_version': ['3.10.13', '3.9.18', '2.7.18'], |
| 65 |
'date': '2023-09-29', |
| 66 |
}, |
| 67 |
'7.3.12': {'python_version': ['3.10.12', '3.9.17', '2.7.18'], |
| 68 |
'date': '2023-06-16', |
| 69 |
}, |
| 70 |
'7.3.12rc2': {'python_version': ['3.10.11', '3.9.16', '2.7.18'], |
| 71 |
'date': '2023-05-28', |
| 72 |
}, |
| 73 |
'7.3.12rc1': {'python_version': ['3.10.9', '3.9.16', '2.7.18'], |
| 74 |
'date': '2023-05-13', |
| 75 |
}, |
| 76 |
'7.3.11': {'python_version': ['3.9.16', '3.8.16', '2.7.18'], |
| 77 |
'date': '2022-12-29', |
| 78 |
}, |
| 79 |
'7.3.10': {'python_version': ['3.9.15', '3.8.15', '2.7.18'], |
| 80 |
'date': '2022-12-06', |
| 81 |
}, |
| 82 |
'7.3.10rc3': {'python_version': ['3.9.15', '3.8.15', '2.7.18'], |
| 83 |
'date': '2022-11-24', |
| 84 |
}, |
| 85 |
'7.3.9': {'python_version': ['3.9.12', '3.8.13', '3.7.13', '2.7.18'], |
| 86 |
'date': '2022-03-30', |
| 87 |
}, |
| 88 |
'7.3.8': {'python_version': ['3.9.10', '3.8.12', '3.7.12', '2.7.18'], |
| 89 |
'date': '2022-02-19', |
| 90 |
}, |
| 91 |
'7.3.8rc2': {'python_version': ['3.9.10', '3.8.12', '3.7.12', '2.7.18'], |
| 92 |
'date': '2022-02-11', |
| 93 |
}, |
| 94 |
'7.3.8rc1': {'python_version': ['3.9.10', '3.8.12', '3.7.12', '2.7.18'], |
| 95 |
'date': '2022-01-26', |
| 96 |
}, |
| 97 |
'7.3.7': {'python_version': ['3.8.12', '3.7.12'], |
| 98 |
'date': '2021-10-25', |
| 99 |
}, |
| 100 |
'7.3.6': {'python_version': ['3.8.12', '3.7.12', '2.7.18'], |
| 101 |
'date': '2021-10-17', |
| 102 |
}, |
| 103 |
'7.3.6rc3': {'python_version': ['3.8.12', '3.7.12', '2.7.18'], |
| 104 |
'date': '2021-10-12', |
| 105 |
}, |
| 106 |
'7.3.6rc2': {'python_version': ['3.8.12', '3.7.12', '2.7.18'], |
| 107 |
'date': '2021-10-06', |
| 108 |
}, |
| 109 |
'7.3.6rc1': {'python_version': ['3.8.12', '3.7.12', '2.7.18'], |
| 110 |
'date': '2021-09-13', |
| 111 |
}, |
| 112 |
'7.3.5': {'python_version': ['3.7.10', '2.7.18'], |
| 113 |
'date': '2021-05-23', |
| 114 |
}, |
| 115 |
'7.3.5rc3': {'python_version': ['3.7.10', '2.7.18'], |
| 116 |
'date': '2021-05-19', |
| 117 |
}, |
| 118 |
'7.3.5rc2': {'python_version': ['3.7.10', '2.7.18'], |
| 119 |
'date': '2021-05-05', |
| 120 |
}, |
| 121 |
'7.3.5rc1': {'python_version': ['3.7.10', '2.7.18'], |
| 122 |
'date': '2021-05-02', |
| 123 |
}, |
| 124 |
'7.3.4': {'python_version': ['3.7.10', '2.7.18'], |
| 125 |
'date': '2021-04-08', |
| 126 |
}, |
| 127 |
'7.3.4rc2': {'python_version': ['3.7.10', '2.7.18'], |
| 128 |
'date': '2021-04-04', |
| 129 |
}, |
| 130 |
'7.3.4rc1': {'python_version': ['3.7.10', '2.7.18'], |
| 131 |
'date': '2021-03-19', |
| 132 |
}, |
| 133 |
'7.3.3': {'python_version': ['3.7.9', '3.6.12', '2.7.18'], |
| 134 |
'date': '2020-11-21', |
| 135 |
}, |
| 136 |
'7.3.3rc1': {'python_version': ['3.6.12'], |
| 137 |
'date': '2020-11-11', |
| 138 |
}, |
| 139 |
'7.3.2': {'python_version': ['3.7.9', '3.6.9', '2.7.13'], |
| 140 |
'date': '2020-09-25', |
| 141 |
}, |
| 142 |
'nightly': {'python_version': ['2.7', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11']}, |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
def create_latest_versions(v): |
| 147 |
"""Create a dictionary with key of cpython_version and value of the latest |
| 148 |
pypy version for that cpython""" |
| 149 |
ret = {} |
| 150 |
for pypy_ver, vv in v.items(): |
| 151 |
if 'rc' in pypy_ver: |
| 152 |
|
| 153 |
continue |
| 154 |
for pv in vv['python_version']: |
| 155 |
|
| 156 |
|
| 157 |
if pv not in ret or ( |
| 158 |
vv['date'] > v[ret[pv]]['date']): |
| 159 |
ret[pv] = pypy_ver |
| 160 |
return ret |
| 161 |
|
| 162 |
|
| 163 |
latest_pypys = create_latest_versions(pypy_versions) |
| 164 |
|
| 165 |
|
| 166 |
arches = ['aarch64', 'i686', 'x64', 'x86', 'darwin', 'arm64'] |
| 167 |
platforms = ['linux', 'win32', 'win64', 'darwin'] |
| 168 |
arch_map={('aarch64', 'linux'): 'aarch64', |
| 169 |
('i686', 'linux'): 'linux32', |
| 170 |
('x64', 'linux'): 'linux64', |
| 171 |
('s390x', 'linux'): 's390x', |
| 172 |
('x86', 'win32'): 'win32', |
| 173 |
('x64', 'win64'): 'win64', |
| 174 |
('x64', 'darwin'): ['macos_x86_64', 'osx64'], |
| 175 |
('arm64', 'darwin'): ['macos_arm64'], |
| 176 |
} |
| 177 |
|
| 178 |
def check_tags(data): |
| 179 |
|
| 180 |
|
| 181 |
URL_BASE = "https://github.com/pypy/pypy/releases/tag" |
| 182 |
pypy_newest_version = data[0]['pypy_version'] |
| 183 |
for d in data: |
| 184 |
if d['pypy_version'] != pypy_newest_version: |
| 185 |
continue |
| 186 |
py_major, py_minor, py_patch = d['python_version'].split('.') |
| 187 |
tag = f"release-pypy{py_major}.{py_minor}-v{pypy_newest_version}" |
| 188 |
tag_url = f"{URL_BASE}/{tag}" |
| 189 |
try: |
| 190 |
r = request.urlopen(tag_url) |
| 191 |
except error.HTTPError as e: |
| 192 |
raise ValueError(f"could not find {tag}' on github. Does the tag exist (forgotten git push --tags)?") from None |
| 193 |
assert_equal(r.getcode(), 200) |
| 194 |
|
| 195 |
def check_versions(data, url, verbose=0, check_times=True, nightly_only=False): |
| 196 |
for d in data: |
| 197 |
if verbose > 0: |
| 198 |
print(f"checking {d['python_version']} {d['pypy_version']}") |
| 199 |
assert_in(d['pypy_version'], pypy_versions) |
| 200 |
v = pypy_versions[d['pypy_version']] |
| 201 |
assert_in(d['python_version'], v['python_version']) |
| 202 |
if ('rc' in d['pypy_version'] or 'nightly' in d['pypy_version']): |
| 203 |
assert d['stable'] is False |
| 204 |
else: |
| 205 |
assert d['stable'] is True |
| 206 |
if d['pypy_version'] == 'nightly': |
| 207 |
assert d['latest_pypy'] is False |
| 208 |
elif d['latest_pypy'] is True: |
| 209 |
assert_equal(latest_pypys[d['python_version']], d['pypy_version']) |
| 210 |
else: |
| 211 |
try: |
| 212 |
|
| 213 |
assert_different(latest_pypys[d['python_version']], d['pypy_version']) |
| 214 |
except KeyError: |
| 215 |
assert 'rc' in d['pypy_version'] |
| 216 |
if 'date' in d: |
| 217 |
assert_equal(d['date'], v['date']) |
| 218 |
for f in d['files']: |
| 219 |
download_url = f['download_url'] |
| 220 |
if verbose > 0: |
| 221 |
print(f' checking {download_url:<80}', end='') |
| 222 |
if 'rc' not in d['pypy_version']: |
| 223 |
assert_in(f['filename'], download_url) |
| 224 |
assert_in(d['pypy_version'], download_url) |
| 225 |
if f['arch'] not in ('s390x',): |
| 226 |
|
| 227 |
assert_in(f['arch'], arches) |
| 228 |
assert_in(f['platform'], platforms) |
| 229 |
arch_plat = arch_map[(f['arch'], f['platform'])] |
| 230 |
py_ver = '.'.join(d['python_version'].split('.')[:2]) |
| 231 |
if d['pypy_version'] == 'nightly': |
| 232 |
if f['platform'] == "darwin": |
| 233 |
if arch_plat[0] not in download_url and arch_plat[1] not in download_url: |
| 234 |
raise ValueError(f"{arch_plat} not in {download_url}") |
| 235 |
elif arch_plat == 'linux32': |
| 236 |
|
| 237 |
arch_plat = 'linux' |
| 238 |
assert_in(arch_plat, download_url) |
| 239 |
else: |
| 240 |
assert_in(arch_plat, download_url) |
| 241 |
py_ver_tuple = [int(s) for s in py_ver.split('.')] |
| 242 |
if py_ver == "2.7": |
| 243 |
py_ver = "main" |
| 244 |
elif f['platform'] == "darwin": |
| 245 |
if arch_plat[0] not in download_url and arch_plat[1] not in download_url: |
| 246 |
raise ValueError(f"{arch_plat} not in {download_url}") |
| 247 |
else: |
| 248 |
assert_in(arch_plat, download_url) |
| 249 |
assert_in(py_ver, download_url) |
| 250 |
if d['pypy_version'] != 'nightly' and nightly_only: |
| 251 |
if verbose > 0: |
| 252 |
print(f' ok') |
| 253 |
continue |
| 254 |
if url and not d['pypy_version'] == "nightly": |
| 255 |
download_url = '/'.join((url, download_url.rsplit('/', 1)[1])) |
| 256 |
try: |
| 257 |
r = request.urlopen(download_url) |
| 258 |
except error.HTTPError as e: |
| 259 |
raise ValueError(f"could not open '{download_url}', got {e}") from None |
| 260 |
assert_equal(r.getcode(), 200) |
| 261 |
if d['pypy_version'] == 'nightly' and (py_ver_tuple > [3, 10] or py_ver == "main"): |
| 262 |
print('time-check', end='') |
| 263 |
|
| 264 |
target = time.strftime("%Y-%m-%d") |
| 265 |
|
| 266 |
|
| 267 |
modified_time_str = ' '.join(r.getheader("Last-Modified").split(' ')[1:4]) |
| 268 |
expected_time = time.mktime(time.strptime(target, "%Y-%m-%d")) |
| 269 |
modified_time = time.mktime(time.strptime(modified_time_str, "%d %b %Y")) |
| 270 |
delta_days = abs(expected_time - modified_time) / (60 * 60 * 24) |
| 271 |
if delta_days > 14 and 's390x' not in f['arch']: |
| 272 |
raise ValueError(f"expected {modified_time_str} to be within 2 weeks of {target}") |
| 273 |
else: |
| 274 |
print(f" {delta_days} days", end='') |
| 275 |
if verbose > 0: |
| 276 |
print(f' ok') |
| 277 |
if verbose > 0: |
| 278 |
print(f"{d['python_version']} {d['pypy_version']} ok") |
| 279 |
|
| 280 |
if __name__ == '__main__': |
| 281 |
if len(sys.argv) > 1: |
| 282 |
print(f'checking local file "{sys.argv[1]}"') |
| 283 |
with open(sys.argv[1]) as fid: |
| 284 |
data = json.loads(fid.read()) |
| 285 |
nightly_only = '--nightly-only' in sys.argv |
| 286 |
check_versions(data, 'https://buildbot.pypy.org/mirror/', verbose=1, |
| 287 |
nightly_only=nightly_only) |
| 288 |
else: |
| 289 |
print('downloading versions.json') |
| 290 |
response = request.urlopen('https://buildbot.pypy.org/pypy/versions.json') |
| 291 |
assert_equal(response.getcode(), 200) |
| 292 |
data = json.loads(response.read()) |
| 293 |
check_versions(data, None, verbose=1) |
| 294 |
check_tags(data) |
| 295 |
print('ok') |