hook-distutils.py 1.8 KB

123456789101112131415161718192021222324252627282930313233
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2005-2023, 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. from PyInstaller.utils.hooks.setuptools import setuptools_info
  12. hiddenimports = []
  13. # From Python 3.6 and later ``distutils.sysconfig`` takes on the same behaviour as regular ``sysconfig`` of moving the
  14. # config vars to a module (see hook-sysconfig.py). It doesn't use a nice `get module name` function like ``sysconfig``
  15. # does to help us locate it but the module is the same file that ``sysconfig`` uses so we can use the
  16. # ``_get_sysconfigdata_name()`` from regular ``sysconfig``.
  17. try:
  18. import sysconfig
  19. hiddenimports += [sysconfig._get_sysconfigdata_name()]
  20. except AttributeError:
  21. # Either sysconfig has no attribute _get_sysconfigdata_name (i.e., the function does not exist), or this is Windows
  22. # and the _get_sysconfigdata_name() call failed due to missing sys.abiflags attribute.
  23. pass
  24. # Starting with setuptools 60.0, the vendored distutils overrides the stdlib one (which will be removed in python 3.12
  25. # anyway), so check if we are using that version. While the distutils override behavior can be controleld via the
  26. # ``SETUPTOOLS_USE_DISTUTILS`` environment variable, the latter may have a different value during the build and at the
  27. # runtime, and so we need to ensure that both stdlib and setuptools variant of distutils are collected.
  28. if setuptools_info.available and setuptools_info.version >= (60, 0):
  29. hiddenimports += ['setuptools._distutils']