Skip to content

Commit

Permalink
hooks: fix pypylon hook for PyInstaller >= 6.0
Browse files Browse the repository at this point in the history
Fix the `pypylon` hook for compatibility with PyInstaller >= 6.0.
The `collect_data_files(..., include_py_files=True)` does not
include binary extensions anymore, and PyInstaller 6.2
(pyinstaller/pyinstaller@ecc218c) fixed the module exclusion for
relative imports; so the extensions that hook tries to exclude
actually end up excluded without being collected via the
alternative codepath.

Presumably that part of hook was needed on older PyInstaller
versions, so keep it around, but disable it for PyInstaller >= 6.0.
  • Loading branch information
rokm committed Jan 18, 2024
1 parent 8612938 commit 2e19791
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-pypylon.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,28 @@

import os

from PyInstaller.utils.hooks import collect_data_files
from PyInstaller.utils.hooks import collect_dynamic_libs
from PyInstaller.utils.hooks import (
collect_data_files,
collect_dynamic_libs,
is_module_satisfies
)

# Collect dynamic libs as data (to prevent pyinstaller from modifying them)
# Collect dynamic libs as data (to prevent pyinstaller from modifying them).
# NOTE: under PyInstaller 6.x, these files end up re-classified as binaries anyway.
datas = collect_dynamic_libs('pypylon')

# Collect data files, looking for pypylon/pylonCXP/bin/ProducerCXP.cti, but other files may also be needed
datas += collect_data_files('pypylon')

# Exclude the C++-extensions from automatic search, add them manually as data files
# their dependencies were already handled with collect_dynamic_libs
excludedimports = ['pypylon._pylon', 'pypylon._genicam']
for filename, module in collect_data_files('pypylon', include_py_files=True):
if (os.path.basename(filename).startswith('_pylon.')
or os.path.basename(filename).startswith('_genicam.')):
datas += [(filename, module)]
# NOTE: the part below is incompatible with PyInstaller 6.x, because `collect_data_files(..., include_py_files=True)`
# does not include binary extensions anymore. In addition, `pyinstaller/pyinstaller@ecc218c` in PyInstaller 6.2 fixed
# the module exclusion for relative imports, so the modules listed below actually end up excluded. Presumably this
# part was necessary with older PyInstaller versions, so we keep it around, but disable it for PyInstaller >= 6.0.
if is_module_satisfies('PyInstaller < 6.0'):
# Exclude the C++-extensions from automatic search, add them manually as data files
# their dependencies were already handled with collect_dynamic_libs
excludedimports = ['pypylon._pylon', 'pypylon._genicam']
for filename, module in collect_data_files('pypylon', include_py_files=True):
if (os.path.basename(filename).startswith('_pylon.')
or os.path.basename(filename).startswith('_genicam.')):
datas += [(filename, module)]

0 comments on commit 2e19791

Please sign in to comment.