Skip to content

Commit

Permalink
add: pyinstaller spec executable
Browse files Browse the repository at this point in the history
  • Loading branch information
singjc committed Feb 9, 2024
1 parent 3d72800 commit e09d9bd
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 0 deletions.
163 changes: 163 additions & 0 deletions dist-scripts/pyinstaller/massdash.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# -*- mode: python ; coding: utf-8 -*-

import pkgutil
import os
import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)
from PyInstaller.building.build_main import Analysis, PYZ, EXE, COLLECT, BUNDLE, TOC
import PyInstaller.utils.hooks
import pkg_resources
import importlib.metadata
import massdash

from PyInstaller.utils.hooks import copy_metadata
from transformers.dependency_versions_check import pkgs_to_check_at_runtime


##################### User definitions
exe_name = 'massdash_gui'
script_name = 'run.py'
if sys.platform[:6] == "darwin":
icon = '../../massdash/assets/img/MassDash_Logo.ico'
else:
icon = '../../massdash/assets/img/MassDash_Logo.ico'
block_cipher = None
location = os.getcwd()
project = "massdash"
remove_tests = True
bundle_name = "massdash"
#####################


requirements = {
req.split()[0] for req in importlib.metadata.requires(project)
}
requirements.add(project)
requirements.add("distributed")
hidden_imports = set()
datas = []
binaries = []
checked = set()
while requirements:
requirement = requirements.pop()
checked.add(requirement)
if requirement in ["pywin32"]:
continue
try:
module_version = importlib.metadata.version(requirement)
except (
importlib.metadata.PackageNotFoundError,
ModuleNotFoundError,
ImportError
):
continue
try:
datas_, binaries_, hidden_imports_ = PyInstaller.utils.hooks.collect_all(
requirement,
include_py_files=True
)
except ImportError:
continue
datas += datas_
# binaries += binaries_
hidden_imports_ = set(hidden_imports_)
if "" in hidden_imports_:
hidden_imports_.remove("")
if None in hidden_imports_:
hidden_imports_.remove(None)
requirements |= hidden_imports_ - checked
hidden_imports |= hidden_imports_

if remove_tests:
hidden_imports = sorted(
[h for h in hidden_imports if "tests" not in h.split(".")]
)
else:
hidden_imports = sorted(hidden_imports)


hidden_imports = [h for h in hidden_imports if "__pycache__" not in h]
datas = [d for d in datas if ("__pycache__" not in d[0]) and (d[1] not in [".", "Resources", "scripts"])]

#if sys.platform[:5] == "win32":
# base_path = os.path.dirname(sys.executable)
# library_path = os.path.join(base_path, "Library", "bin")
# dll_path = os.path.join(base_path, "DLLs")
# libcrypto_dll_path = os.path.join(dll_path, "libcrypto-1_1-x64.dll")
# libssl_dll_path = os.path.join(dll_path, "libssl-1_1-x64.dll")
# libcrypto_lib_path = os.path.join(library_path, "libcrypto-1_1-x64.dll")
# libssl_lib_path = os.path.join(library_path, "libssl-1_1-x64.dll")
# if not os.path.exists(libcrypto_dll_path):
# datas.append((libcrypto_lib_path, "."))
# if not os.path.exists(libssl_dll_path):
# datas.append((libssl_lib_path, "."))

for _pkg in ["python","accelerate"]:
if _pkg in pkgs_to_check_at_runtime:
pkgs_to_check_at_runtime.remove(_pkg)
for _pkg in pkgs_to_check_at_runtime:
datas += copy_metadata(_pkg)

datas += copy_metadata("streamlit")

a = Analysis(
[script_name],
pathex=[location],
binaries=binaries,
datas=datas,
hiddenimports=hidden_imports,
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False
)
pyz = PYZ(
a.pure,
a.zipped_data,
cipher=block_cipher
)

if sys.platform[:5] == "linux":
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name=bundle_name,
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
upx_exclude=[],
icon=icon
)
else:
exe = EXE(
pyz,
a.scripts,
# a.binaries,
a.zipfiles,
# a.datas,
exclude_binaries=True,
name=exe_name,
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
icon=icon
)
coll = COLLECT(
exe,
a.binaries,
# a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name=exe_name
)
10 changes: 10 additions & 0 deletions dist-scripts/pyinstaller/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is the entry point for the application when it is run as a standalone executable.
if __name__ == "__main__":
try:
import massdash.main
massdash.main.gui(['--verbose', '--no_perf', '--perf_output', 'MassDash_Performance_Report.txt', '--server_port', '8501', '--no_global_developmentMode'], standalone_mode=False)
except ImportError:
import sys
import traceback
traceback.print_exception(*sys.exc_info())
input("An error occurred. Press Enter to exit.")

0 comments on commit e09d9bd

Please sign in to comment.