Skip to content

Commit ef78f82

Browse files
committed
optimize scripts
1 parent b2b4673 commit ef78f82

File tree

5 files changed

+73
-21
lines changed

5 files changed

+73
-21
lines changed

src/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# SOP Checklist
22

3+
## Build
4+
5+
## Upload
6+
37
1. (pypy docker) `python3 copy_whls.py`
48
2. (pypy docker) `python3 build_many.py`
59
3. (pypy host) `cp -rvf whl /mnt/hdd/Temp/`

src/build.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ def build(
210210
)
211211
load = get_load()
212212
while load > load_limit:
213-
pbar.write(f'Load: {load} > {load_limit}, waiting...')
213+
pbar.write(f'Load: {load:.2f} > {load_limit}, waiting...')
214214
time.sleep(60)
215215
load = get_load()
216-
pbar.write(f'Load: {load} < {load_limit}, start!')
216+
pbar.write(f'Load: {load:.2f} < {load_limit}, start!')
217217
try:
218218
pbar.write(f'Now running {command}')
219219
p = subprocess.Popen(
@@ -255,6 +255,10 @@ def build(
255255
pbar.write('Built 100 packages. Uninstall all.')
256256
count = 0
257257
uninst_all(ver, py_path, plat, pbar)
258+
elif 'dependency conflicts' in result + error:
259+
pbar.write('Found dependency conflicts! Uninstall all.')
260+
count = 0
261+
uninst_all(ver, py_path, plat, pbar)
258262
except KeyboardInterrupt:
259263
pbar.write('Exiting...')
260264
pbar.write(f'{success=}')
@@ -269,7 +273,11 @@ def build(
269273
return success, failed
270274

271275

272-
NO_UNINST = ['pip', 'setuptools', 'wheel', 'certifi']
276+
NO_UNINST = [
277+
'pip', 'setuptools', 'wheel',
278+
'certifi', 'wrapt',
279+
'semantic_version'
280+
]
273281

274282

275283
def uninst_all(ver: str, py_path: str, plat: str = 'win', upper_pbar: tqdm = None):

src/host_cache.py

+31-10
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,67 @@
11
import os
2+
import logging
23
from flask import Flask, send_from_directory
34

45

6+
WORKDIR = os.path.expanduser('~')
57
if os.name == 'nt':
6-
WORKDIR = os.path.expanduser('~')
78
HTML_DIR = 'E:/Cache/pypy/html'
89
CACHE_DIR = 'AppData/Local/pip/cache/wheels'
910
else:
10-
WORKDIR = '/home/kuma'
1111
HTML_DIR = '/tmp/html'
1212
CACHE_DIR = '.cache/pip/wheels'
1313

14+
app = Flask(__name__)
15+
16+
logging.basicConfig(
17+
format='%(asctime)s %(levelname)-8s %(message)s',
18+
level=logging.INFO,
19+
datefmt='%Y-%m-%d %H:%M:%S')
20+
21+
logger = logging.getLogger('werkzeug')
22+
logger.setLevel(logging.WARNING)
23+
1424

1525
def get_local_whl_list():
1626
if not os.path.isdir(f'{WORKDIR}/{CACHE_DIR}'):
17-
print('No wheels yet!')
27+
logger.warning('No wheels yet!')
1828
return []
1929

2030
whl_list = []
2131
for root, dirs, files in os.walk(f'{WORKDIR}/{CACHE_DIR}'):
2232
for file in files:
2333
if file.endswith('.whl'):
2434
whl_list.append((file, root.replace(f'{WORKDIR}/', '')))
25-
return whl_list
35+
logger.warning(f'Found {len(whl_list)} wheels.')
36+
unique_whl_list = []
37+
unique_whl_name_list = []
38+
for whl in whl_list:
39+
if whl[0] not in unique_whl_name_list:
40+
unique_whl_name_list.append(whl[0])
41+
unique_whl_list.append(whl)
42+
logger.warning(f'Found {len(unique_whl_list)} unique wheels.')
43+
return unique_whl_list
2644

2745

2846
def gen_html():
29-
print('Generating HTML...')
47+
logger.warning('Generating HTML...')
3048
whl_list = get_local_whl_list()
31-
print(f'Found {len(whl_list)} wheels.')
3249
whl_list.sort(key=lambda x: x[0])
3350

3451
html_head = '<!DOCTYPE html><html><head><meta charset="utf-8"><title>Wheels</title></head><body>\n'
3552
html_tail = '</body></html>\n'
3653
html_body = ''
3754
for whl in whl_list:
38-
html_body += f'<a href="{whl[1]}/{whl[0]}">{whl[0]}</a><br>\n'
55+
path = whl[1].replace('\\', '/')
56+
name = whl[0]
57+
html_body += f'<a href="{path}/{name}">{name}</a><br>\n'
3958
html = html_head + html_body + html_tail
4059

4160
os.makedirs(HTML_DIR, exist_ok=True)
4261
with open(f'{HTML_DIR}/index.html', 'w', encoding='utf-8') as f:
4362
f.write(html)
4463

4564

46-
app = Flask(__name__)
4765
gen_html()
4866
req_count = 0
4967

@@ -55,15 +73,18 @@ def index():
5573
global req_count
5674
req_count += 1
5775
if req_count % 100 == 0:
58-
print(f'Requested {req_count} times, regenerating HTML...')
76+
logger.warning(f'Requested {req_count} times, regenerating HTML...')
5977
gen_html()
6078
return send_from_directory(HTML_DIR, 'index.html')
6179

6280

6381
@app.route('/<path:path>')
6482
def send_whl(path):
83+
if not 'whl' in path:
84+
logger.error(f'Dismissed: {path}')
85+
return '', 404
6586
filename = path.split('/')[-1]
66-
print(f'Requested: {filename}')
87+
logger.warning(f'Requested: {filename}')
6788
return send_from_directory(WORKDIR, path)
6889

6990

src/init-centos-7.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,20 @@ cd ..
8888
rm -rvf libpng-1.6.40 libpng-1.6.40.tar.xz
8989

9090
# others
91-
sudo dnf -y install postgresql-devel libxml2-devel libxslt-devel unixODBC-devel librdkafka-devel freetds-devel
91+
sudo dnf -y install postgresql-devel libxml2-devel libxslt-devel unixODBC-devel freetds-devel
92+
93+
#
94+
# error "confluent-kafka-python requires librdkafka v2.3.0 or later.
95+
cd /tmp
96+
wget https://gh.kmtea.eu/https://github.com/confluentinc/librdkafka/archive/refs/tags/v2.3.0.tar.gz
97+
tar xvzf v2.3.0.tar.gz
98+
cd librdkafka-2.3.0
99+
sudo ln -s /opt/python/cp312-cp312/bin/python3 /usr/bin/python3
100+
./configure
101+
make
102+
sudo make install
103+
cd ..
104+
rm -rvf librdkafka-2.3.0 v2.3.0.tar.gz
92105

93106
# hdf5
94107
# Exception: This version of h5py requires HDF5 >= 1.10.4 (got version (1, 8, 12) from environment variable or library)

src/tools.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_pypy_link(ver: str, plat='win64') -> str:
3131

3232

3333
def copy_wheels(dst: str):
34-
print(f'Copying wheels for pypy...')
34+
logging.info(f'Copying wheels for pypy...')
3535
pip_cache_dir = get_pip_cache_dir()
3636
if not os.path.exists(pip_cache_dir):
3737
return None
@@ -41,7 +41,7 @@ def copy_wheels(dst: str):
4141
os.makedirs(f'{dst}/{ver}', exist_ok=True)
4242
os.makedirs(f'{dst}/none', exist_ok=True)
4343

44-
# find whl file in pip cache
44+
logging.info('find whl file in pip cache')
4545
whl_files = []
4646
for root, dirs, files in os.walk(pip_cache_dir):
4747
for file in files:
@@ -51,38 +51,44 @@ def copy_wheels(dst: str):
5151
with open('../whl/wheels.html', 'r', encoding='utf-8') as f:
5252
whl_html = f.read()
5353

54-
# copy whl file to wheel dir
54+
logging.info('get new wheels')
5555
new_whl = []
5656
for root, file in whl_files:
5757
if file not in whl_html:
5858
new_whl.append((root, file))
5959
else:
6060
if file in saved_sha256sums:
61-
logging.warning(f'{file} already exists in saved_sha256sums')
61+
logging.warning(f'Skip: \t{file} already exists in saved_sha256sums')
6262
else:
6363
new_whl.append((root, file))
64-
logging.warning(f'{file} already exists in wheels.html')
65-
logging.warning(f'You MUST remove old file from releases!!!')
64+
logging.warning(f'NEW: \t{file} exists in wheels.html but not in saved_sha256sums')
65+
logging.warning(f'\tYou MUST remove old file from releases!!!')
6666

67+
logging.info('select files to copy')
6768
pbar = tqdm(new_whl)
6869
copied_files = []
6970
for root, file in pbar:
7071
if file in copied_files:
7172
continue
7273
else:
7374
pbar.set_description(f'Coping {file}')
75+
matched = False
7476
for ver in build_versions:
7577
if f'pp{ver.replace(".", "")}-pypy{ver.replace(".", "")}' in file:
7678
if not (os.path.isfile(f'{dst}/{ver}/{file}') or os.path.isfile(f'{LINUX_MANY_DIR}/done/{file}')):
7779
shutil.copy(f'{root}/{file}', f'{dst}/{ver}/{file}')
7880
copied_files.append(file)
81+
matched = True
7982
break
8083
if 'none' in file:
8184
if not (os.path.isfile(f'{dst}/none/{file}') or os.path.isfile(f'{LINUX_MANY_DIR}/done/{file}')):
8285
shutil.copy(f'{root}/{file}', f'{dst}/none/{file}')
8386
copied_files.append(file)
87+
matched = True
88+
if not matched:
89+
logging.error(f'Unmatched: {file}')
8490

85-
print(f'Copied {len(copied_files)} wheels')
91+
logging.info(f'Copied {len(copied_files)} wheels')
8692
return copied_files
8793

8894

0 commit comments

Comments
 (0)