Skip to content

Commit 4209d03

Browse files
committed
freezer: Add WIP pyinstaller runner.
re #251 [ci skip]
1 parent dbe984c commit 4209d03

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ doc/_build/
6161
MANIFEST
6262
py2src_noedit/
6363
test/fuzz_fusil/fusil*/
64-
freezer/cx_freeze/packages
64+
6565
# ignore source code directory:
66+
freezer/cx_freeze/packages
6667
freezer/cx_freeze/cx_freeze
6768

69+
# Ignore virtualenv
70+
freezer/pyinstaller/wpull_env
71+
freezer/pyinstaller/wpull.spec
72+
6873
*.orig

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ recursive-include test runner.py README.md
2020
# Binary generators
2121
include freezer/README.md
2222
include freezer/cx_freeze/debian.patch freezer/cx_freeze/Makefile freezer/cx_freeze/windows_msi.sh
23+
include freezer/pyinstaller/hooks/*.py freezer/pyinstaller/runner.py
24+
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
3+
from PyInstaller.utils.hooks.hookutils import collect_data_files
4+
5+
6+
def get_virtual_env_extra_site_files():
7+
return [
8+
(
9+
os.path.join(
10+
os.path.dirname(__file__),
11+
'..', 'wpull_env', 'lib', 'python*', '*.txt'
12+
),
13+
'./'
14+
)
15+
]
16+
17+
18+
datas = collect_data_files('wpull') + get_virtual_env_extra_site_files()

freezer/pyinstaller/runner.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
import copy
3+
import subprocess
4+
import sys
5+
import distutils.util
6+
import platform
7+
import os.path
8+
import os
9+
10+
11+
def main():
12+
this_python = sys.executable
13+
env_dir = os.path.abspath('./wpull_env/')
14+
env_bin_dir = 'Scripts' if platform.system() == 'Windows' else 'bin'
15+
16+
def run_py(args):
17+
subprocess.check_call([this_python, '-m'] + list(args))
18+
19+
def run_env_py(args, get_output=False):
20+
proc_args = [os.path.join(env_dir, env_bin_dir, 'python'), '-m'] + list(args)
21+
22+
if get_output:
23+
return subprocess.check_output(proc_args)
24+
else:
25+
subprocess.check_call(proc_args)
26+
27+
print('Initialize virtual env.')
28+
run_py(['virtualenv', '--always-copy', env_dir])
29+
30+
print('Check for PyInstaller.')
31+
try:
32+
run_env_py(['PyInstaller.main', '--version'])
33+
except subprocess.CalledProcessError as error:
34+
print('Returned code', error.returncode)
35+
36+
print('Install PyInstaller.')
37+
run_env_py([
38+
'pip', 'install',
39+
'git+https://github.com/pyinstaller/pyinstaller@python3#egg=PyInstaller',
40+
])
41+
42+
print('Install packages.')
43+
run_env_py(['pip', 'install', '-r', '../../requirements.txt'])
44+
45+
print('Install optional packages.')
46+
run_env_py(['pip', 'install', 'cchardet'])
47+
48+
print('Install Wpull.')
49+
run_env_py(['pip', 'install', '../../'])
50+
51+
exe_name = 'wpull'
52+
53+
if platform.system() == 'Windows':
54+
exe_name += '.exe'
55+
56+
print('Build binary.')
57+
run_env_py(['PyInstaller.main',
58+
os.path.join(env_dir, env_bin_dir, 'wpull'),
59+
'--additional-hooks-dir', 'hooks',
60+
'--onefile',
61+
'--name', exe_name,
62+
])
63+
64+
print('Zip.')
65+
wpull_version = run_env_py(['wpull', '--version'], get_output=True)\
66+
.decode('ascii').strip()
67+
platform_string = distutils.util.get_platform()
68+
69+
# TODO: zip up the binary with the readme and license file.
70+
71+
72+
if __name__ == '__main__':
73+
main()

0 commit comments

Comments
 (0)