forked from pydrofoil/pydrofoil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_pypy_to_download.py
executable file
·39 lines (36 loc) · 1.26 KB
/
get_pypy_to_download.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
39
#!/usr/bin/env python3
"""
Use the platform.uname and the versions.json from downloads.python.org to find
the name of the latests pypy2.7 for this platform. Print it out on stdout
"""
import json
from urllib import request, error
import platform
import tarfile
import io
response = request.urlopen('https://downloads.python.org/pypy/versions.json')
if not (response.getcode(), 200):
raise RuntimeError("could not download versions.json from https://downloads/python.org/pypy/")
data = json.loads(response.read())
download = ''
# Find the one that has python_version 2.7, "stable", and platform matches
uname = platform.uname()
def lookup_arch(machine):
if machine == "x86_64":
return "x64"
else:
return machine
for d in data:
if d['stable'] is True and "2.7" in d["python_version"]:
for f in d["files"]:
if f["arch"] == lookup_arch(uname.machine) and f["platform"] == uname.system.lower():
download = f["download_url"]
break
else:
raise RuntimeError(
f"No known stable PyPy2.7 build for {uname.machine}-{uname.system}"
)
break
else:
raise RuntimeError(f"No known stable PyPy2.7 build???")
request.urlretrieve(download, filename="pypy.tar.bz2")