def pre_safe_import_module(api): if not (is_win or is_cygwin): return win32com_dir = os.path.dirname(get_module_file_attribute('win32com')) comext_dir = os.path.join(os.path.dirname(win32com_dir), 'win32comext') logger.debug('win32com: extending __path__ with dir %r' % comext_dir) # Append the __path__ where PyInstaller will look for 'win32com' modules.' api.append_package_path(comext_dir)
def pre_safe_import_module(psim_api): ''' print "{" print psim_api.module_name print get_module_file_attribute(psim_api.module_name) print "}" ''' module_dir = os.path.dirname( get_module_file_attribute(psim_api.module_name)) arg_dir = os.path.join(module_dir, policies.msgDataProtocol) psim_api.append_package_path(arg_dir)
def _compile_modules(self): modules = {} for module_finder, name, ispkg in pkgutil.walk_packages(): for attempt in range(2): with suppress((AttributeError, ImportError)): if attempt == 0: loader = module_finder.find_spec(name).loader filename = loader.get_filename(name) elif attempt == 1: filename = get_module_file_attribute(name) break else: continue modules[os.path.abspath(filename)] = name return modules
import os import glob from PyInstaller.utils.hooks import get_module_file_attribute from PyInstaller.compat import is_win binaries = [] # package the DLL bundle that official scipy wheels for Windows ship if is_win: dll_glob = os.path.join(os.path.dirname( get_module_file_attribute('scipy')), 'extra-dll', "*.dll") if glob.glob(dll_glob): binaries.append((dll_glob, ".")) # collect library-wide utility extension modules hiddenimports = ['scipy._lib.%s' % m for m in [ 'messagestream', "_ccallback_c", "_fpumode"]]
#----------------------------------------------------------------------------- # Copyright (c) 2013-2020, PyInstaller Development Team. # # Distributed under the terms of the GNU General Public License (version 2 # or later) with exception for distributing the bootloader. # # The full license is in the file COPYING.txt, distributed with this software. # # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception) #----------------------------------------------------------------------------- # When PyQt5.Qt is imported it implies the import of all PyQt5 modules. See # http://pyqt.sourceforge.net/Docs/PyQt5/Qt.html. import os from PyInstaller.utils.hooks import get_module_file_attribute # Only do this if PyQt5 is found. mfi = get_module_file_attribute('PyQt5') if mfi: # Determine the name of all these modules by looking in the PyQt5 directory. hiddenimports = [] for f in os.listdir(os.path.dirname(mfi)): root, ext = os.path.splitext(os.path.basename(f)) if root.startswith('Qt') and root != 'Qt': # On Linux and OS X, PyQt 5.14.1 has a ``.abi3`` suffix on all library names. Remove it. if root.endswith('.abi3'): root = root[:-5] hiddenimports.append('PyQt5.' + root)
# ----------------------------------------------------------------------------- # Copyright (c) 2013-2019, PyInstaller Development Team. # # Distributed under the terms of the GNU General Public License with exception # for distributing bootloader. # # The full license is in the file COPYING.txt, distributed with this software. # ----------------------------------------------------------------------------- import os import glob from PyInstaller.utils.hooks import get_module_file_attribute from PyInstaller.compat import is_win binaries = [] # package the DLL bundle that official scipy wheels for Windows ship if is_win: dll_glob = os.path.join( os.path.dirname(get_module_file_attribute('scipy')), 'extra-dll', "*.dll") if glob.glob(dll_glob): binaries.append((dll_glob, ".")) # collect library-wide utility extension modules hiddenimports = [ 'scipy._lib.%s' % m for m in ['messagestream', "_ccallback_c", "_fpumode"] ]
"""Pyinstaller hooks for the main module.""" from PyInstaller.utils.hooks import get_module_file_attribute import os srctools_loc = os.path.dirname(get_module_file_attribute('srctools')) datas = [ # Add our FGD database and our srctools custom FGD. (os.path.join(srctools_loc, 'fgd.lzma'), 'srctools'), (os.path.join(srctools_loc, 'srctools.fgd'), 'srctools'), ] excludedimports = [ 'PIL', # Pillow is optional for VTF, the user will import if required. 'tkinter', # Same for Tkinter. 'wx', # And wxWidgets. ]
# ----------------------------------------------------------------------------- # Copyright (c) 2019-2020, PyInstaller Development Team. # # Distributed under the terms of the GNU General Public License (version 2 # or later) with exception for distributing the bootloader. # # The full license is in the file COPYING.txt, distributed with this software. # # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception) # ----------------------------------------------------------------------------- """ Avro is a serialization and RPC framework. """ import os from PyInstaller.utils.hooks import get_module_file_attribute res_loc = os.path.dirname(get_module_file_attribute("avro")) # see https://github.com/apache/avro/blob/master/lang/py3/setup.py datas = [ # Include the version.txt file, used to set __version__ (os.path.join(res_loc, "VERSION.txt"), "avro"), # The handshake schema is needed for IPC communication (os.path.join(res_loc, "HandshakeRequest.avsc"), "avro"), (os.path.join(res_loc, "HandshakeResponse.avsc"), "avro"), ]
# Workaround for packaging Monkey Island using PyInstaller. See https://github.com/oasis-open/cti-python-stix2/issues/218 import os from PyInstaller.utils.hooks import get_module_file_attribute stix2_dir = os.path.dirname(get_module_file_attribute('stix2')) datas = [(stix2_dir, 'stix2')]
def test_get_module_file_attribute_non_exist_module(): with pytest.raises(ImportError): get_module_file_attribute('pyinst_nonexisting_module_name')
'html.parser', ] else: # Python 2.x hiddenimports += [ 'Cookie', 'HTMLParser', ] # Include django data files - localizations, etc. datas = collect_data_files('django') # Bundle django DB schema migration scripts as data files. # They are necessary for some commands. logger.info('Collecting Django migration scripts.') django_mod_dir = os.path.dirname(get_module_file_attribute('django')) migration_modules = [ 'conf.app_template.migrations', 'contrib.admin.migrations', 'contrib.auth.migrations', 'contrib.contenttypes.migrations', 'contrib.flatpages.migrations', 'contrib.redirects.migrations', 'contrib.sessions.migrations', 'contrib.sites.migrations', ] for mod in migration_modules: bundle_dir = mod.replace('.', os.sep) pattern = os.path.join(django_mod_dir, bundle_dir, '*.py') files = glob.glob(pattern) for f in files:
# imported = {} # for filename in os.listdir(directory): # base, extension = splitext(filename) # if base in imported or base == '__pycache__': # continue # if extension in PY_EXTS and base != '__init__' or ( # not extension and isdir(join(directory, base))): # try: # module = load_module_from_file(join(directory, filename)) # # # So, we need all the Python source in the ``checkers/`` and ``reporters/`` # subdirectories, since these are run-time discovered and loaded. Therefore, # these files are all data files. In addition, since this is a module, the # pylint/__init__.py file must be included, since submodules must be children of # a module. from PyInstaller.utils.hooks import collect_data_files, collect_submodules, is_module_or_submodule,\ get_module_file_attribute datas = ( [(get_module_file_attribute('pylint.__init__'), 'pylint')] + collect_data_files('pylint.checkers', True) + collect_data_files('pylint.reporters', True) ) # Add imports from dynamically loaded modules excluding tests and testutils hiddenimports = collect_submodules('pylint', lambda name: (not is_module_or_submodule(name, 'pylint.test')) and (not name == 'testutils'))
# """ # imported = {} # for filename in os.listdir(directory): # base, extension = splitext(filename) # if base in imported or base == '__pycache__': # continue # if extension in PY_EXTS and base != '__init__' or ( # not extension and isdir(join(directory, base))): # try: # module = load_module_from_file(join(directory, filename)) # # # So, we need all the Python source in the ``checkers/`` and ``reporters/`` # subdirectories, since these are run-time discovered and loaded. Therefore, # these files are all data files. In addition, since this is a module, the # pylint/__init__.py file must be included, since submodules must be children of # a module. from PyInstaller.utils.hooks import collect_data_files, collect_submodules, is_module_or_submodule,\ get_module_file_attribute datas = ([(get_module_file_attribute('pylint.__init__'), 'pylint')] + collect_data_files('pylint.checkers', True) + collect_data_files('pylint.reporters', True)) # Add imports from dynamically loaded modules excluding tests and testutils hiddenimports = collect_submodules( 'pylint', lambda name: (not is_module_or_submodule(name, 'pylint.test')) and (not name == 'testutils'))
# # The full license is available in LICENSE.GPL.txt, distributed with # this software. # # SPDX-License-Identifier: GPL-2.0-or-later # ------------------------------------------------------------------ import os import glob from PyInstaller.utils.hooks import get_module_file_attribute from PyInstaller.compat import is_win # blspy comes as a stand-alone extension module that's placed directly # in site-packages. # # On macOS and Linux, it is linked against the GMP library, whose shared # library is stored in blspy.libs and .dylibsblspy, respectively. As this # is a linked dependency, it is collected properly by PyInstaller and # no further work is needed. # # On Windows, however, the blspy extension is linked against MPIR library, # whose DLLs are placed directly into site-packages. The mpir.dll is # linked dependency and is picked up automatically, but it in turn # dynamically loads CPU-specific backends that are named mpir_*.dll. # We need to colllect these manually. if is_win: blspy_dir = os.path.dirname(get_module_file_attribute('blspy')) mpir_dlls = glob.glob(os.path.join(blspy_dir, 'mpir_*.dll')) binaries = [(mpir_dll, '.') for mpir_dll in mpir_dlls]
# for distributing bootloader. # # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- """ Hook for cryptography module from the Python Cryptography Authority. """ import os.path import glob from PyInstaller.compat import EXTENSION_SUFFIXES from PyInstaller.utils.hooks import collect_submodules, get_module_file_attribute # Add the OpenSSL FFI binding modules as hidden imports hiddenimports = collect_submodules('cryptography.hazmat.bindings.openssl') + ['_cffi_backend'] # Include the cffi extensions as binaries in a subfolder named like the package. # The cffi verifier expects to find them inside the package directory for # the main module. We cannot use hiddenimports because that would add the modules # outside the package. binaries = [] cryptography_dir = os.path.dirname(get_module_file_attribute('cryptography')) for ext in EXTENSION_SUFFIXES: ffimods = glob.glob(os.path.join(cryptography_dir, '*_cffi_*%s*' % ext)) for f in ffimods: binaries.append((f, 'cryptography'))
def add_qt_dependencies(hook_file): # Accumulate all dependencies in a set to avoid duplicates. hiddenimports = set() translations_base = set() plugins = set() # Find the module underlying this Qt hook: change # ``/path/to/hook-PyQt5.blah.py`` to ``PyQt5.blah``. hook_name, hook_ext = os.path.splitext(os.path.basename(hook_file)) assert hook_ext.startswith('.py') assert hook_name.startswith('hook-') module_name = hook_name[5:] namespace = module_name.split('.')[0] # Retrieve Qt library info structure qt_info = get_qt_library_info(namespace) # Exit if the requested library can't be imported. NOTE: qt_info.version # can be empty list on older Qt5 versions (#5381) if qt_info.version is None: return [], [], [] # Look up the module returned by this import. module = hooks.get_module_file_attribute(module_name) logger.debug('add_qt%d_dependencies: Examining %s, based on hook of %s.', qt_info.qt_major, module, hook_file) # Walk through all the static dependencies of a dynamically-linked library # (``.so``/``.dll``/``.dylib``). imports = set(bindepend.getImports(module)) while imports: imp = imports.pop() # On Windows, find this library; other platforms already provide the # full path. if compat.is_win: # First, look for Qt binaries in the local Qt install. imp = bindepend.getfullnameof(imp, qt_info.location['BinariesPath']) # Strip off the extension and ``lib`` prefix (Linux/Mac) to give the raw # name. Lowercase (since Windows always normalized names to lowercase). lib_name = os.path.splitext(os.path.basename(imp))[0].lower() # Linux libraries sometimes have a dotted version number -- # ``libfoo.so.3``. It's now ''libfoo.so``, but the ``.so`` must also be # removed. if compat.is_linux and os.path.splitext(lib_name)[1] == '.so': lib_name = os.path.splitext(lib_name)[0] if lib_name.startswith('lib'): lib_name = lib_name[3:] # Mac: rename from ``qt`` to ``qt5`` or ``qt6`` to match names in # Windows/Linux. if compat.is_darwin and lib_name.startswith('qt'): lib_name = 'qt' + str(qt_info.qt_major) + lib_name[2:] # match libs with QT_LIBINFIX set to '_conda', i.e. conda-forge builds if lib_name.endswith('_conda'): lib_name = lib_name[:-6] logger.debug('add_qt%d_dependencies: raw lib %s -> parsed lib %s', qt_info.qt_major, imp, lib_name) # Follow only Qt dependencies. _qt_dynamic_dependencies_dict = (_qt5_dynamic_dependencies_dict if qt_info.qt_major == 5 else _qt6_dynamic_dependencies_dict) if lib_name in _qt_dynamic_dependencies_dict: # Follow these to find additional dependencies. logger.debug('add_qt%d_dependencies: Import of %s.', qt_info.qt_major, imp) imports.update(bindepend.getImports(imp)) # Look up which plugins and translations are needed. dd = _qt_dynamic_dependencies_dict[lib_name] lib_name_hiddenimports, lib_name_translations_base = dd[:2] lib_name_plugins = dd[2:] # Add them in. if lib_name_hiddenimports: hiddenimports.update([namespace + lib_name_hiddenimports]) plugins.update(lib_name_plugins) if lib_name_translations_base: translations_base.update([lib_name_translations_base]) # Change plugins into binaries. binaries = [] for plugin in plugins: more_binaries = qt_plugins_binaries(plugin, namespace=namespace) binaries.extend(more_binaries) # Change translation_base to datas. tp = qt_info.location['TranslationsPath'] tp_dst = os.path.join(qt_info.qt_rel_dir, 'translations') datas = [] for tb in translations_base: src = os.path.join(tp, tb + '_*.qm') # Not all PyQt5 installations include translations. See # https://github.com/pyinstaller/pyinstaller/pull/3229#issuecomment-359479893 # and # https://github.com/pyinstaller/pyinstaller/issues/2857#issuecomment-368744341. if glob.glob(src): datas.append((src, tp_dst)) else: logger.warning( 'Unable to find Qt%d translations %s. These ' 'translations were not packaged.', qt_info.qt_major, src) # Change hiddenimports to a list. hiddenimports = list(hiddenimports) logger.debug( 'add_qt%d_dependencies: imports from %s:\n' ' hiddenimports = %s\n' ' binaries = %s\n' ' datas = %s', qt_info.qt_major, hook_name, hiddenimports, binaries, datas) return hiddenimports, binaries, datas
# # Distributed under the terms of the GNU General Public License (version 2 # or later) with exception for distributing the bootloader. # # The full license is in the file COPYING.txt, distributed with this software. # # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception) #----------------------------------------------------------------------------- # Tested with PyNaCl 0.3.0 on Mac OS X. import os.path import glob from PyInstaller.compat import EXTENSION_SUFFIXES from PyInstaller.utils.hooks import collect_data_files, get_module_file_attribute datas = collect_data_files('nacl') # Include the cffi extensions as binaries in a subfolder named like the package. binaries = [] nacl_dir = os.path.dirname(get_module_file_attribute('nacl')) for ext in EXTENSION_SUFFIXES: ffimods = glob.glob(os.path.join(nacl_dir, '_lib', '*_cffi_*%s*' % ext)) dest_dir = os.path.join('nacl', '_lib') for f in ffimods: binaries.append((f, dest_dir))
#----------------------------------------------------------------------------- # Copyright (c) 2005-2018, PyInstaller Development Team. # # Distributed under the terms of the GNU General Public License with exception # for distributing bootloader. # # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- # Tested with PyNaCl 0.3.0 on Mac OS X. import os.path import glob from PyInstaller.compat import EXTENSION_SUFFIXES from PyInstaller.utils.hooks import collect_data_files, get_module_file_attribute datas = collect_data_files('nacl') # Include the cffi extensions as binaries in a subfolder named like the package. binaries = [] nacl_dir = os.path.dirname(get_module_file_attribute('nacl')) for ext in EXTENSION_SUFFIXES: ffimods = glob.glob(os.path.join(nacl_dir, '_lib', '*_cffi_*%s*' % ext)) dest_dir = os.path.join('nacl', '_lib') for f in ffimods: binaries.append((f, dest_dir))
# Distributed under the terms of the GNU General Public License with exception # for distributing bootloader. # # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- import os from PyInstaller.utils.hooks import ( get_module_attribute, is_module_satisfies, qt_menu_nib_dir, get_module_file_attribute, collect_data_files) from PyInstaller.compat import getsitepackages, is_darwin, is_win # On Windows system PATH has to be extended to point to the PySide2 directory. # The PySide directory contains Qt dlls. We need to avoid including different # version of Qt libraries when there is installed another application (e.g. QtCreator) if is_win: from PyInstaller.utils.win32.winutils import extend_system_path extend_system_path([os.path.join(x, 'PySide2') for x in getsitepackages()]) extend_system_path([os.path.join(os.path.dirname(get_module_file_attribute('PySide2')), 'Qt', 'bin')]) # FIXME: this should not be needed hiddenimports = ['numpy.core.multiarray'] # TODO: check if this is needed # Collect just the qt.conf file. datas = [x for x in collect_data_files('PySide2', False, os.path.join('Qt', 'bin')) if x[0].endswith('qt.conf')]
import os import glob from PyInstaller.compat import is_win from PyInstaller.utils.hooks import get_module_file_attribute binaries = [] binaries.append( (os.path.join(os.path.dirname(get_module_file_attribute('sklearn')), ".libs", "vcomp140.dll"), "sklearn/.libs/")) hiddenimports = [ 'sklearn.utils._cython_blas', 'sklearn.neighbors.typedefs', 'sklearn.neighbors.quad_tree', 'sklearn.tree', 'sklearn.tree._utils' ]
#----------------------------------------------------------------------------- # Copyright (c) 2013-2019, PyInstaller Development Team. # # Distributed under the terms of the GNU General Public License with exception # for distributing bootloader. # # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- # When PyQt5.Qt is imported it implies the import of all PyQt5 modules. See # http://pyqt.sourceforge.net/Docs/PyQt5/Qt.html. import os from PyInstaller.utils.hooks import get_module_file_attribute # Determine the name of all these modules by looking in the PyQt5 directory. hiddenimports = [] for f in os.listdir(os.path.dirname(get_module_file_attribute('PyQt5'))): root, ext = os.path.splitext(os.path.basename(f)) if root.startswith('Qt') and root != 'Qt': hiddenimports.append('PyQt5.' + root)
# Include the webengine process. The ``LibraryExecutablesPath`` is only # valid on Windows and Linux. # # Again, rewrite when Python 3.4 is EOL to # ``os.path.join(*rel_data_path, remove_prefix(...``. (os.path.join(pyqt5_library_info.location['LibraryExecutablesPath'], 'QtWebEngineProcess*'), os.path.join(*(rel_data_path + [remove_prefix(pyqt5_library_info.location['LibraryExecutablesPath'], pyqt5_library_info.location['PrefixPath'] + '/')]))) ] # Add Linux-specific libraries. if compat.is_linux: # The automatic library detection fails for `NSS # <https://packages.ubuntu.com/search?keywords=libnss3>`_, which is used by # QtWebEngine. In some distributions, the ``libnss`` supporting libraries # are stored in a subdirectory ``nss``. Since ``libnss`` is not statically # linked to these, but dynamically loads them, we need to search for and add # them. # # First, get all libraries linked to ``PyQt5.QtWebEngineWidgets``. for imp in getImports(get_module_file_attribute('PyQt5.QtWebEngineWidgets')): # Look for ``libnss3.so``. if os.path.basename(imp).startswith('libnss3.so'): # Find the location of NSS: given a ``/path/to/libnss.so``, # add ``/path/to/nss/*.so`` to get the missing NSS libraries. nss_glob = os.path.join(os.path.dirname(imp), 'nss', '*.so') if glob.glob(nss_glob): binaries.append((nss_glob, 'nss'))
import os from PyInstaller.utils.hooks import (get_module_attribute, is_module_satisfies, qt_menu_nib_dir, get_module_file_attribute, collect_data_files) from PyInstaller.compat import getsitepackages, is_darwin, is_win # On Windows system PATH has to be extended to point to the PySide2 directory. # The PySide directory contains Qt dlls. We need to avoid including different # version of Qt libraries when there is installed another application (e.g. QtCreator) if is_win: from PyInstaller.utils.win32.winutils import extend_system_path extend_system_path([os.path.join(x, 'PySide2') for x in getsitepackages()]) extend_system_path([ os.path.join(os.path.dirname(get_module_file_attribute('PySide2')), 'Qt', 'bin') ]) # FIXME: this should not be needed hiddenimports = ['numpy.core.multiarray'] # TODO: check if this is needed # Collect just the qt.conf file. datas = [ x for x in collect_data_files('PySide2', False, os.path.join('Qt', 'bin')) if x[0].endswith('qt.conf') ]
# License (version 2.0 or later). # # The full license is available in LICENSE.GPL.txt, distributed with # this software. # # SPDX-License-Identifier: GPL-2.0-or-later # ------------------------------------------------------------------ """ pysoundfile: https://github.com/bastibe/SoundFile """ import os from PyInstaller.compat import is_win, is_darwin from PyInstaller.utils.hooks import get_module_file_attribute # get path of soundfile module_dir = os.path.dirname(get_module_file_attribute('soundfile')) # add binaries packaged by soundfile on OSX and Windows # an external dependency (libsndfile) is used on GNU/Linux path = None if is_win: path = os.path.join(module_dir, '_soundfile_data') elif is_darwin: path = os.path.join(module_dir, '_soundfile_data', 'libsndfile.dylib') if path is not None and os.path.exists(path): binaries = [(path, "_soundfile_data")]
# or later) with exception for distributing the bootloader. # # The full license is in the file COPYING.txt, distributed with this software. # # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception) # ----------------------------------------------------------------------------- import os import glob from PyInstaller.compat import is_win from PyInstaller.utils.hooks import get_module_file_attribute # if we bundle the testing module, this will cause # `scipy` to be pulled in unintentionally but numpy imports # numpy.testing at the top level for historical reasons. # excludedimports = collect_submodules('numpy.testing') binaries = [] # package the DLL bundle that official numpy wheels for Windows ship # The DLL bundle will either be in extra-dll on windows proper # and in .libs if installed on a virtualenv created from MinGW (Git-Bash # for example) if is_win: extra_dll_locations = ['DLLs', 'extra-dll', '.libs'] for location in extra_dll_locations: dll_glob = os.path.join( os.path.dirname(get_module_file_attribute('numpy')), location, "*.dll") if glob.glob(dll_glob): binaries.append((dll_glob, "."))
# Distributed under the terms of the GNU General Public License (version 2 # or later) with exception for distributing the bootloader. # # The full license is in the file COPYING.txt, distributed with this software. # # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception) #----------------------------------------------------------------------------- """ `importlib_resources` is a backport of the 3.9+ module `importlib.resources` """ import os from PyInstaller.utils.hooks import get_module_file_attribute, \ is_module_satisfies, copy_metadata if is_module_satisfies("importlib_resources >= 1.2.0"): # since 1.2.0 importlib.metadata is used datas = copy_metadata('importlib_resources') else: # include the version.txt file, used to set __version__ res_loc = os.path.dirname(get_module_file_attribute('importlib_resources')) datas = [ (os.path.join(res_loc, 'version.txt'), 'importlib_resources'), ] if is_module_satisfies("importlib_resources >= 1.3.1"): hiddenimports = ['importlib_resources.trees'] # this is only required for python2 support excludedimports = ['importlib_resources._py2']
#----------------------------------------------------------------------------- # Copyright (c) 2005-2018, PyInstaller Development Team. # # Distributed under the terms of the GNU General Public License with exception # for distributing bootloader. # # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- import os import glob from PyInstaller.utils.hooks import get_module_file_attribute # Compiler (see class BaseDatabaseOperations) hiddenimports = ['django.db.models.sql.compiler'] # Include all available Django backends. modpath = os.path.dirname(get_module_file_attribute('django.db.backends')) for fn in glob.glob(os.path.join(modpath, '*')): if os.path.isdir(fn): fn = os.path.basename(fn) hiddenimports.append('django.db.backends.' + fn + '.base')
""" import os.path import glob from PyInstaller.compat import EXTENSION_SUFFIXES from PyInstaller.utils.hooks import collect_submodules, get_module_file_attribute from PyInstaller.utils.hooks import copy_metadata # get the package data so we can load the backends datas = copy_metadata('cryptography') # Add the backends as hidden imports hiddenimports = collect_submodules('cryptography.hazmat.backends') # Add the OpenSSL FFI binding modules as hidden imports hiddenimports += collect_submodules('cryptography.hazmat.bindings.openssl') + [ '_cffi_backend' ] # Include the cffi extensions as binaries in a subfolder named like the package. # The cffi verifier expects to find them inside the package directory for # the main module. We cannot use hiddenimports because that would add the modules # outside the package. binaries = [] cryptography_dir = os.path.dirname(get_module_file_attribute('cryptography')) for ext in EXTENSION_SUFFIXES: ffimods = glob.glob(os.path.join(cryptography_dir, '*_cffi_*%s*' % ext)) for f in ffimods: binaries.append((f, 'cryptography'))
# ``os.path.join(*rel_data_path, remove_prefix(...``. (os.path.join( pyqt5_library_info.location['LibraryExecutablesPath'], 'QtWebEngineProcess*'), os.path.join(*(rel_data_path + [ remove_prefix( pyqt5_library_info.location['LibraryExecutablesPath'], pyqt5_library_info.location['PrefixPath'] + '/') ]))) ] # Add Linux-specific libraries. if compat.is_linux: # The automatic library detection fails for `NSS # <https://packages.ubuntu.com/search?keywords=libnss3>`_, which is used by # QtWebEngine. In some distributions, the ``libnss`` supporting libraries # are stored in a subdirectory ``nss``. Since ``libnss`` is not statically # linked to these, but dynamically loads them, we need to search for and add # them. # # First, get all libraries linked to ``PyQt5.QtWebEngineWidgets``. for imp in getImports( get_module_file_attribute('PyQt5.QtWebEngineWidgets')): # Look for ``libnss3.so``. if os.path.basename(imp).startswith('libnss3.so'): # Find the location of NSS: given a ``/path/to/libnss.so``, # add ``/path/to/nss/*.so`` to get the missing NSS libraries. nss_subdir = os.path.join(os.path.dirname(imp), 'nss') if os.path.exists(nss_subdir): binaries.append((os.path.join(nss_subdir, '*.so'), 'nss'))
pyside2_library_info.location['LibraryExecutablesPath'], pyside2_library_info.location['PrefixPath'] + '/') ]))) ] if compat.is_win: datas += [ x for x in collect_system_data_files( pyside2_library_info.location['PrefixPath'], '.') if os.path.basename(x[0]) == 'qt.conf' ] # Add Linux-specific libraries. if compat.is_linux: # The automatic library detection fails for `NSS # <https://packages.ubuntu.com/search?keywords=libnss3>`_, which is used by # QtWebEngine. In some distributions, the ``libnss`` supporting libraries # are stored in a subdirectory ``nss``. Since ``libnss`` is not statically # linked to these, but dynamically loads them, we need to search for and add # them. # # First, get all libraries linked to ``PyQt5.QtWebEngineWidgets``. for imp in getImports( get_module_file_attribute('PySide2.QtWebEngineWidgets')): # Look for ``libnss3.so``. if os.path.basename(imp).startswith('libnss3.so'): # Find the location of NSS: given a ``/path/to/libnss.so``, # add ``/path/to/nss/*.so`` to get the missing NSS libraries. nss_subdir = os.path.join(os.path.dirname(imp), 'nss') if os.path.exists(nss_subdir): binaries.append((os.path.join(nss_subdir, '*.so'), 'nss'))
def get_qt_webengine_binaries_and_data_files(qt_library_info): binaries = [] datas = [] # Output directory (varies between PyQt and PySide and among OSes; the difference is abstracted by # qt_library_info.qt_rel_dir) rel_data_path = qt_library_info.qt_rel_dir if compat.is_darwin: # On macOS, Qt shared libraries are provided in form of .framework bundles. However, PyInstaller collects shared # library from the bundle into top-level application directory, breaking the bundle structure. # # QtWebEngine and its underlying Chromium engine, however, have very strict data file layout requirements due to # sandboxing, and does not work if the helper process executable does not load the shared library from # QtWebEngineCore.framework (which also needs to contain all resources). # # Therefore, we collect the QtWebEngineCore.framework manually, in order to obtain a working QtWebEngineProcess # helper executable. But because that bypasses our dependency scanner, we need to collect the dependent # .framework bundles as well. And we need to override QTWEBENGINEPROCESS_PATH in rthook, because the # QtWebEngineWidgets python extension actually loads up the copy of shared library that is located in # sys._MEIPASS (as opposed to the manually-copied one in .framework bundle). Furthermore, because the extension # modules use Qt shared libraries in sys._MEIPASS, we also copy all contents of # QtWebEngineCore.framework/Resources into sys._MEIPASS to make resource loading in the main process work. # # Besides being ugly, this approach has three main ramifications: # 1. we bundle two copies of each Qt shared library involved: the copy used by main process, picked up by # dependency scanner; and a copy in manually-collected .framework bundle that is used by the helper process. # 2. the trick with copying contents of Resource directory of QtWebEngineCore.framework does not work in onefile # mode, and consequently QtWebEngine does not work in onefile mode. # 3. copying contents of QtWebEngineCore.framework/Resource means that its Info.plist ends up in sys._MEIPASS, # causing the main process in onedir mode to be mis-identified as "QtWebEngineProcess". # # In the near future, this quagmire will hopefully be properly sorted out, but in the mean time, we have to live # with what we have been given. data_path = qt_library_info.location['DataPath'] libraries = [ 'QtCore', 'QtWebEngineCore', 'QtQuick', 'QtQml', 'QtQmlModels', 'QtNetwork', 'QtGui', 'QtWebChannel', 'QtPositioning' ] for i in libraries: framework_dir = i + '.framework' datas += hooks.collect_system_data_files( os.path.join(data_path, 'lib', framework_dir), os.path.join(rel_data_path, 'lib', framework_dir), True) datas += [(os.path.join(data_path, 'lib', 'QtWebEngineCore.framework', 'Resources'), os.curdir)] else: # Windows and linux locales = 'qtwebengine_locales' resources = 'resources' # Translations datas.append(( os.path.join(qt_library_info.location['TranslationsPath'], locales), os.path.join(rel_data_path, 'translations', locales), )) # Resources; ``DataPath`` is the base directory for ``resources``, as per the # `docs <https://doc.qt.io/qt-5.10/qtwebengine-deploying.html#deploying-resources>`_. datas.append( (os.path.join(qt_library_info.location['DataPath'], resources), os.path.join(rel_data_path, resources)), ) # Helper process executable (QtWebEngineProcess), located in ``LibraryExecutablesPath``. dest = os.path.join( rel_data_path, os.path.relpath(qt_library_info.location['LibraryExecutablesPath'], qt_library_info.location['PrefixPath'])) datas.append( (os.path.join(qt_library_info.location['LibraryExecutablesPath'], 'QtWebEngineProcess*'), dest)) # Add Linux-specific libraries. if compat.is_linux: # The automatic library detection fails for `NSS <https://packages.ubuntu.com/search?keywords=libnss3>`_, which # is used by QtWebEngine. In some distributions, the ``libnss`` supporting libraries are stored in a # subdirectory ``nss``. Since ``libnss`` is not statically linked to these, but dynamically loads them, we need # to search for and add them. # First, get all libraries linked to ``QtWebEngineWidgets`` extension module. module_file = hooks.get_module_file_attribute( qt_library_info.namespace + '.QtWebEngineWidgets') module_imports = bindepend.getImports(module_file) for imp in module_imports: # Look for ``libnss3.so``. if os.path.basename(imp).startswith('libnss3.so'): # Find the location of NSS: given a ``/path/to/libnss.so``, add ``/path/to/nss/*.so`` to get the # missing NSS libraries. nss_glob = os.path.join(os.path.dirname(imp), 'nss', '*.so') if glob.glob(nss_glob): binaries.append((nss_glob, 'nss')) return binaries, datas
'django.conf.app_template.migrations', 'django.contrib.admin.migrations', 'django.contrib.auth.migrations', 'django.contrib.contenttypes.migrations', 'django.contrib.flatpages.migrations', 'django.contrib.redirects.migrations', 'django.contrib.sessions.migrations', 'django.contrib.sites.migrations', ] # Include migration scripts of Django-based apps too. installed_apps = eval(get_module_attribute(package_name + '.settings', 'INSTALLED_APPS')) migration_modules.extend(set(app + '.migrations' for app in installed_apps)) # Copy migration files. for mod in migration_modules: mod_name, bundle_name = mod.split('.', 1) mod_dir = os.path.dirname(get_module_file_attribute(mod_name)) bundle_dir = bundle_name.replace('.', os.sep) pattern = os.path.join(mod_dir, bundle_dir, '*.py') files = glob.glob(pattern) for f in files: datas.append((f, os.path.join(mod_name, bundle_dir))) # Include data files from your Django project found in your django root package. datas += collect_data_files(package_name) # Include database file if using sqlite. The sqlite database is usually next to the manage.py script. root_dir_parent = os.path.dirname(root_dir) # TODO Add more patterns if necessary. _patterns = ['*.db', 'db.*'] for p in _patterns: files = glob.glob(os.path.join(root_dir_parent, p))
#----------------------------------------------------------------------------- # Copyright (c) 2005-2017, PyInstaller Development Team. # # Distributed under the terms of the GNU General Public License with exception # for distributing bootloader. # # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- import os import glob from PyInstaller.utils.hooks import get_module_file_attribute # Compiler (see class BaseDatabaseOperations) hiddenimports = ['django.db.models.sql.compiler'] # Include all available Django backends. modpath = os.path.dirname(get_module_file_attribute('django.db.backends')) for fn in glob.glob(os.path.join(modpath, '*')): if os.path.isdir(fn): fn = os.path.basename(fn) hiddenimports.append('django.db.backends.' + fn + '.base')
import os import glob from PyInstaller.compat import is_win from PyInstaller.utils.hooks import get_module_file_attribute binaries = [] binaries.append( (os.path.join(os.path.dirname(get_module_file_attribute('lightgbm')), "lib_lightgbm.dll"), "lightgbm"))
#----------------------------------------------------------------------------- """ Hook for PyZMQ. Cython based Python bindings for messaging library ZeroMQ. http://www.zeromq.org/ """ from PyInstaller.utils.hooks import collect_submodules, get_module_file_attribute from PyInstaller.compat import is_py2, is_win hiddenimports = ['zmq.utils.garbage'] + collect_submodules('zmq.backend') # Python 2 requires use of the ``CExtensionImporter`` in # ``pyimod03_importers.py``, rather than the standard Python import mechanism # used by Python 3. This break's PyZMQ's ability to find some of ts extension # module, requiring the following workaround. if is_py2: # If PyZMQ provides its own copy of libzmq and libsodium, add it to the # extension-modules TOC so zmq/__init__.py can load it at runtime. # PyZMQ is able to load 'libzmq' and 'libsodium' even from sys._MEIPASS, # like they could do with other .dlls. try: binaries = [(get_module_file_attribute('zmq.libzmq'), '.' if is_win else 'zmq')] except ImportError: # Not all platforms provide their own copy of libzmq. pass else: # If PyZMQ pvorides its own copy of libzmq and libsodium, these libs look like # C extensions. Excluding these modules ensures that those dlls are not bundled # twice. Once as ./zmq.libzmq.pyd and once as ./zmq/libzmq.py. excludedimports = ['zmq.libzmq']
#!/usr/bin/env python """ hook-chameleon.py ist303-miye Copyright (C) 2017 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ from PyInstaller.utils.hooks import get_module_file_attribute orig_file = get_module_file_attribute('chameleon.compiler') excludedimports = ['chameleon.compiler'] datas = [(orig_file, 'chameleon')]
""" Hook for PyZMQ. Cython based Python bindings for messaging library ZeroMQ. http://www.zeromq.org/ """ from PyInstaller.utils.hooks import collect_submodules, get_module_file_attribute from PyInstaller.compat import is_py2, is_win hiddenimports = ['zmq.utils.garbage'] + collect_submodules('zmq.backend') # Python 2 requires use of the ``CExtensionImporter`` in # ``pyimod03_importers.py``, rather than the standard Python import mechanism # used by Python 3. This break's PyZMQ's ability to find some of ts extension # module, requiring the following workaround. if is_py2: # If PyZMQ provides its own copy of libzmq and libsodium, add it to the # extension-modules TOC so zmq/__init__.py can load it at runtime. # PyZMQ is able to load 'libzmq' and 'libsodium' even from sys._MEIPASS, # like they could do with other .dlls. try: binaries = [(get_module_file_attribute('zmq.libzmq'), '.' if is_win else 'zmq')] except ImportError: # Not all platforms provide their own copy of libzmq. pass else: # If PyZMQ pvorides its own copy of libzmq and libsodium, these libs look like # C extensions. Excluding these modules ensures that those dlls are not bundled # twice. Once as ./zmq.libzmq.pyd and once as ./zmq/libzmq.py. excludedimports = ['zmq.libzmq']