From 35b2f370694bb610118064ef0a6cc5a30fad4b70 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Tue, 28 Apr 2009 18:05:33 +0200 Subject: [PATCH] distutils: introduce and use EXECUTABLE_DIRNAME os.path.abspath(sys.executable) is used several times in distutils.sysconfig. This patch introduces the variable EXECUTABLE_DIRNAME which holds this information. This makes it easier to overwrite this value in the cross compilation scenario. (see later patch) Signed-off-by: Marc Kleine-Budde #@@ -73,13 +74,12 @@ def get_python_inc(plat_specific=0, prefix=None): # prefix = plat_specific and EXEC_PREFIX or PREFIX # if os.name == "posix": # if python_build: #- base = os.path.dirname(os.path.abspath(sys.executable)) # if plat_specific: #- inc_dir = base #+ inc_dir = EXECUTABLE_DIRNAME # else: #- inc_dir = os.path.join(base, "Include") #+ inc_dir = os.path.join(EXECUTABLE_DIRNAME, "Include") # if not os.path.exists(inc_dir): #- inc_dir = os.path.join(os.path.dirname(base), "Include") #+ inc_dir = os.path.join(os.path.dirname(EXECUTABLE_DIRNAME), "Include") # return inc_dir # return os.path.join(prefix, "include", "python" + get_python_version()) # elif os.name == "nt": --- Lib/distutils/sysconfig.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) Index: b/Lib/distutils/sysconfig.py =================================================================== --- a/Lib/distutils/sysconfig.py +++ b/Lib/distutils/sysconfig.py @@ -21,11 +21,12 @@ from .errors import DistutilsPlatformErr # These are needed in a couple of spots, so just compute them once. PREFIX = os.path.normpath(sys.prefix) EXEC_PREFIX = os.path.normpath(sys.exec_prefix) +EXECUTABLE_DIRNAME = os.path.dirname(os.path.abspath(sys.executable)) # Path to the base directory of the project. On Windows the binary may # live in project/PCBuild9. If we're dealing with an x64 Windows build, # it'll live in project/PCbuild/amd64. -project_base = os.path.dirname(os.path.abspath(sys.executable)) +project_base = EXECUTABLE_DIRNAME if os.name == "nt" and "pcbuild" in project_base[-8:].lower(): project_base = os.path.abspath(os.path.join(project_base, os.path.pardir)) # PC/VS7.1 @@ -77,9 +78,8 @@ def get_python_inc(plat_specific=0, pref # the build directory may not be the source directory, we # must use "srcdir" from the makefile to find the "Include" # directory. - base = os.path.dirname(os.path.abspath(sys.executable)) if plat_specific: - return base + return EXECUTABLE_DIRNAME else: incdir = os.path.join(get_config_var('srcdir'), 'Include') return os.path.normpath(incdir) @@ -223,7 +223,7 @@ def get_config_h_filename(): def get_makefile_filename(): """Return full pathname of installed Makefile from the Python build.""" if python_build: - return os.path.join(os.path.dirname(sys.executable), "Makefile") + return os.path.join(EXECUTABLE_DIRNAME, "Makefile") lib_dir = get_python_lib(plat_specific=1, standard_lib=1) return os.path.join(lib_dir, "config", "Makefile") @@ -520,7 +520,7 @@ def get_config_vars(*args): # testing, for example, we might be running a non-installed python # from a different directory. if python_build and os.name == "posix": - base = os.path.dirname(os.path.abspath(sys.executable)) + base = EXECUTABLE_DIRNAME if (not os.path.isabs(_config_vars['srcdir']) and base != os.getcwd()): # srcdir is relative and we are not in the same directory