From ac7908c62ccdbc09b754b4b74dea2b24207c85d8 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sun, 26 Nov 2017 18:15:33 -0500 Subject: [PATCH] rearrange spec files --- .../linux/pyfa-linux.spec | 0 pyfa-mac.spec => dist_assets/mac/pyfa.spec | 2 +- .../hook-matplotlib.backends.py | 78 +++++++++++++++++++ dist_assets/win/pyfa.spec | 72 +++++++++-------- pyfa-win.spec | 78 ------------------- 5 files changed, 114 insertions(+), 116 deletions(-) rename pyfa-linux.spec => dist_assets/linux/pyfa-linux.spec (100%) rename pyfa-mac.spec => dist_assets/mac/pyfa.spec (97%) create mode 100644 dist_assets/pyinstaller_hooks/hook-matplotlib.backends.py delete mode 100644 pyfa-win.spec diff --git a/pyfa-linux.spec b/dist_assets/linux/pyfa-linux.spec similarity index 100% rename from pyfa-linux.spec rename to dist_assets/linux/pyfa-linux.spec diff --git a/pyfa-mac.spec b/dist_assets/mac/pyfa.spec similarity index 97% rename from pyfa-mac.spec rename to dist_assets/mac/pyfa.spec index d10728185..f0accf264 100644 --- a/pyfa-mac.spec +++ b/dist_assets/mac/pyfa.spec @@ -43,7 +43,7 @@ a = Analysis([r'pyfa.py'], binaries=[], datas=added_files, hiddenimports=import_these, - hookspath=[], + hookspath=['dist_assets/pyinstaller_hooks'], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, diff --git a/dist_assets/pyinstaller_hooks/hook-matplotlib.backends.py b/dist_assets/pyinstaller_hooks/hook-matplotlib.backends.py new file mode 100644 index 000000000..d73ba1ec3 --- /dev/null +++ b/dist_assets/pyinstaller_hooks/hook-matplotlib.backends.py @@ -0,0 +1,78 @@ +# This apes hook-matplotlib.backends.py, but REMOVES backends, all but +# the ones in the list below. +# Courtesy of https://github.com/bpteague/cytoflow/blob/70f9291/packaging/hook-matplotlib.backends.py + +KEEP = ["WXAgg", "WX", "agg"] + +from PyInstaller.compat import is_darwin +from PyInstaller.utils.hooks import ( + eval_statement, exec_statement, logger) + + +def get_matplotlib_backend_module_names(): + """ + List the names of all matplotlib backend modules importable under the + current Python installation. + Returns + ---------- + list + List of the fully-qualified names of all such modules. + """ + # Statement safely importing a single backend module. + import_statement = """ +import os, sys +# Preserve stdout. +sys_stdout = sys.stdout +try: + # Redirect output printed by this importation to "/dev/null", preventing + # such output from being erroneously interpreted as an error. + with open(os.devnull, 'w') as dev_null: + sys.stdout = dev_null + __import__('%s') +# If this is an ImportError, print this exception's message without a traceback. +# ImportError messages are human-readable and require no additional context. +except ImportError as exc: + sys.stdout = sys_stdout + print(exc) +# Else, print this exception preceded by a traceback. traceback.print_exc() +# prints to stderr rather than stdout and must not be called here! +except Exception: + sys.stdout = sys_stdout + import traceback + print(traceback.format_exc()) +""" + + # List of the human-readable names of all available backends. + backend_names = eval_statement( + 'import matplotlib; print(matplotlib.rcsetup.all_backends)') + + # List of the fully-qualified names of all importable backend modules. + module_names = [] + + # If the current system is not OS X and the "CocoaAgg" backend is available, + # remove this backend from consideration. Attempting to import this backend + # on non-OS X systems halts the current subprocess without printing output + # or raising exceptions, preventing its reliable detection. + if not is_darwin and 'CocoaAgg' in backend_names: + backend_names.remove('CocoaAgg') + + # For safety, attempt to import each backend in a unique subprocess. + for backend_name in backend_names: + if backend_name in KEEP: + continue + + module_name = 'matplotlib.backends.backend_%s' % backend_name.lower() + stdout = exec_statement(import_statement % module_name) + + # If no output was printed, this backend is importable. + if not stdout: + module_names.append(module_name) + logger.info(' Matplotlib backend "%s": removed' % backend_name) + + return module_names + +# Freeze all importable backends, as PyInstaller is unable to determine exactly +# which backends are required by the current program. +e=get_matplotlib_backend_module_names() +print(e) +excludedimports = e \ No newline at end of file diff --git a/dist_assets/win/pyfa.spec b/dist_assets/win/pyfa.spec index 0f61a860d..a5e71adca 100644 --- a/dist_assets/win/pyfa.spec +++ b/dist_assets/win/pyfa.spec @@ -1,35 +1,36 @@ # -*- mode: python -*- -# Note: This script is provided AS-IS for those that may be interested. -# pyfa does not currently support pyInstaller (or any other build process) 100% at the moment - -# Command line to build: -# (Run from directory where pyfa.py and pyfa.spec lives.) -# c:\Python27\scripts\pyinstaller.exe --clean --noconfirm --windowed --upx-dir=.\scripts\upx.exe pyfa.spec - -# Don't forget to change the path to where your pyfa.py and pyfa.spec lives -# pathex=['C:\\Users\\Ebag333\\Documents\\GitHub\\Ebag333\\Pyfa'], - import os +from itertools import chain +import subprocess +import requests.certs + +label = subprocess.check_output([ + "git", "describe", "--tags"]).strip() + +with open('gitversion', 'w+') as f: + f.write(label.decode()) block_cipher = None added_files = [ - ( 'imgs/gui/*.png', 'imgs/gui' ), - ( 'imgs/gui/*.gif', 'imgs/gui' ), - ( 'imgs/icons/*.png', 'imgs/icons' ), - ( 'imgs/renders/*.png', 'imgs/renders' ), - ( 'dist_assets/win/pyfa.ico', '.' ), - ( 'dist_assets/cacert.pem', '.' ), - ( 'eve.db', '.' ), - ( 'README.md', '.' ), - ( 'LICENSE', '.' ), + ('../../imgs/gui/*.png', 'imgs/gui'), + ('../../imgs/gui/*.gif', 'imgs/gui'), + ('../../imgs/icons/*.png', 'imgs/icons'), + ('../../imgs/renders/*.png', 'imgs/renders'), + ('../../dist_assets/win/pyfa.ico', '.'), + (requests.certs.where(), '.'), # is this needed anymore? + ('../../eve.db', '.'), + ('../../README.md', '.'), + ('../../LICENSE', '.'), + ('../../gitversion', '.'), ] import_these = [] -# Walk eos.effects and add all effects so we can import them properly -for root, folders, files in os.walk("eos/effects"): +# Walk directories that do dynamic importing +paths = ('eos/effects', 'eos/db/migrations', 'service/conversions') +for root, folders, files in chain.from_iterable(os.walk(path) for path in paths): for file_ in files: if file_.endswith(".py") and not file_.startswith("_"): mod_name = "{}.{}".format( @@ -38,36 +39,34 @@ for root, folders, files in os.walk("eos/effects"): ) import_these.append(mod_name) -a = Analysis( - ['pyfa.py'], - pathex=['C:\\projects\\pyfa\\'], +a = Analysis(['../../pyfa.py'], + pathex=[ + # Need this, see https://github.com/pyinstaller/pyinstaller/issues/1566 + # To get this, download and install windows 10 SDK + # If not building on Windows 10, this might be optional + r'C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x86'], binaries=[], datas=added_files, hiddenimports=import_these, - hookspath=[], + hookspath=['dist_assets/pyinstaller_hooks'], runtime_hooks=[], - excludes=[], + excludes=['Tkinter'], win_no_prefer_redirects=False, win_private_assemblies=False, - cipher=block_cipher, - ) + cipher=block_cipher) -pyz = PYZ( - a.pure, - a.zipped_data, - cipher=block_cipher, - ) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) exe = EXE(pyz, a.scripts, exclude_binaries=True, debug=False, - console=False, + console=True, strip=False, upx=True, name='pyfa', icon='dist_assets/win/pyfa.ico', - onefile=False, ) coll = COLLECT( @@ -77,7 +76,6 @@ coll = COLLECT( a.datas, strip=False, upx=True, - onefile=False, name='pyfa', icon='dist_assets/win/pyfa.ico', - ) + ) \ No newline at end of file diff --git a/pyfa-win.spec b/pyfa-win.spec deleted file mode 100644 index 7671e380d..000000000 --- a/pyfa-win.spec +++ /dev/null @@ -1,78 +0,0 @@ -# -*- mode: python -*- - -import os -from itertools import chain -import subprocess - -label = subprocess.check_output([ - "git", "describe", "--tags"]).strip() - -with open('gitversion', 'w+') as f: - f.write(label.decode()) - -block_cipher = None - -added_files = [ - ( 'imgs/gui/*.png', 'imgs/gui' ), - ( 'imgs/gui/*.gif', 'imgs/gui' ), - ( 'imgs/icons/*.png', 'imgs/icons' ), - ( 'imgs/renders/*.png', 'imgs/renders' ), - ( 'dist_assets/win/pyfa.ico', '.' ), - ( 'dist_assets/cacert.pem', '.' ), - ( 'eve.db', '.' ), - ( 'README.md', '.' ), - ( 'LICENSE', '.' ), - ( 'gitversion', '.' ), - ] - -import_these = [] - -# Walk directories that do dynamic importing -paths = ('eos/effects', 'eos/db/migrations', 'service/conversions') -for root, folders, files in chain.from_iterable(os.walk(path) for path in paths): - for file_ in files: - if file_.endswith(".py") and not file_.startswith("_"): - mod_name = "{}.{}".format( - root.replace("/", "."), - file_.split(".py")[0], - ) - import_these.append(mod_name) - -a = Analysis([r'C:\Users\Ryan\Sync\Git\blitzmann\Pyfa\pyfa.py'], - pathex=[ - # Need this, see https://github.com/pyinstaller/pyinstaller/issues/1566 - # To get this, download and install windows 10 SDK - # If not building on Windows 10, this might be optional - r'C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x86'], - binaries=[], - datas=added_files, - hiddenimports=import_these, - hookspath=[], - runtime_hooks=[], - excludes=[], - win_no_prefer_redirects=False, - win_private_assemblies=False, - cipher=block_cipher) -pyz = PYZ(a.pure, a.zipped_data, - cipher=block_cipher) -exe = EXE(pyz, - a.scripts, - exclude_binaries=True, - debug=False, - console=True, - strip=False, - upx=True, - name='pyfa', - icon='dist_assets/win/pyfa.ico', - ) - -coll = COLLECT( - exe, - a.binaries, - a.zipfiles, - a.datas, - strip=False, - upx=True, - name='pyfa', - icon='dist_assets/win/pyfa.ico', - ) \ No newline at end of file