forked from dipu-bd/lightnovel-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_pyi.py
96 lines (76 loc) · 2.59 KB
/
setup_pyi.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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import platform
import re
import shlex
import shutil
import sys
from pathlib import Path
from PyInstaller import __main__ as pyi
from setuptools.config import read_configuration
ROOT = Path(__file__).parent
unix_root = '/'.join(str(ROOT).split(os.sep))
def package():
output = str(ROOT / 'windows')
shutil.rmtree(output, ignore_errors=True)
os.makedirs(output, exist_ok=True)
setup_command()
pyi.run()
shutil.rmtree(output, ignore_errors=True)
# end def
def setup_command():
command = 'pyinstaller -y '
command += '--clean '
command += '-F ' # onefile
command += '-n "lncrawl" '
command += '-i "%s/res/lncrawl.ico" ' % unix_root
command += gather_data_files()
command += gather_hidden_imports()
command += '"%s/__main__.py" ' % unix_root
print(command)
print()
extra = ['--distpath', str(ROOT / 'dist')]
extra += ['--specpath', str(ROOT / 'windows')]
extra += ['--workpath', str(ROOT / 'windows' / 'build')]
sys.argv = shlex.split(command) + extra
# end def
def gather_data_files():
command = ''
# add data files of this project
for f in (ROOT / 'src').glob('**/*.*'):
src = str(f)
src = '/'.join(src.split(os.sep))
dst = str(f.parent.relative_to(ROOT))
dst = '/'.join(dst.split(os.sep))
command += '--add-data "%s%s%s" ' % (src, os.pathsep, dst)
# end for
command += '--add-data "%s/src/VERSION%ssrc" ' % (unix_root, os.pathsep)
# add data files of other dependencies
site_packages = list(ROOT.glob('venv/**/site-packages'))[0]
site_packages = '/'.join(str(site_packages).split(os.sep))
command += '--add-data "%s/cairosvg/VERSION%s." ' % (
site_packages, os.pathsep)
command += '--add-data "%s/cairocffi/VERSION%scairocffi" ' % (
site_packages, os.pathsep)
command += '--add-data "%s/tinycss2/VERSION%stinycss2" ' % (
site_packages, os.pathsep)
command += '--add-data "%s/text_unidecode/data.bin%stext_unidecode" ' % (
site_packages, os.pathsep)
return command
# end def
def gather_hidden_imports():
command = ''
# add hidden imports of this project
for f in (ROOT / 'src' / 'sources').glob('*.py'):
if os.path.isfile(f) and re.match(r'^([^_.][^.]+).py[c]?$', f.name):
module_name = f.name[:-3]
command += '--hidden-import "src.sources.%s" ' % module_name
# end if
command += '--hidden-import pkg_resources.py2_warn '
# end for
return command
# end def
if __name__ == '__main__':
package()
# end if