def _warn_if_activetcl_or_teapot_installed(tcl_root, tcltree): """ If the current Tcl installation is a Teapot-distributed version of ActiveTcl *and* the current platform is OS X, log a non-fatal warning that the resulting executable will (probably) fail to run on non-host systems. PyInstaller does *not* freeze all ActiveTcl dependencies -- including Teapot, which is typically ignorable. Since Teapot is *not* ignorable in this case, this function warns of impending failure. See Also ------- https://github.com/pyinstaller/pyinstaller/issues/621 """ from macholib import util # System libraries do not experience this problem. if util.in_system_path(tcl_root): return # Absolute path of the "init.tcl" script. try: init_resource = [r[1] for r in tcltree if r[1].endswith("init.tcl")][0] # If such script could not be found, silently return. except IndexError: return mentions_activetcl = False mentions_teapot = False # TCL/TK reads files using the `system encoding <https://www.tcl.tk/doc/howto/i18n.html#system_encoding>`_. with open_file( init_resource, text_read_mode, encoding=locale.getpreferredencoding() ) as init_file: for line in init_file.readlines(): line = line.strip().lower() if line.startswith("#"): continue if "activetcl" in line: mentions_activetcl = True if "teapot" in line: mentions_teapot = True if mentions_activetcl and mentions_teapot: break if mentions_activetcl and mentions_teapot: logger.warning( """ You appear to be using an ActiveTcl build of Tcl/Tk, which PyInstaller has difficulty freezing. To fix this, comment out all references to "teapot" in: %s See https://github.com/pyinstaller/pyinstaller/issues/621 for more information. """ % init_resource )
def _warn_if_activetcl_or_teapot_installed(tcl_root, tcltree): """ If the current Tcl installation is a Teapot-distributed version of ActiveTcl *and* the current platform is OS X, log a non-fatal warning that the resulting executable will (probably) fail to run on non-host systems. PyInstaller does *not* freeze all ActiveTcl dependencies -- including Teapot, which is typically ignorable. Since Teapot is *not* ignorable in this case, this function warns of impending failure. See Also ------- https://github.com/pyinstaller/pyinstaller/issues/621 """ from PyInstaller.lib.macholib import util # System libraries do not experience this problem. if util.in_system_path(tcl_root): return # Absolute path of the "init.tcl" script. try: init_resource = [r[1] for r in tcltree if r[1].endswith('init.tcl')][0] # If such script could not be found, silently return. except IndexError: return mentions_activetcl = False mentions_teapot = False with open(init_resource, 'r') as init_file: for line in init_file.readlines(): line = line.strip().lower() if line.startswith('#'): continue if 'activetcl' in line: mentions_activetcl = True if 'teapot' in line: mentions_teapot = True if mentions_activetcl and mentions_teapot: break if mentions_activetcl and mentions_teapot: logger.warning( """ You appear to be using an ActiveTcl build of Tcl/Tk, which PyInstaller has difficulty freezing. To fix this, comment out all references to "teapot" in: %s See https://github.com/pyinstaller/pyinstaller/issues/621 for more information. """ % init_resource)
import os from PyInstaller.depend.utils import _resolveCtypesImports from PyInstaller.utils.hooks import collect_data_files, logger datas = collect_data_files("cairocffi") binaries = [] # NOTE: Update this if cairocffi requires more libraries libs = ["cairo-2", "cairo", "libcairo-2"] try: lib_basenames = [] for lib in libs: libname = ctypes.util.find_library(lib) if libname is not None: lib_basenames += [os.path.basename(libname)] if lib_basenames: resolved_libs = _resolveCtypesImports(lib_basenames) for resolved_lib in resolved_libs: binaries.append((resolved_lib[1], '.')) except Exception as e: logger.warning( "Error while trying to find system-installed Cairo library: %s", e) if not binaries: logger.warning( "Cairo library not found - cairocffi will likely fail to work!")
gdk_pixbuf_query_loaders = None if compat.architecture == '64bit': # CentOS/Fedora package as -64 cmds = ['gdk-pixbuf-query-loaders-64', 'gdk-pixbuf-query-loaders'] else: cmds = ['gdk-pixbuf-query-loaders'] for cmd in cmds: gdk_pixbuf_query_loaders = which(cmd) if gdk_pixbuf_query_loaders is not None: break if gdk_pixbuf_query_loaders is None: logger.warning( '"hook-gi.repository.GdkPixbuf" ignored, since GDK not found ' '(i.e., "gdk-pixbuf-query-loaders" not in $PATH).') # Else, GDK is available. Let's do this. else: binaries, datas, hiddenimports = get_gi_typelibs('GdkPixbuf', '2.0') datas += collect_glib_translations('gdk-pixbuf') libdir = get_gi_libdir('GdkPixbuf', '2.0') # To add support for a new platform, add a new "elif" branch below with the # proper is_<platform>() test and glob for finding loaders on that platform. if is_win: ext = "*.dll" elif is_darwin or is_linux: ext = "*.so"
loaders_path = os.path.join('gdk-pixbuf-2.0', '2.10.0', 'loaders') destpath = "lib/gdk-pixbuf/loaders" cachedest = "lib/gdk-pixbuf" # If the "gdk-pixbuf-query-loaders" command is not in the current ${PATH}, or # is not in the GI lib path, GDK and thus GdkPixbuf is unavailable. Return with # a non-fatal warning. gdk_pixbuf_query_loaders = None try: libdir = get_gi_libdir('GdkPixbuf', '2.0') except ValueError: logger.warning( '"hook-gi.repository.GdkPixbuf" ignored, ' 'since GdkPixbuf library not found' ) libdir = None if libdir: # Distributions either package gdk-pixbuf-query-loaders in the GI libs # directory (not on the path), or on the path with or without a -x64 suffix # depending on the architecture cmds = [ os.path.join(libdir, 'gdk-pixbuf-2.0/gdk-pixbuf-query-loaders'), 'gdk-pixbuf-query-loaders-64', 'gdk-pixbuf-query-loaders', ] for cmd in cmds:
import os import ctypes from PyInstaller.utils.hooks import logger, get_package_paths, collect_data_files from PyInstaller.depend.utils import _resolveCtypesImports binaries = [] pkg_base, pkg_dir = get_package_paths('flower') binaries += [(os.path.join(pkg_dir, 'static'), 'flower/static')] binaries += [(os.path.join(pkg_dir, 'templates'), 'flower/templates')] binaries += [(os.path.join(pkg_dir, 'views'), 'flower/views')] logger.warning(binaries) #logger.warning(datas)
gdk_pixbuf_query_loaders = None if architecture() == '64bit': # CentOS/Fedora package as -64 cmds = ['gdk-pixbuf-query-loaders-64', 'gdk-pixbuf-query-loaders'] else: cmds = ['gdk-pixbuf-query-loaders'] for cmd in cmds: gdk_pixbuf_query_loaders = which(cmd) if gdk_pixbuf_query_loaders is not None: break if gdk_pixbuf_query_loaders is None: logger.warning( '"hook-gi.repository.GdkPixbuf" ignored, since GDK not found ' '(i.e., "gdk-pixbuf-query-loaders" not in $PATH).' ) # Else, GDK is available. Let's do this. else: binaries, datas, hiddenimports = get_gi_typelibs('GdkPixbuf', '2.0') datas += collect_glib_translations('gdk-pixbuf') libdir = get_gi_libdir('GdkPixbuf', '2.0') # To add support for a new platform, add a new "elif" branch below with the # proper is_<platform>() test and glob for finding loaders on that platform. if is_win: pattern = os.path.join( libdir, 'gdk-pixbuf-2.0', '2.10.0', 'loaders', '*.dll') elif is_darwin or is_linux: pattern = os.path.join(
if not binaries and not (is_win or is_darwin): def _find_system_mediainfo_library(): import os import ctypes.util from PyInstaller.depend.utils import _resolveCtypesImports libname = ctypes.util.find_library("mediainfo") if libname is not None: resolved_binary = _resolveCtypesImports( [os.path.basename(libname)]) if resolved_binary: return resolved_binary[0][1] try: mediainfo_lib = _find_system_mediainfo_library() except Exception as e: logger.warning( "Error while trying to find system-installed MediaInfo library: %s", e) mediainfo_lib = None if mediainfo_lib: # Put the library into pymediainfo sub-directory, to keep layout consistent with that of wheels. binaries += [(mediainfo_lib, 'pymediainfo')] if not binaries: logger.warning( "MediaInfo shared library not found - pymediainfo will likely fail to work!" )
# Linux and macOS also require distutils. if not is_win: hiddenimports += ["distutils.util"] # Data collection datas = collect_data_files('pyproj') if hasattr(sys, 'real_prefix'): # check if in a virtual environment root_path = sys.real_prefix else: root_path = sys.prefix # - conda-specific if is_win: tgt_proj_data = os.path.join('Library', 'share', 'proj') src_proj_data = os.path.join(root_path, 'Library', 'share', 'proj') else: # both linux and darwin tgt_proj_data = os.path.join('share', 'proj') src_proj_data = os.path.join(root_path, 'share', 'proj') from PyInstaller.compat import is_conda if is_conda: if os.path.exists(src_proj_data): datas.append((src_proj_data, tgt_proj_data)) else: from PyInstaller.utils.hooks import logger logger.warning( "Datas for pyproj not found at:\n{}".format(src_proj_data)) # A runtime hook defines the path for `PROJ_LIB`
backend_contents_before_discovery = set(dir(usb.backend)) # perform find, which will load a usb library if found usb.core.find() # get the backend symbols which have been added (loaded) backends = set(dir(usb.backend)) - backend_contents_before_discovery # gather the libraries from the loaded backends backend_lib_basenames = [] for usblib in [getattr(usb.backend, be)._lib for be in backends]: if usblib is not None: # OSX returns the full path, Linux only the filename. # save the basename and reconstruct the path after gathering. backend_lib_basenames.append(os.path.basename(usblib._name)) # try to resolve the library names to absolute paths. binaries = _resolveCtypesImports(backend_lib_basenames) except (ValueError, usb.core.USBError) as exc: logger.warning("%s", exc) # If pyusb didn't find a backend, manually search for usb libraries. if not binaries: # NOTE: Update these lists when adding further libs. if is_cygwin: libusb_candidates = ['cygusb-1.0-0.dll', 'cygusb0.dll'] else: libusb_candidates = [ # libusb10 'usb-1.0', 'usb', 'libusb-1.0', # libusb01 'usb-0.1', 'libusb0', # openusb 'openusb', ]
pyusb_backend_dir = set(dir(usb.backend)) # perform find, which will load a usb library if found usb.core.find() # get the backend symbols which have been added (loaded) backends = set(dir(usb.backend)) - pyusb_backend_dir # for each of the loaded backends, see if they have a library binaries = [] for usblib in [getattr(usb.backend, be)._lib for be in backends]: if usblib is not None: binaries = [(usblib._name, '')] except (ValueError, usb.core.USBError) as exc: logger.warning("%s", exc) # if nothing found, try to use our custom mechanism if not binaries: # Try to resolve your libusb libraries in the following order: # # libusb-1.0, libusb-0.1, openusb # # NOTE: Mind updating run-time hook when adding further libs. libusb_candidates = ( # libusb10 'usb-1.0', 'usb', 'libusb-1.0', # libusb01 'usb-0.1', 'libusb0', # openusb
if is_win: fontconfig_config_dir = Path( libname).parent.parent / 'etc/fonts' if fontconfig_config_dir.exists( ) and fontconfig_config_dir.is_dir(): datas += [(str(fontconfig_config_dir), 'etc/fonts')] fontconfig_config_dir_found = True if lib_basenames: resolved_libs = _resolveCtypesImports(lib_basenames) for resolved_lib in resolved_libs: binaries.append((resolved_lib[1], '.')) # Try to load fontconfig config files on other OS fontconfig_config_dir = Path('/etc/fonts') if fontconfig_config_dir.exists() and fontconfig_config_dir.is_dir(): datas += [(str(fontconfig_config_dir), 'etc/fonts')] fontconfig_config_dir_found = True except Exception as e: logger.warning( 'Error while trying to find system-installed depending libraries: %s', e) if not binaries: logger.warning( 'Depending libraries not found - weasyprint will likely fail to work!') if not fontconfig_config_dir_found: logger.warning( 'Fontconfig configuration files not found - weasyprint will likely throw warnings and use default fonts!' )