2014-03-07 18:05:56 +00:00
|
|
|
require "language/python"
|
2013-01-21 10:33:56 +01:00
|
|
|
|
2013-09-14 11:49:54 +01:00
|
|
|
class PythonDependency < Requirement
|
2014-01-04 13:18:42 +00:00
|
|
|
fatal true
|
2014-03-07 18:05:56 +00:00
|
|
|
default_formula "python"
|
2014-12-25 20:44:43 +00:00
|
|
|
cask "python"
|
2013-01-21 10:33:56 +01:00
|
|
|
|
|
|
|
satisfy :build_env => false do
|
2014-03-07 18:05:56 +00:00
|
|
|
python = which_python
|
|
|
|
next unless python
|
|
|
|
version = python_short_version
|
|
|
|
next unless version
|
|
|
|
# Always use Python 2.7 for consistency on older versions of OSX.
|
|
|
|
version == Version.new("2.7")
|
2013-01-21 10:33:56 +01:00
|
|
|
end
|
|
|
|
|
2014-03-28 14:53:12 +00:00
|
|
|
def pour_bottle?
|
2014-07-01 21:57:30 -05:00
|
|
|
build? || system_python?
|
2014-03-28 14:53:12 +00:00
|
|
|
end
|
|
|
|
|
2013-01-21 10:33:56 +01:00
|
|
|
def modify_build_environment
|
2014-02-10 14:45:08 +00:00
|
|
|
if system_python?
|
2014-03-07 18:05:56 +00:00
|
|
|
if python_binary == "python"
|
|
|
|
version = python_short_version
|
|
|
|
ENV["PYTHONPATH"] = "#{HOMEBREW_PREFIX}/lib/python#{version}/site-packages"
|
2014-02-10 14:45:08 +00:00
|
|
|
end
|
|
|
|
elsif which_python
|
2014-03-07 18:05:56 +00:00
|
|
|
ENV.prepend_path "PATH", which_python.dirname
|
2014-01-28 19:08:23 +01:00
|
|
|
end
|
2013-01-21 10:33:56 +01:00
|
|
|
end
|
|
|
|
|
2014-03-07 18:05:56 +00:00
|
|
|
def python_short_version
|
|
|
|
@short_version ||= Language::Python.major_minor_version which_python
|
2014-01-28 19:08:23 +01:00
|
|
|
end
|
|
|
|
|
2014-03-07 18:05:56 +00:00
|
|
|
def which_python
|
|
|
|
python = which python_binary
|
|
|
|
return unless python
|
|
|
|
executable = `#{python} -c "import sys; print(sys.executable)"`.strip
|
|
|
|
return unless executable
|
|
|
|
Pathname.new executable
|
2013-01-21 10:33:56 +01:00
|
|
|
end
|
2014-01-28 19:08:23 +01:00
|
|
|
|
2014-03-07 18:05:56 +00:00
|
|
|
def system_python; "/usr/bin/#{python_binary}" end
|
|
|
|
def system_python?; system_python == which_python.to_s end
|
|
|
|
def python_binary; "python" 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
|
2014-03-07 18:05:56 +00:00
|
|
|
fatal true
|
|
|
|
default_formula "python3"
|
2014-12-25 20:44:43 +00:00
|
|
|
cask "python3"
|
2013-01-21 10:33:56 +01:00
|
|
|
|
2014-03-07 18:05:56 +00:00
|
|
|
satisfy(:build_env => false) { which_python }
|
2014-01-28 19:08:23 +01:00
|
|
|
|
2014-03-07 18:05:56 +00:00
|
|
|
def python_binary; "python3" end
|
2013-01-21 10:33:56 +01:00
|
|
|
end
|