From b9c9c6de144cba4cf1ece0c6874b564d3344f629 Mon Sep 17 00:00:00 2001 From: bwoodsend Date: Fri, 2 Oct 2020 22:32:13 +0100 Subject: [PATCH] Hooks: distutils: Fix no suitable dest location found for pyconfig.h. Locating `pyconfig.h` and the `makefile` gets into a mess when using certain environment managers (pyenv-virtualenv) because PyInstaller, whilst trying to find an appropriate `dest` path to put the files in, gets confused by `sys.prefix` (or its varients) not being a parent dir of the config and makefiles. As of Python 3.6, direct parsing of `pyconfig.h` and `makefile` are replaced by a Python module generated on building Python so that these files are no longer required. --- PyInstaller/hooks/hook-distutils.py | 25 ++++++++++--------------- news/5218.hooks.rst | 1 + 2 files changed, 11 insertions(+), 15 deletions(-) create mode 100644 news/5218.hooks.rst diff --git a/PyInstaller/hooks/hook-distutils.py b/PyInstaller/hooks/hook-distutils.py index efb98e8740a..36f322726fb 100644 --- a/PyInstaller/hooks/hook-distutils.py +++ b/PyInstaller/hooks/hook-distutils.py @@ -17,19 +17,14 @@ runtime for platform-specific metadata. """ -# TODO Verify that bundling Makefile and pyconfig.h is still required for Python 3. - -import os +from PyInstaller import compat + +# From Python 3.6 and later ``distutils.sysconfig`` takes on the same +# behaviour as regular ``sysconfig`` of moving the config vars to a +# module (see hook-sysconfig.py). It doesn't use a nice +# `get module name` function like ``sysconfig`` does to help us +# locate it but the module is the same file that ``sysconfig`` uses so +# we can use the ``_get_sysconfigdata_name()`` from regular ``sysconfig``. import sysconfig - -from PyInstaller.utils.hooks import relpath_to_config_or_make - -_CONFIG_H = sysconfig.get_config_h_filename() -_MAKEFILE = sysconfig.get_makefile_filename() - -# Data files in PyInstaller hook format. -datas = [(_CONFIG_H, relpath_to_config_or_make(_CONFIG_H))] - -# The Makefile does not exist on all platforms, eg. on Windows -if os.path.exists(_MAKEFILE): - datas.append((_MAKEFILE, relpath_to_config_or_make(_MAKEFILE))) +if not compat.is_win and hasattr(sysconfig, '_get_sysconfigdata_name'): + hiddenimports = [sysconfig._get_sysconfigdata_name()] diff --git a/news/5218.hooks.rst b/news/5218.hooks.rst new file mode 100644 index 00000000000..9de05c4e18c --- /dev/null +++ b/news/5218.hooks.rst @@ -0,0 +1 @@ +Update hook for ``distutils.sysconfig`` to be compatible with pyenv-virtualenv.