safer check for sys.executable in sitecustomize.py
make sure it doesn't actually point to something else since sitecustomize.py is put in a location found by pypy, it breaks pypy by setting sys.executable to a path that is definitely wrong, and may not even exist. Closes Homebrew/homebrew#24581. Signed-off-by: Adam Vandenberg <flangy@gmail.com>
This commit is contained in:
parent
6675fd88fc
commit
cb7f158663
@ -296,10 +296,10 @@ class PythonDependency < Requirement
|
||||
# This file is created by Homebrew and is executed on each python startup.
|
||||
# Don't print from here, or else python command line scripts may fail!
|
||||
# <https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python>
|
||||
import os
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] != #{version.major}:
|
||||
import os
|
||||
# This can only happen if the user has set the PYTHONPATH for 3.x and run Python 2.x or vice versa.
|
||||
# Every Python looks at the PYTHONPATH variable and we can't fix it here in sitecustomize.py,
|
||||
# because the PYTHONPATH is evaluated after the sitecustomize.py. Many modules (e.g. PyQt4) are
|
||||
@ -310,7 +310,8 @@ class PythonDependency < Requirement
|
||||
' You should `unset PYTHONPATH` to fix this.')
|
||||
else:
|
||||
# Only do this for a brewed python:
|
||||
if sys.executable.startswith('#{HOMEBREW_PREFIX}'):
|
||||
opt_executable = '#{HOMEBREW_PREFIX}/opt/#{python}/bin/#{xy}'
|
||||
if os.path.realpath(sys.executable) == os.path.realpath(opt_executable):
|
||||
# Remove /System site-packages, and the Cellar site-packages
|
||||
# which we moved to lib/pythonX.Y/site-packages. Further, remove
|
||||
# HOMEBREW_PREFIX/lib/python because we later addsitedir(...).
|
||||
@ -331,7 +332,7 @@ class PythonDependency < Requirement
|
||||
pass # remember: don't print here. Better to fail silently.
|
||||
|
||||
# Set the sys.executable to use the opt_prefix
|
||||
sys.executable = '#{HOMEBREW_PREFIX}/opt/#{python}/bin/#{xy}'
|
||||
sys.executable = opt_executable
|
||||
|
||||
# Tell about homebrew's site-packages location.
|
||||
# This is needed for Python to parse *.pth.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user