Skip to content

Commit

Permalink
Hooks: distutils: Fix no suitable dest location found for pyconfig.h.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bwoodsend committed Mar 8, 2021
1 parent ea3a2e1 commit 5806950
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
25 changes: 10 additions & 15 deletions PyInstaller/hooks/hook-distutils.py
Expand Up @@ -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()]
1 change: 1 addition & 0 deletions news/5218.hooks.rst
@@ -0,0 +1 @@
Update hook for ``distutils.sysconfig`` to be compatible with pyenv-virtualenv.

0 comments on commit 5806950

Please sign in to comment.