From 2ace57910796b01044ce9ac4abedf3c001d0c8fb Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Fri, 11 Jun 2021 21:52:42 +0300 Subject: [PATCH] Runtime hook for pyinstaller to load plugins and setup %PATH%. --- packages/pyinstaller/bitmessagemain.spec | 12 +++--------- .../hooks/pyinstaller_rthook_plugins.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 packages/pyinstaller/hooks/pyinstaller_rthook_plugins.py diff --git a/packages/pyinstaller/bitmessagemain.spec b/packages/pyinstaller/bitmessagemain.spec index d73e4ddf..d7d4d70d 100644 --- a/packages/pyinstaller/bitmessagemain.spec +++ b/packages/pyinstaller/bitmessagemain.spec @@ -10,7 +10,7 @@ site_root = os.path.abspath(HOMEPATH) spec_root = os.path.abspath(SPECPATH) arch = 32 if ctypes.sizeof(ctypes.c_voidp) == 4 else 64 cdrivePath = site_root[0:3] -srcPath = os.path.join(spec_root[:-20], "src") +srcPath = os.path.join(spec_root[:-20], "pybitmessage") sslName = 'OpenSSL-Win%i' % arch openSSLPath = os.path.join(cdrivePath, sslName) msvcrDllPath = os.path.join(cdrivePath, "windows", "system32") @@ -22,9 +22,7 @@ os.chdir(srcPath) snapshot = False -os.rename( - os.path.join(srcPath, '__init__.py'), - os.path.join(srcPath, '__init__.py.backup')) +hookspath=os.path.join(spec_root, 'hooks') a = Analysis( [os.path.join(srcPath, 'bitmessagemain.py')], @@ -39,14 +37,10 @@ a = Analysis( 'setuptools.msvc', '_cffi_backend', 'plugins.menu_qrcode', 'plugins.proxyconfig_stem' ], - runtime_hooks=None, + runtime_hooks=[os.path.join(hookspath, 'pyinstaller_rthook_plugins.py')], excludes=['bsddb', 'bz2', 'tcl', 'tk', 'Tkinter', 'tests'] ) -os.rename( - os.path.join(srcPath, '__init__.py.backup'), - os.path.join(srcPath, '__init__.py')) - def addTranslations(): extraDatas = [] diff --git a/packages/pyinstaller/hooks/pyinstaller_rthook_plugins.py b/packages/pyinstaller/hooks/pyinstaller_rthook_plugins.py new file mode 100644 index 00000000..e796c1f5 --- /dev/null +++ b/packages/pyinstaller/hooks/pyinstaller_rthook_plugins.py @@ -0,0 +1,17 @@ +"""Runtime PyInstaller hook to load plugins""" + +import os +import sys + +homepath = os.path.abspath(os.path.dirname(sys.argv[0])) + +os.environ['PATH'] += ';' + ';'.join([ + homepath, os.path.join(homepath, 'Tor'), + os.path.abspath(os.curdir) +]) + +try: + import pybitmessage.plugins.menu_qrcode + import pybitmessage.plugins.proxyconfig_stem # noqa:F401 +except ImportError: + pass