-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo-win.py
68 lines (55 loc) · 2.07 KB
/
do-win.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import zipfile
from tempfile import TemporaryDirectory
import shutil
from pathlib import Path
import json
import io
from pybi import make_pybi
import requests
http = requests.Session()
built_path = Path("built").absolute()
def repack_nupkg(tag, nupkg_file, work_path):
zipfile.ZipFile(nupkg_file).extractall(work_path)
# actual python environment is nested inside a "tools/" directory
base_path = work_path / "tools"
scripts_path = base_path / "Scripts"
scripts_path.mkdir(exist_ok=True)
for p in base_path.iterdir():
if p.suffix in (".exe", ".dll"):
p.rename(base_path / "Scripts" / p.name)
for p in (base_path / "Lib" / "site-packages").iterdir():
if p.name != "README.txt":
print(f"Blowing away {p}")
if p.is_dir():
shutil.rmtree(p)
else:
p.unlink()
make_pybi(base_path, built_path, scripts_path="Scripts", platform_tag=tag)
def python_nupkg_urls():
response = http.get("https://api.nuget.org/v3/index.json")
response.raise_for_status()
for resource in response.json()["resources"]:
if resource["@type"] == "PackageBaseAddress/3.0.0":
base = resource["@id"]
break
else:
raise RuntimeError("nuget.org broken?")
for pkg in ["python", "pythonx86"]:
response = http.get(f"{base}{pkg}/index.json")
response.raise_for_status()
for version in response.json()["versions"]:
yield (pkg, version, f"{base}{pkg}/{version}/{pkg}.{version}.nupkg")
for pkg, version, url in python_nupkg_urls():
if version.startswith("3.5.") or version.startswith("3.6."):
continue
if pkg == "python":
tag = "win_amd64"
else:
assert pkg == "pythonx86"
tag = "win32"
pybi_name = f"cpython_unofficial-{version}-{tag}.pybi"
if not (built_path / pybi_name).exists():
print(f"Building {pybi_name}")
nupkg_data = http.get(url).content
with TemporaryDirectory() as work_path:
repack_nupkg(tag, io.BytesIO(nupkg_data), Path(work_path))