-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.py
49 lines (41 loc) · 1.43 KB
/
build.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
"""
PyDetex
https://github.com/ppizarror/PyDetex
BUILD.
"""
import os
import shutil
import struct
import sys
assert len(sys.argv) == 2, 'Argument is required, usage: build.py pyinstaller/pip/twine'
mode = sys.argv[1].strip()
sys_arch = struct.calcsize('P') * 8
if mode == 'pyinstaller':
# Check upx
upx = ''
if sys.platform == 'win32' and sys_arch == 64:
upx = '--upx-dir specs'
pyinstaller = f'python -m PyInstaller' if sys.platform == 'win32' else 'pyinstaller'
os.system(f'{pyinstaller} specs/PyDetex_Win_Single.spec --noconfirm {upx}')
os.system(f'{pyinstaller} specs/PyDetex_macOS.spec --noconfirm')
elif mode == 'pip':
if os.path.isdir('dist/pip'):
for k in os.listdir('dist'):
if '.egg' in k:
os.remove(f'dist/{k}')
if os.path.isdir('dist/pip'):
for k in os.listdir('dist/pip'):
if 'pydetex-' in k:
os.remove(f'dist/pip/{k}')
if os.path.isdir('build'):
for k in os.listdir('build'):
if 'bdist.' in k or k == 'lib':
shutil.rmtree(f'build/{k}')
os.system(f'python setup.py sdist --dist-dir dist/pip bdist_wheel --dist-dir dist/pip')
elif mode == 'twine':
if os.path.isdir('dist/pip'):
os.system(f'python -m twine upload dist/pip/*')
else:
raise FileNotFoundError('Not distribution been found, execute build.py pip')
else:
raise ValueError(f'Unknown mode {mode}')