python_dependency: fixes, features, cleanup.

- PythonDependency now implies Python 2.7
- PythonDependency now uses brewed Python for bottling
- Use double-quotes everywhere

Closes Homebrew/homebrew#27112.
This commit is contained in:
Mike McQuaid 2014-03-07 18:05:56 +00:00
parent 34edc35b9b
commit c594053449

View File

@ -1,46 +1,54 @@
require 'requirement' require "language/python"
class PythonDependency < Requirement class PythonDependency < Requirement
fatal true fatal true
default_formula "python"
satisfy :build_env => false do satisfy :build_env => false do
which_python python = which_python
end next unless python
version = python_short_version
def which_python next unless version
@which_python ||= which python_binary # Always use Python 2.7 for consistency on older versions of OSX.
version == Version.new("2.7")
end end
def modify_build_environment def modify_build_environment
if system_python? if system_python?
if python_binary == 'python' if python_binary == "python"
ENV['PYTHONPATH'] = "#{HOMEBREW_PREFIX}/lib/python2.7/site-packages" version = python_short_version
ENV["PYTHONPATH"] = "#{HOMEBREW_PREFIX}/lib/python#{version}/site-packages"
end end
elsif which_python elsif which_python
ENV.prepend_path 'PATH', which_python.dirname ENV.prepend_path "PATH", which_python.dirname
end end
end end
def system_python? def python_short_version
which_python.to_s == "/usr/bin/#{python_binary}" @short_version ||= Language::Python.major_minor_version which_python
end end
def python_binary def which_python
'python' python = which python_binary
return unless python
executable = `#{python} -c "import sys; print(sys.executable)"`.strip
return unless executable
Pathname.new executable
end end
def system_python; "/usr/bin/#{python_binary}" end
def system_python?; system_python == which_python.to_s end
def python_binary; "python" end
# Deprecated # Deprecated
alias_method :to_s, :python_binary alias_method :to_s, :python_binary
end end
class Python3Dependency < PythonDependency class Python3Dependency < PythonDependency
default_formula 'python3' fatal true
default_formula "python3"
satisfy :build_env => false do satisfy(:build_env => false) { which_python }
which_python
end
def python_binary def python_binary; "python3" end
'python3'
end
end end