Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions WaterColumnPlotter/GUI/GUI_Main.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Builds a single-folder EXE for distribution.

from datetime import datetime
import sys
import os
from PyInstaller.building.build_main import Analysis, PYZ, EXE, COLLECT, TOC
from PyInstaller.compat import is_darwin, is_win

sys.setrecursionlimit(20000)


def collect_pkg_data(package, include_py_files=False, subdir=None):
from PyInstaller.utils.hooks import get_package_paths, remove_prefix, PY_IGNORE_EXTENSIONS

# Accept only strings as packages.
if type(package) is not str:
raise ValueError

pkg_base, pkg_dir = get_package_paths(package)
if subdir:
pkg_dir = os.path.join(pkg_dir, subdir)
# Walk through all file in the given package, looking for data files.
data_toc = TOC()
for dir_path, dir_names, files in os.walk(pkg_dir):
for f in files:
extension = os.path.splitext(f)[1]
if include_py_files or (extension not in PY_IGNORE_EXTENSIONS):
source_file = os.path.join(dir_path, f)
dest_folder = remove_prefix(dir_path, os.path.dirname(pkg_base) + os.sep)
dest_file = os.path.join(dest_folder, f)
data_toc.append((dest_file, source_file, 'DATA'))

return data_toc


def python_path() -> str:
""" Return the python site-specific directory prefix (PyInstaller-aware) """

# required by PyInstaller
if hasattr(sys, '_MEIPASS'):

if is_win():
import win32api
# noinspection PyProtectedMember
sys_prefix = win32api.GetLongPathName(sys._MEIPASS)
else:
# noinspection PyProtectedMember
sys_prefix = sys._MEIPASS

print("using _MEIPASS: %s" % sys_prefix)
return sys_prefix

# check if in a virtual environment
if hasattr(sys, 'real_prefix'):
return sys.real_prefix

return sys.prefix


def collect_folder_data(input_data_folder: str, relative_output_folder: str, recursively: bool = False):

data_toc = TOC()
if not os.path.exists(input_data_folder):
print("issue with folder: %s" % input_data_folder)
return data_toc

for dir_path, dir_names, files in os.walk(input_data_folder):
for f in files:
source_file = os.path.join(dir_path, f)
dest_file = os.path.normpath(
os.path.join(relative_output_folder, os.path.relpath(dir_path, input_data_folder), f))
data_toc.append((dest_file, source_file, 'DATA'))

if not recursively:
break

return data_toc


wcp_data = collect_pkg_data('WaterColumnPlotter')
print(wcp_data)

a = Analysis(['GUI_Main.py'],
pathex=[],
hiddenimports=["PIL", "scipy._lib.messagestream", "cftime._cftime", "PySide2.QtPrintSupport",
"pyproj.datadir", "pkg_resources.py2_warn"],
excludes=["IPython", "PyQt4", "pandas", "sphinx", "sphinx_rtd_theme", "OpenGL_accelerate",
"FixTk", "tcl", "tk", "_tkinter", "tkinter", "Tkinter", "wx"],
hookspath=None,
runtime_hooks=None)

pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='WaterColumnPlotter',
debug=False,
strip=None,
upx=True,
console=True)
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
wcp_data,
strip=None,
upx=True,
name='WaterColumnPlotter')