From ed53bb333b4a2b918a2020343fda89ac8331c101 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 28 Jan 2014 19:08:23 +0100 Subject: [PATCH] python_dependency: cleanup and fix build env. * Only set PYTHONPATH for Python 2. * Set the Python binary for superenv. References Homebrew/homebrew#24842. Closes Homebrew/homebrew#26197. Closes Homebrew/homebrew#26216. Closes Homebrew/homebrew#26218. Closes Homebrew/homebrew#26228. --- .../requirements/python_dependency.rb | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/requirements/python_dependency.rb b/Library/Homebrew/requirements/python_dependency.rb index 58ca58670f..5fe51efda9 100644 --- a/Library/Homebrew/requirements/python_dependency.rb +++ b/Library/Homebrew/requirements/python_dependency.rb @@ -4,23 +4,43 @@ class PythonDependency < Requirement fatal true satisfy :build_env => false do - which 'python' + which_python + end + + def which_python + @which_python ||= which python_binary end def modify_build_environment - ENV['PYTHONPATH'] = "#{HOMEBREW_PREFIX}/lib/python2.7/site-packages" + if python_binary == 'python' + ENV['PYTHONPATH'] = "#{HOMEBREW_PREFIX}/lib/python2.7/site-packages" + end + + if !system_python? && which_python + ENV.prepend_path 'PATH', which_python.dirname + end + end + + def system_python? + which_python.to_s == "/usr/bin/#{python_binary}" + end + + def python_binary + 'python' end # Deprecated - def to_s - 'python' - end + alias_method :to_s, :python_binary end class Python3Dependency < PythonDependency default_formula 'python3' satisfy :build_env => false do - which 'python3' + which_python + end + + def python_binary + 'python3' end end