forked from dipu-bd/lightnovel-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_pyi.py
100 lines (80 loc) · 2.87 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
97
98
99
100
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
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))
site_packages = list(ROOT.glob('venv/**/site-packages'))[0]
unix_site_packages = '/'.join(str(site_packages).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 '
command += '--onefile ' # onefile
command += '--clean '
command += '--noconfirm '
command += '--name "lncrawl" '
command += '--icon "%s/res/lncrawl.ico" ' % unix_root
command += '--distpath "%s" ' % str(ROOT / 'dist')
command += '--specpath "%s" ' % str(ROOT / 'windows')
command += '--workpath "%s" ' % str(ROOT / 'windows' / 'build')
command += gather_data_files()
command += gather_hidden_imports()
command += '"%s/__main__.py" ' % unix_root
print(command)
print()
sys.argv = shlex.split(command)
# end def
def gather_data_files():
command = ''
# add data files of this project
for f in (ROOT / 'lncrawl').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/lncrawl/VERSION%slncrawl" ' % (unix_root, os.pathsep)
# add data files of other dependencies
command += '--add-data "%s/cairosvg/VERSION%s." ' % (
unix_site_packages, os.pathsep)
command += '--add-data "%s/cairocffi/VERSION%scairocffi" ' % (
unix_site_packages, os.pathsep)
#command += '--add-data "%s/tinycss2/VERSION%stinycss2" ' % (
# unix_site_packages, os.pathsep)
command += '--add-data "%s/text_unidecode/data.bin%stext_unidecode" ' % (
unix_site_packages, os.pathsep)
command += '--add-data "%s/cloudscraper%scloudscraper" ' % (
unix_site_packages, os.pathsep)
command += '--add-data "%s/wcwidth/version.json%swcwidth" ' % (
unix_site_packages, os.pathsep)
return command
# end def
def gather_hidden_imports():
command = ''
# add hidden imports of this project
for f in (ROOT / 'lncrawl' / 'sources').glob('*.py'):
if os.path.isfile(f) and re.match(r'^([^_.][^.]+).py$', f.name):
module_name = f.name[:-3]
command += '--hidden-import "lncrawl.sources.%s" ' % module_name
# end if
# end for
command += '--hidden-import "pkg_resources.py2_warn" '
return command
# end def
if __name__ == '__main__':
package()
# end if