8000 [2.7] bpo-28552: Fix distutils.sysconfig for empty sys.executable (GH-12875) by vstinner · Pull Request #12949 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[2.7] bpo-28552: Fix distutils.sysconfig for empty sys.executable (GH-12875) #12949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/distutils/command/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def finalize_options(self):
self.build_scripts = os.path.join(self.build_base,
'scripts-' + sys.version[0:3])

if self.executable is None:
if self.executable is None and sys.executable:
self.executable = os.path.normpath(sys.executable)

def run(self):
Expand Down
14 changes: 12 additions & 2 deletions Lib/distutils/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
# 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))
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()
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
Expand Down Expand Up @@ -79,7 +84,12 @@ def get_python_inc(plat_specific=0, prefix=None):

if os.name == "posix":
if python_build:
buildir = os.path.dirname(sys.executable)
if sys.executable:
buildir = os.path.dirname(sys.executable)
else:
# sys.executable can be empty if argv[0] has been changed
# and Python is unable to retrieve the real program name
buildir = os.getcwd()
if plat_specific:
# python.h is located in the buildir
inc_dir = buildir
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
0