From c850638537a2ef242851125fef036bec5a6fec45 Mon Sep 17 00:00:00 2001 From: Chris Wood Date: Thu, 29 Mar 2018 14:11:15 -0400 Subject: [PATCH] Fix PyInstaller builds This commit contains a few small changes to fix PyInstaller frozen builds (which were recently broken in a few ways by changes introduced with `tahoe invite`, `tahoe daemonize`, and the addition of "setuptools >= 28.8.0" to setup_requires) and removes a couple of hacks that are no longer necessary to create working frozen tahoe executables with PyInstaller. --- pyinstaller.spec | 30 +++++++++++++--------------- src/allmydata/_auto_deps.py | 10 ++-------- src/allmydata/scripts/tahoe_start.py | 2 +- tox.ini | 6 +----- 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/pyinstaller.spec b/pyinstaller.spec index 98505a23d..bfd7d5acf 100644 --- a/pyinstaller.spec +++ b/pyinstaller.spec @@ -15,17 +15,6 @@ if not hasattr(sys, 'real_prefix'): sys.exit("Please run inside a virtualenv with Tahoe-LAFS installed.") -# Ugly hack to disable the setuptools requirement asserted in '_auto_deps.py'. -# Without patching out this requirement, frozen binaries will fail at runtime. -autodeps_path = os.path.join(get_python_lib(), 'allmydata', '_auto_deps.py') -print("Patching '{}' to remove setuptools check...".format(autodeps_path)) -autodeps_path_backup = autodeps_path + '.backup' -shutil.copy2(autodeps_path, autodeps_path_backup) -with open(autodeps_path_backup) as src, open(autodeps_path, 'w+') as dest: - dest.write(src.read().replace('"setuptools >=', '#"setuptools >=')) -print("Done!") - - options = [('u', None, 'OPTION')] # Unbuffered stdio added_files = [ @@ -37,12 +26,25 @@ added_files = [ ('src/allmydata/web/static/css/*', 'allmydata/web/static/css'), ('src/allmydata/web/static/img/*.png', 'allmydata/web/static/img')] +hidden_imports = [ + 'allmydata.client', + 'allmydata.introducer', + 'allmydata.stats', + 'cffi', + 'characteristic', + 'Crypto', + 'packaging.specifiers', + 'six.moves.html_parser', + 'yaml', + 'zfec' +] + a = Analysis( ['static/tahoe.py'], pathex=[], binaries=None, datas=added_files, - hiddenimports=['characteristic', 'cffi'], + hiddenimports=hidden_imports, hookspath=[], runtime_hooks=[], excludes=[], @@ -76,10 +78,6 @@ coll = COLLECT( name='Tahoe-LAFS') -# Revert the '_auto_deps.py' patch above -shutil.move(autodeps_path_backup, autodeps_path) - - print("Creating archive...") platform_tag = platform.system().replace('Darwin', 'MacOS') bitness_tag = str(struct.calcsize('P') * 8) + 'bit' diff --git a/src/allmydata/_auto_deps.py b/src/allmydata/_auto_deps.py index 6bd532bf2..486a09199 100644 --- a/src/allmydata/_auto_deps.py +++ b/src/allmydata/_auto_deps.py @@ -123,6 +123,8 @@ package_imports = [ ('enum34', 'enum'), ('pycparser', 'pycparser'), ('PyYAML', 'yaml'), + ('magic-wormhole', 'wormhole'), + ('setuptools', 'setuptools') ] # Dependencies for which we don't know how to get a version number at run-time. @@ -141,14 +143,6 @@ ignorable = [ 'twisted-conch', ] -import sys - -# Don't try to get the version number of setuptools in frozen builds, because -# that triggers 'site' processing that causes failures. Note that frozen -# builds still (unfortunately) import pkg_resources in .tac files, so the -# entry for setuptools in install_requires above isn't conditional. -if not hasattr(sys, 'frozen'): - package_imports.append(('setuptools', 'setuptools')) setup_requires = [ 'setuptools >= 28.8.0', # for PEP-440 style versions diff --git a/src/allmydata/scripts/tahoe_start.py b/src/allmydata/scripts/tahoe_start.py index 342b55769..239607c72 100644 --- a/src/allmydata/scripts/tahoe_start.py +++ b/src/allmydata/scripts/tahoe_start.py @@ -104,7 +104,7 @@ def start(config): # "pretty fast" and with a zero return-code, or else something # Very Bad has happened. try: - args = [sys.executable] + args = [sys.executable] if not getattr(sys, 'frozen', False) else [] for i, arg in enumerate(sys.argv): if arg in ['start', 'restart']: args.append('daemonize') diff --git a/tox.ini b/tox.ini index b5122cfd9..5386c1b94 100644 --- a/tox.ini +++ b/tox.ini @@ -102,14 +102,10 @@ commands = sphinx-build -b html -d {toxinidir}/docs/_build/doctrees {toxinidir}/docs {toxinidir}/docs/_build/html [testenv:pyinstaller] -# Do not use the '--editable' flag for this testenv as the 'pyinstaller.spec' -# script called below will need patch the source tree at build-time in order -# to remove the setuptools requirement from '_auto_deps.py' (and we want to -# avoid race-conditions when running tests in parallel, e.g., with "detox"). -usedevelop = False extras = deps = . + packaging pyinstaller # Setting PYTHONHASHSEED to a known value assists with reproducible builds. # See https://pyinstaller.readthedocs.io/en/stable/advanced-topics.html#creating-a-reproducible-build