-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.py
More file actions
155 lines (133 loc) · 4.18 KB
/
utils.py
File metadata and controls
155 lines (133 loc) · 4.18 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import datetime as dt
import json
import requests_cache
BASE_URL = "https://pypi.org/pypi"
DEPRECATED_PACKAGES = {
"BeautifulSoup",
"bs4",
"distribute",
"django-social-auth",
"nose",
"pep8",
"pycrypto",
"pypular",
"sklearn",
"subprocess32",
}
NON_MOBILE_PACKAGES = {
# Nvidia/CUDA projects. These can't be ported to mobile, because
# CUDA isn't available for Android or iOS.
"cuda-bindings",
"cupy-cuda11x",
"cupy-cuda12x",
"jax-cuda12-pjrt",
"jax-cuda12-plugin",
"nvidia-cublas-cu11",
"nvidia-cublas-cu12",
"nvidia-cuda-cupti-cu11",
"nvidia-cuda-cupti-cu12",
"nvidia-cuda-nvcc-cu12",
"nvidia-cuda-nvrtc-cu11",
"nvidia-cuda-nvrtc-cu12",
"nvidia-cuda-runtime-cu11",
"nvidia-cuda-runtime-cu12",
"nvidia-cudnn-cu11",
"nvidia-cudnn-cu12",
"nvidia-cufft-cu11",
"nvidia-cufft-cu12",
"nvidia-cufile-cu12",
"nvidia-curand-cu11",
"nvidia-curand-cu12",
"nvidia-cusolver-cu11",
"nvidia-cusolver-cu12",
"nvidia-cusparse-cu11",
"nvidia-cusparse-cu12",
"nvidia-cusparselt-cu12",
"nvidia-modelopt-core",
"nvidia-modelopt",
"nvidia-nccl-cu11",
"nvidia-nccl-cu12",
"nvidia-nccl-cu12",
"nvidia-nvshmem-cu12",
"nvidia-nvtx-cu11",
"nvidia-nvtx-cu12",
"sgl-kernel",
# Intel processors aren't used on mobile platforms.
"intel-cmplr-lib-ur",
"intel-openmp",
"mkl",
"tensorflow-intel",
# Subprocesses aren't supported on mobile platforms
"multiprocess",
# Windows-specific bindings
"pywin32",
"pywinpty",
"windows-curses",
}
PLATFORMS = ["android", "ios"]
# Keep responses for one hour
SESSION = requests_cache.CachedSession("requests-cache", expire_after=60 * 60)
def get_json_url(package_name):
return BASE_URL + "/" + package_name + "/json"
def annotate_wheels(packages, to_chart: int) -> list[dict]:
print("Getting wheel data...")
num_packages = len(packages)
total = 0
keep = []
for index, package in enumerate(packages):
print(f"{total + 1}/{to_chart} {index + 1}/{num_packages} {package['name']}")
if package["name"] in DEPRECATED_PACKAGES | NON_MOBILE_PACKAGES:
continue
available_platforms = set()
url = get_json_url(package["name"])
response = SESSION.get(url)
if response.status_code != 200:
print(" ! Skipping " + package["name"])
continue
data = response.json()
for download in data["urls"]:
if download["packagetype"] == "bdist_wheel":
# The wheel filename is:
# {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl
# https://packaging.python.org/en/latest/specifications/binary-distribution-format/#file-name-convention
platform_tag = download["filename"].removesuffix(".whl").split("-")[-1]
available_platforms.add(platform_tag.split("_")[0])
if available_platforms == {"any"}:
# Don't show packages with only pure Python wheels.
continue
else:
for platform in PLATFORMS:
package[platform] = (
"success"
if platform in available_platforms
else "pure-py"
if "any" in available_platforms
else "warning"
)
keep.append(package)
total += 1
if total == to_chart:
break
return keep
def get_top_packages():
print("Getting packages...")
with open("top-pypi-packages.json") as data_file:
packages = json.load(data_file)["rows"]
# We only need the names.
for package in packages:
name = package.pop("project")
package.clear()
package["name"] = name
return packages
def save_to_file(packages, file_name):
now = dt.datetime.now(tz=dt.timezone.utc)
with open(file_name, "w") as f:
f.write(
json.dumps(
{
"data": packages,
"last_update": now.strftime("%A, %d %B %Y, %X %Z"),
},
indent=1,
)
)