forked from pyinstaller/pyinstaller
/
hook-distutils.py
58 lines (48 loc) · 2.25 KB
/
hook-distutils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#-----------------------------------------------------------------------------
# Copyright (c) 2005-2020, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
#-----------------------------------------------------------------------------
"""
`distutils`-specific post-import hook.
This hook freezes the external `Makefile` and `pyconfig.h` files bundled with
the active Python interpreter, which the `distutils.sysconfig` module parses at
runtime for platform-specific metadata.
"""
from distutils import sysconfig
import sys
from os import path
from PyInstaller.utils.hooks import logger
if sys.version_info < (3, 6):
# XXX: Pythons >= 3.6 no longer use these files. Once we drop 3.5 support
# we can delete this.
datas = []
# Locate the ``Include`` folder containing the two files.
INCLUDE = sysconfig.get_python_inc()
# Get a dist target location. This seems to handle venv and its many
# variants better than our own attempts involving ``sys.prefix``. See
# https://github.com/pyinstaller/pyinstaller/issues/4775.
DEST = sysconfig.get_python_inc(prefix=".")
for filename in ["pyconfig.h", "Makefile"]:
source = path.join(INCLUDE, filename)
if path.exists(source):
datas.append((source, DEST))
logger.debug("Add '{}' from '{}' to '{}'."
.format(filename, INCLUDE, DEST))
else:
logger.debug("Skip non-existent '{}' from '{}' to '{}'."
.format(filename, INCLUDE, DEST))
else:
# In Python 3.6 and later ``distutils.sysconfig`` takes on the same
# behaviour as regular ``sysconfig`` of moving the config vars to an
# extension module (see hook-sysconfig.py). But it doesn't use a nice
# `get extension module name` function like ``sysconfig`` does. However the
# extension module is the same file that ``sysconfig`` uses so if we run
# the hook for ``sysconfig``, the extension module will be located and
# included.
hiddenimports = ["sysconfig"]