2013-01-21 10:33:56 +01:00
|
|
|
require 'requirement'
|
|
|
|
|
2013-09-14 11:49:54 +01:00
|
|
|
class PythonDependency < Requirement
|
2014-01-04 13:18:42 +00:00
|
|
|
fatal true
|
2013-01-21 10:33:56 +01:00
|
|
|
|
|
|
|
satisfy :build_env => false do
|
2014-01-28 19:08:23 +01:00
|
|
|
which_python
|
|
|
|
end
|
|
|
|
|
|
|
|
def which_python
|
|
|
|
@which_python ||= which python_binary
|
2013-01-21 10:33:56 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def modify_build_environment
|
2014-02-10 14:45:08 +00:00
|
|
|
if system_python?
|
|
|
|
if python_binary == 'python'
|
|
|
|
ENV['PYTHONPATH'] = "#{HOMEBREW_PREFIX}/lib/python2.7/site-packages"
|
|
|
|
end
|
|
|
|
elsif which_python
|
2014-01-28 19:08:23 +01:00
|
|
|
ENV.prepend_path 'PATH', which_python.dirname
|
|
|
|
end
|
2013-01-21 10:33:56 +01:00
|
|
|
end
|
|
|
|
|
2014-01-28 19:08:23 +01:00
|
|
|
def system_python?
|
|
|
|
which_python.to_s == "/usr/bin/#{python_binary}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def python_binary
|
2014-01-04 13:18:42 +00:00
|
|
|
'python'
|
2013-01-21 10:33:56 +01:00
|
|
|
end
|
2014-01-28 19:08:23 +01:00
|
|
|
|
|
|
|
# Deprecated
|
|
|
|
alias_method :to_s, :python_binary
|
2014-01-04 13:18:42 +00:00
|
|
|
end
|
2013-01-21 10:33:56 +01:00
|
|
|
|
2014-01-04 13:18:42 +00:00
|
|
|
class Python3Dependency < PythonDependency
|
|
|
|
default_formula 'python3'
|
2013-01-21 10:33:56 +01:00
|
|
|
|
2014-01-20 23:30:25 -08:00
|
|
|
satisfy :build_env => false do
|
2014-01-28 19:08:23 +01:00
|
|
|
which_python
|
|
|
|
end
|
|
|
|
|
|
|
|
def python_binary
|
|
|
|
'python3'
|
2013-01-21 10:33:56 +01:00
|
|
|
end
|
|
|
|
end
|