Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16c8d70

Browse files
committed
When using a Python that has not been installed to build 3rd-party
modules, distutils does not understand that the build version of the source tree is needed. This patch fixes distutils.sysconfig to understand that the running Python is part of the build tree and needs to use the appropriate "shape" of the tree. This does not assume anything about the current directory, so can be used to build 3rd-party modules using Python's build tree as well. This is useful since it allows us to use a non-installed debug-mode Python with 3rd-party modules for testing. It as the side-effect that set_python_build() is no longer needed (the hack which was added to allow distutils to be used to build the "standard" extension modules). This closes SF patch #547734.
1 parent 474458d commit 16c8d70

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

Lib/distutils/sysconfig.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
PREFIX = os.path.normpath(sys.prefix)
2424
EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
2525

26-
# Boolean; if it's true, we're still building Python, so
27-
# we use different (hard-wired) directories.
28-
29-
python_build = 0
30-
31-
def set_python_build():
32-
"""Set the python_build flag to true.
33-
34-
This means that we're building Python itself. Only called from
35-
the setup.py script shipped with Python.
36-
"""
37-
global python_build
26+
# python_build: (Boolean) if true, we're either building Python or
27+
# building an extension with an un-installed Python, so we use
28+
# different (hard-wired) directories.
29+
30+
argv0_path = os.path.dirname(os.path.abspath(sys.executable))
31+
landmark = os.path.join(argv0_path, "Modules", "Setup")
32+
if not os.path.isfile(landmark):
33+
python_build = 0
34+
elif os.path.isfile(os.path.join(argv0_path, "Lib", "os.py")):
3835
python_build = 1
36+
else:
37+
python_build = os.path.isfile(os.path.join(os.path.dirname(argv0_path),
38+
"Lib", "os.py"))
39+
del argv0_path, landmark
3940

4041

4142
def get_python_inc(plat_specific=0, prefix=None):
@@ -53,7 +54,14 @@ def get_python_inc(plat_specific=0, prefix=None):
5354
prefix = plat_specific and EXEC_PREFIX or PREFIX
5455
if os.name == "posix":
5556
if python_build:
56-
return "Include/"
57+
base = os.path.dirname(os.path.abspath(sys.executable))
58+
if plat_specific:
59+
inc_dir = base
60+
else:
61+
inc_dir = os.path.join(base, "Include")
62+
if not os.path.exists(inc_dir):
63+
inc_dir = os.path.join(os.path.dirname(base), "Include")
64+
return inc_dir
5765
return os.path.join(prefix, "include", "python" + sys.version[:3])
5866
elif os.name == "nt":
5967
return os.path.join(prefix, "include")
@@ -163,7 +171,7 @@ def get_config_h_filename():
163171
def get_makefile_filename():
164172
"""Return full pathname of installed Makefile from the Python build."""
165173
if python_build:
166-
return './Makefile'
174+
return os.path.join(os.path.dirname(sys.executable), "Makefile")
167175
lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
168176
return os.path.join(lib_dir, "config", "Makefile")
169177

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,5 +822,4 @@ def main():
822822

823823
# --install-platlib
824824
if __name__ == '__main__':
825-
sysconfig.set_python_build()
826825
main()

0 commit comments

Comments
 (0)