hook-distutils.py 1.4 KB

12345678910111213141516171819202122232425262728
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2005-2021, PyInstaller Development Team.
  3. #
  4. # Distributed under the terms of the GNU General Public License (version 2
  5. # or later) with exception for distributing the bootloader.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10. #-----------------------------------------------------------------------------
  11. """
  12. `distutils`-specific post-import hook.
  13. This hook freezes the external `Makefile` and `pyconfig.h` files bundled with the active Python interpreter, which the
  14. `distutils.sysconfig` module parses at runtime for platform-specific metadata.
  15. """
  16. # From Python 3.6 and later ``distutils.sysconfig`` takes on the same behaviour as regular ``sysconfig`` of moving the
  17. # config vars to a module (see hook-sysconfig.py). It doesn't use a nice `get module name` function like ``sysconfig``
  18. # does to help us locate it but the module is the same file that ``sysconfig`` uses so we can use the
  19. # ``_get_sysconfigdata_name()`` from regular ``sysconfig``.
  20. try:
  21. import sysconfig
  22. hiddenimports = [sysconfig._get_sysconfigdata_name()]
  23. except AttributeError:
  24. # Either sysconfig has no attribute _get_sysconfigdata_name (i.e., the function does not exist), or this is Windows
  25. # and the _get_sysconfigdata_name() call failed due to missing sys.abiflags attribute.
  26. pass