hook-av.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2020 PyInstaller Development Team.
  3. #
  4. # This file is distributed under the terms of the GNU General Public
  5. # License (version 2.0 or later).
  6. #
  7. # The full license is available in LICENSE, distributed with
  8. # this software.
  9. #
  10. # SPDX-License-Identifier: GPL-2.0-or-later
  11. # ------------------------------------------------------------------
  12. import os
  13. from PyInstaller.compat import is_win
  14. from PyInstaller.utils.hooks import collect_submodules, is_module_satisfies, get_package_paths
  15. hiddenimports = ['fractions'] + collect_submodules("av")
  16. # Starting with av 9.1.1, the DLLs shipped with Windows PyPI wheels are stored
  17. # in site-packages/av.libs instead of directly in the site-packages/av.
  18. if is_module_satisfies("av >= 9.1.1") and is_win:
  19. pkg_base, pkg_dir = get_package_paths("av")
  20. lib_dir = os.path.join(pkg_base, "av.libs")
  21. if os.path.isdir(lib_dir):
  22. # We collect DLLs as data files instead of binaries to suppress binary
  23. # analysis, which would result in duplicates (because it collects a copy
  24. # into the top-level directory instead of preserving the original layout).
  25. # In addition to DLls, this also collects .load-order* file (required on
  26. # python < 3.8), and ensures that Shapely.libs directory exists (required
  27. # on python >= 3.8 due to os.add_dll_directory call).
  28. datas = [
  29. (os.path.join(lib_dir, lib_file), 'av.libs')
  30. for lib_file in os.listdir(lib_dir)
  31. ]
  32. # With av 13.0.0, one of the cythonized modules (`av.audio.layout`) started using `dataclasses`. Add it to hidden
  33. # imports to ensure it is collected in cases when it is not referenced from anywhere else.
  34. if is_module_satisfies("av >= 13.0.0"):
  35. hiddenimports += ['dataclasses']
  36. # av 13.1.0 added a cythonized `av.opaque` module that uses `uuid`; add it to hidden imports to ensure it is collected
  37. # in cases when it is not referenced from anywhere else.
  38. if is_module_satisfies("av >= 13.1.0"):
  39. hiddenimports += ['uuid']