mypy.py 1.1 KB

12345678910111213141516171819202122232425
  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_hooks_contrib.compat import importlib_metadata
  13. # Given the distribution name, find the top-level `mypyc` extension module belonging to that distribution. The said
  14. # top-level module is called something like `30fcd23745efe32ce681__mypyc`; the prefix changes across different versions
  15. # of the same distribution (and, of course, across different distributions). Therefore, we need to obtain the name by
  16. # looking at distribution's list of files.
  17. def find_mypyc_module_for_dist(dist_name):
  18. try:
  19. dist = importlib_metadata.distribution(dist_name)
  20. except importlib_metadata.PackageNotFoundError:
  21. return []
  22. return [entry.name.split('.')[0] for entry in (dist.files or []) if '__mypyc' in entry.name]