|
| 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