bpo-28552: Fix distutils.sysconfig for empty sys.executable (GH-12875) · python/cpython@0ef8c15 (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Commit 0ef8c15

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).

File tree

3 files changed

lines changed

3 files changed

lines changed

Lines changed: 1 addition & 1 deletion

Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ def finalize_options(self):
116 116 self.build_scripts = os.path.join(self.build_base,
117 117 'scripts-%d.%d' % sys.version_info[:2])
118 118
119 -if self.executable is None:
119 +if self.executable is None and sys.executable:
120 120 self.executable = os.path.normpath(sys.executable)
121 121
122 122 if isinstance(self.parallel, str):

Lines changed: 6 additions & 1 deletion

Original file line number Diff line number Diff line change
@@ -28,7 +28,12 @@
28 28 if "_PYTHON_PROJECT_BASE" in os.environ:
29 29 project_base = os.path.abspath(os.environ["_PYTHON_PROJECT_BASE"])
30 30 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()
32 37
33 38
34 39 # python_build: (Boolean) if true, we're either building Python or

Lines changed: 4 additions & 0 deletions

Original file line number Diff line number Diff 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.