hook-chardet.py 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2026 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. from PyInstaller.utils.hooks import is_module_satisfies
  13. hiddenimports = []
  14. datas = []
  15. # Starting with v7.0.0, we need to collect mypy extension, and the data files from chardet/models
  16. if is_module_satisfies("chardet >= 7.0.0"):
  17. from PyInstaller.utils.hooks import collect_data_files
  18. from _pyinstaller_hooks_contrib.utils.mypy import find_mypyc_module_for_dist
  19. hiddenimports += find_mypyc_module_for_dist('chardet')
  20. datas += collect_data_files('chardet')
  21. # In the Windows PyPI wheel of chardet v7.4.0post2, the extensions in `chardet.pipeline` seem to come with individual
  22. # `__mypyc` counterparts (for example the `chardet.pipeline.orchestrator` extension references a corresponding
  23. # `chardet.pipeline.orchestrator__mypyc` extension). Ensure all these are collected by collecting submodules.
  24. if is_module_satisfies("chardet >= 7.4.0"):
  25. from PyInstaller.utils.hooks import collect_submodules
  26. hiddenimports += collect_submodules('chardet.pipeline')