hook-sam2.py 1.3 KB

123456789101112131415161718192021222324252627282930
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2025 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. # Hook for Segment Anything Model 2 (SAM 2): https://pypi.org/project/sam2
  13. from PyInstaller.utils.hooks import collect_data_files, collect_submodules
  14. # Collect config .yaml files.
  15. datas = collect_data_files('sam2')
  16. # Ensure that all indirectly-imported modules are collected (e.g., `sam2.modeling.backbones`).
  17. hiddenimports = collect_submodules('sam2')
  18. # Due to use of `torch.script`, we need to collect source .py files for `sam2`. The `sam2/__init__.py` also seems to be
  19. # required by `hydra`. Furthermore, the source-based introspection attempts to load the source of stdlib `enum` module.
  20. # The module collection mode support and run-time discovery of source .py files for modules that are collected into
  21. # `base_library.zip` archive was added in pyinstaller/pyinstaller#8971 (i.e., PyInstaller > 6.11.1).
  22. module_collection_mode = {
  23. 'sam2': 'pyz+py',
  24. 'enum': 'pyz+py', # requires PyInstaller > 6.11.1; no-op in earlier versions
  25. }