Skip to content

Commit

Permalink
Hooks: sysconfig: Don't collect pyconfig.h and makefile.
Browse files Browse the repository at this point in the history
As of Python 3.x, the config header and makefile are not longer used.  Trying to
include them causes build errors in pyenv/venv/equivalents.  Applying this fixes
5018, fixes 4775, and closes 1545 (a cleanup issue).

On Windows:
 The pyconfig.h data is hardcoded directly into sysconfig.py.
 And the makefile does not exist.
On Unix:
 A Python extension module contains all the details. This module is
 a hidden import since 3.6 but is already marked as such in the hook.

The functions to find and parse the files are still left over in sysconfig.py
but they are almost fully replaced by functions to get configuration parameters
directly. Should a user attempt to invoke the parser in a PyInstaller build, it
will now fail. They should instead use get_config_var() which will always work
(and is the recommended usage anyway).
  • Loading branch information
bwoodsend committed Mar 8, 2021
1 parent b5be6af commit ea3a2e1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
17 changes: 0 additions & 17 deletions PyInstaller/hooks/hook-sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,10 @@
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
#-----------------------------------------------------------------------------


# The 'sysconfig' module requires Makefile and pyconfig.h files from
# Python installation. 'sysconfig' parses these files to get some
# information from them.
# TODO Verify that bundling Makefile and pyconfig.h is still required for Python 3.

import sysconfig
import os

from PyInstaller.utils.hooks import relpath_to_config_or_make
from PyInstaller.compat import is_win

_CONFIG_H = sysconfig.get_config_h_filename()
_MAKEFILE = sysconfig.get_makefile_filename()


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 is_win and hasattr(sysconfig, '_get_sysconfigdata_name'):
# Python 3.6 uses additional modules like
Expand Down
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

intersphinx_mapping = {
'website': ('http://www.pyinstaller.org//', None),
'python': ('http://docs.python.org/3', None),
}

# Add any paths that contain templates here, relative to this directory.
Expand Down
1 change: 1 addition & 0 deletions news/5018.hooks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update hook for ``sysconfig`` to be compatible with pyenv-virtualenv.
4 changes: 4 additions & 0 deletions news/5218.break.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
No longer collect ``pyconfig.h`` and ``makefile`` for :mod:`sysconfig`. Instead
of :func:`~sysconfig.get_config_h_filename` and
:func:`~sysconfig.get_makefile_filename`, you should use
:func:`~sysconfig.get_config_vars` which no longer depends on those files.

0 comments on commit ea3a2e1

Please sign in to comment.