Skip to content

Commit 8e7e98f

Browse files
committed
update musl wheels
1 parent 004b1ef commit 8e7e98f

File tree

7 files changed

+269
-11
lines changed

7 files changed

+269
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This project provides pre-built wheels of popular packages.
66
### Add to pip
77

88
```bash
9-
pip config set global.extra-index-url https://ext.kmtea.eu/cdn
9+
pip config set global.extra-index-url https://ext.kmtea.eu/simple
1010
```
1111

1212
### Temporary use

src/col_whl.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def get_release_assets(repo: str, tag: str, author: str = AUTHOR) -> list:
2121
return result['assets']
2222

2323

24-
def save_release_data(repo: str, tag: str, data: dict):
24+
def save_release_data(repo: str, tag: str, data: list):
2525
with open(f'{WORKDIR}/whl/data/{repo}_{tag}.json', 'w', encoding='utf-8') as json_file:
2626
json.dump(data, json_file, indent=2)
2727

@@ -30,11 +30,11 @@ def get_all_repo_data():
3030
os.makedirs(f'{WORKDIR}/whl/data', exist_ok=True)
3131

3232
for repo in PROJECTS:
33-
print(f'Fetching GitHub releases for {AUTHOR}/{repo}...')
33+
print(f'\nFetching GitHub releases for {AUTHOR}/{repo}...')
3434
tags = get_repo_release_tags(repo)
3535
pbar = tqdm(tags)
36-
for tag in tags:
37-
pbar.set_description(f'Fetching {tag}...')
36+
for tag in pbar:
37+
pbar.set_description(f'Fetching {tag:>8}...')
3838
assets = get_release_assets(repo, tag)
3939
save_release_data(repo, tag, assets)
4040

src/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
PROJECTS = [
55
'pypy-wheels',
66
'riscv-wheels',
7+
'musl-wheels',
78
'ext-whl',
89
'NextBot',
910
'pytorch-riscv64',
@@ -13,3 +14,5 @@
1314
WORKDIR = '..'
1415
else:
1516
WORKDIR = '.'
17+
18+
LOCAL_WHL_DIR = r'E:\Cache\whl'

src/gen_index.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ def gen_cdn_index():
105105
if os.name == 'nt':
106106
hash_dict = get_saved_hash()
107107
wheels = get_assets(hash_dict)
108-
ps = gen_index(wheels)
109108
if input('Check official index? ([Y]/n) ').lower() in ['', 'y']:
110109
from tqdm import tqdm
111-
for p in tqdm(ps):
110+
for p in tqdm(gen_index(wheels)):
112111
check_official(p)
113112
else:
114113
wheels = get_assets_from_html()

src/gen_whl.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from conf import *
2-
from tools import get_saved_hash, get_assets, check_dup
1+
from tools import *
32

43

5-
def gen_index(saved_hash: dict):
4+
def gen_html_content(saved_hash: dict):
65
assets = get_assets(saved_hash)
76
check_dup(assets)
87
html = ''
@@ -23,7 +22,7 @@ def gen_index(saved_hash: dict):
2322

2423

2524
def gen_html(saved_hash: dict):
26-
index = gen_index(saved_hash)
25+
index = gen_html_content(saved_hash)
2726
with open(f'{WORKDIR}/whl/wheels.html', 'w', encoding='utf-8') as html_file:
2827
html_file.write(index)
2928

@@ -38,6 +37,9 @@ def gen_html_cdn():
3837
if __name__ == '__main__':
3938
if os.name == 'nt':
4039
hash_dict = get_saved_hash()
40+
local_whl = get_local_whl()
41+
hash_dict = extend_hash_dict(hash_dict, local_whl)
42+
save_hash(hash_dict)
4143
gen_html(hash_dict)
4244
else:
4345
gen_html_cdn()

src/tools.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import hashlib
23
import logging
34
from conf import *
45
from tqdm import tqdm
@@ -12,6 +13,12 @@ def get_saved_hash():
1213
return {}
1314

1415

16+
def save_hash(saved_hash: dict):
17+
saved_hash = dict(sorted(saved_hash.items(), key=lambda x: x[0].lower()))
18+
with open(f'{WORKDIR}/whl/data/sha256sums.json', 'w', encoding='utf-8') as json_file:
19+
json.dump(saved_hash, json_file, indent=2)
20+
21+
1522
def get_whl_sha256(name: str, saved_hash: dict):
1623
if name in saved_hash:
1724
return saved_hash[name]['sha256']
@@ -70,3 +77,36 @@ def get_assets_from_html() -> list:
7077
pkgs.append({'name': pkg_filename, 'url': pkg_url})
7178

7279
return pkgs
80+
81+
82+
def calculate_hash(file: str, algorithm: str = 'sha256') -> str:
83+
with open(file, 'rb') as f:
84+
hash_obj = hashlib.new(algorithm)
85+
hash_obj.update(f.read())
86+
return hash_obj.hexdigest()
87+
88+
89+
def get_local_whl() -> list[tuple[str, str]]:
90+
"""
91+
Get all .whl files in LOCAL_WHL_DIR
92+
:return: list of tuples (filename, path)
93+
"""
94+
whl_files = []
95+
for root, dirs, files in os.walk(LOCAL_WHL_DIR):
96+
for file in files:
97+
if file.endswith('.whl'):
98+
whl_files.append((file, os.path.join(root, file)))
99+
return whl_files
100+
101+
102+
def extend_hash_dict(saved_hash: dict, whl_files: list[tuple[str, str]]) -> dict:
103+
saved_wheels = saved_hash.keys()
104+
assert not any(name in saved_wheels for name, _ in whl_files)
105+
106+
print('Calculating hash for local wheels...')
107+
for name, path in tqdm(whl_files):
108+
saved_hash[name] = {
109+
'sha256': calculate_hash(path),
110+
'verify': False
111+
}
112+
return saved_hash

0 commit comments

Comments
 (0)