Skip to content

Commit 0ef8c15

Browse files
authored
bpo-28552: Fix distutils.sysconfig for empty sys.executable (GH-12875)
bpo-28552, bpo-7774: Fix distutils.sysconfig if sys.executable is None or an empty string: use os.getcwd() to initialize project_base. Fix also the distutils build command: don't use sys.executable if it's evaluated as false (None or empty string).
1 parent 235e7b2 commit 0ef8c15

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Lib/distutils/command/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def finalize_options(self):
116116
self.build_scripts = os.path.join(self.build_base,
117117
'scripts-%d.%d' % sys.version_info[:2])
118118

119-
if self.executable is None:
119+
if self.executable is None and sys.executable:
120120
self.executable = os.path.normpath(sys.executable)
121121

122122
if isinstance(self.parallel, str):

Lib/distutils/sysconfig.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@
2828
if "_PYTHON_PROJECT_BASE" in os.environ:
2929
project_base = os.path.abspath(os.environ["_PYTHON_PROJECT_BASE"])
3030
else:
31-
project_base = os.path.dirname(os.path.abspath(sys.executable))
31+
if sys.executable:
32+
project_base = os.path.dirname(os.path.abspath(sys.executable))
33+
else:
34+
# sys.executable can be empty if argv[0] has been changed and Python is
35+
# unable to retrieve the real program name
36+
project_base = os.getcwd()
3237

3338

3439
# python_build: (Boolean) if true, we're either building Python or
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix :mod:`distutils.sysconfig` if :data:`sys.executable` is ``None`` or an
2+
empty string: use :func:`os.getcwd` to initialize ``project_base``. Fix
3+
also the distutils build command: don't use :data:`sys.executable` if it is
4+
``None`` or an empty string.

0 commit comments

Comments
 (0)