You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.6 KiB
93 lines
2.6 KiB
# Windows py2exe build script |
|
# running: python3 setup.py py2exe |
|
|
|
import os |
|
import sys |
|
import traceback |
|
# noinspection PyUnresolvedReferences |
|
import py2exe |
|
import importlib |
|
|
|
from distutils.core import setup |
|
from glob import glob |
|
|
|
sys.argv.append("py2exe") |
|
|
|
PYTHON_PATH = r"C:\Python311" |
|
|
|
|
|
SETUP_DICT = { |
|
"console": [{ |
|
"script": "speedtest.py", |
|
"icon_resources": [(1, "resources/speedometer.ico")], |
|
"dest_base": "Speedtest" |
|
|
|
}], |
|
|
|
"zipfile": "lib/library.zip", |
|
|
|
"data_files": [ |
|
("", glob(os.path.join(WINDOWS_PATH, r"SYSTEM32\msvcp100.dll"))), |
|
|
|
("", glob(os.path.join(WINDOWS_PATH, r"SYSTEM32\msvcr100.dll"))), |
|
|
|
], |
|
|
|
"options": { |
|
"py2exe": { |
|
"bundle_files": 3, |
|
"excludes": ["tcl", "tk", "tkinter", "idna", "lib2to3", "xmlrpc", "multiprocessing", "urllib3", "chardet", |
|
"asyncio", "pydoc_data", "requests", "unittest", "pydoc", "lzma", "bz2"], |
|
"dll_excludes": ["tcl86.dll", "tk86.dll"], |
|
"compressed": True, |
|
"optimize": 2 |
|
|
|
}, |
|
}, |
|
# fix for conflicting module dirs |
|
"py_modules": [], |
|
|
|
} |
|
|
|
# Check if all files can be found |
|
for num, file in enumerate(SETUP_DICT["data_files"]): |
|
type_, file = file |
|
if len(file) > 0: |
|
file = file[0] |
|
if os.path.exists(file): |
|
print("Found file:", file) |
|
else: |
|
print("File not found:", file) |
|
sys.exit(-1) |
|
else: |
|
if type_: |
|
print("Data file of type", type_, "not found") |
|
else: |
|
print("Data file with index", num, "and name", file, "not found") |
|
sys.exit(-1) |
|
|
|
try: |
|
setup(**SETUP_DICT) |
|
except Exception: |
|
traceback.print_exc() |
|
os.system("pause") |
|
else: |
|
# DDLs / exe files that are safe to be compressed with UPX |
|
OPTIMIZE = [glob(r"dist\python311.dll"), |
|
glob("dist\adb.exe"), |
|
glob(r"dist\lib\Qt*"), |
|
glob(r"dist\lib\*.pyd"), |
|
glob(r"dist\lib\libcrypto-1_1.dll"), |
|
glob(r"dist\lib\libssl-1_1.dll")] |
|
|
|
if os.path.exists("dist") and os.path.exists("upx.exe"): |
|
for files in OPTIMIZE: |
|
for file in files: |
|
if os.path.exists(file): |
|
# todo use subprocessing to run UPX on ALL CPU cores |
|
os.system("upx --best %s" % file) |
|
else: |
|
print("Warning: not going to optimize dist size because upx.exe doesn't exist\n") |
|
print("Please put upx.exe next to setup.py in order to have the build reduced in size by ~50%") |
|
|
|
os.system("pause")
|
|
|