From cb7f1586639cb667e338000197db1579b12f7a1a Mon Sep 17 00:00:00 2001 From: MinRK Date: Thu, 21 Nov 2013 21:33:58 -0800 Subject: [PATCH] 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 --- Library/Homebrew/requirements/python_dependency.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/requirements/python_dependency.rb b/Library/Homebrew/requirements/python_dependency.rb index 831b0ddc9a..4ce9cd96ff 100644 --- a/Library/Homebrew/requirements/python_dependency.rb +++ b/Library/Homebrew/requirements/python_dependency.rb @@ -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! # + 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.