[Python-checkins] bpo-28552: Fix distutils.sysconfig for empty sys.executable (GH-12875)
Victor Stinner
webhook-mailer at python.org
Thu Apr 25 05:59:55 EDT 2019
https://github.com/python/cpython/commit/0ef8c157e9195df0115c54ba875a5efb92ac22fb
commit: 0ef8c157e9195df0115c54ba875a5efb92ac22fb
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2019-04-25T11:59:34+02:00
summary:
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).
files:
A Misc/NEWS.d/next/Library/2019-04-18-16-10-29.bpo-28552.MW1TLt.rst
M Lib/distutils/command/build.py
M Lib/distutils/sysconfig.py
diff --git a/Lib/distutils/command/build.py b/Lib/distutils/command/build.py
index c6f52e61e1bc..a86df0bc7f92 100644
--- a/Lib/distutils/command/build.py
+++ b/Lib/distutils/command/build.py
@@ -116,7 +116,7 @@ def finalize_options(self):
self.build_scripts = os.path.join(self.build_base,
'scripts-%d.%d' % sys.version_info[:2])
- if self.executable is None:
+ if self.executable is None and sys.executable:
self.executable = os.path.normpath(sys.executable)
if isinstance(self.parallel, str):
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
index a3494670db18..570a612d1b10 100644
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -28,7 +28,12 @@
if "_PYTHON_PROJECT_BASE" in os.environ:
project_base = os.path.abspath(os.environ["_PYTHON_PROJECT_BASE"])
else:
- project_base = os.path.dirname(os.path.abspath(sys.executable))
+ if sys.executable:
+ project_base = os.path.dirname(os.path.abspath(sys.executable))
+ else:
+ # sys.executable can be empty if argv[0] has been changed and Python is
+ # unable to retrieve the real program name
+ project_base = os.getcwd()
# python_build: (Boolean) if true, we're either building Python or
diff --git a/Misc/NEWS.d/next/Library/2019-04-18-16-10-29.bpo-28552.MW1TLt.rst b/Misc/NEWS.d/next/Library/2019-04-18-16-10-29.bpo-28552.MW1TLt.rst
new file mode 100644
index 000000000000..2aa30c98c452
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-04-18-16-10-29.bpo-28552.MW1TLt.rst
@@ -0,0 +1,4 @@
+Fix :mod:`distutils.sysconfig` if :data:`sys.executable` is ``None`` or an
+empty string: use :func:`os.getcwd` to initialize ``project_base``. Fix
+also the distutils build command: don't use :data:`sys.executable` if it is
+``None`` or an empty string.
More information about the Python-checkins
mailing list