Skip to content
Snippets Groups Projects
Commit cb7f1586 authored by MinRK's avatar MinRK Committed by Adam Vandenberg
Browse files

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: default avatarAdam Vandenberg <flangy@gmail.com>
parent 6675fd88
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment