2014-03-07 18:05:56 +00:00
|
|
|
require "language/python"
|
2013-01-21 10:33:56 +01:00
|
|
|
|
2015-06-15 09:56:04 +01:00
|
|
|
class PythonRequirement < 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
|
|
|
|
2016-09-17 15:32:44 +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
|
2016-09-18 19:57:19 +01:00
|
|
|
# Always use Python 2.7 for consistency on older versions of Mac OS X.
|
2016-07-11 16:09:35 +03:00
|
|
|
version == Version.create("2.7")
|
2013-01-21 10:33:56 +01:00
|
|
|
end
|
|
|
|
|
2015-03-05 20:39:53 -05:00
|
|
|
env do
|
2015-08-09 19:12:54 -07:00
|
|
|
short_version = python_short_version
|
|
|
|
|
2016-07-11 16:09:35 +03:00
|
|
|
if !system_python? && short_version == Version.create("2.7")
|
2014-03-07 18:05:56 +00:00
|
|
|
ENV.prepend_path "PATH", which_python.dirname
|
2015-08-09 19:12:54 -07:00
|
|
|
# Homebrew Python should take precedence over older Pythons in the PATH
|
2016-07-11 16:09:35 +03:00
|
|
|
elsif short_version != Version.create("2.7")
|
2015-08-09 19:12:54 -07:00
|
|
|
ENV.prepend_path "PATH", Formula["python"].opt_bin
|
|
|
|
end
|
|
|
|
|
2015-09-10 13:25:06 -07:00
|
|
|
ENV["PYTHONPATH"] = "#{HOMEBREW_PREFIX}/lib/python#{short_version}/site-packages"
|
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
|
2015-03-05 20:48:47 -05:00
|
|
|
Pathname.new Utils.popen_read(python, "-c", "import sys; print(sys.executable)").strip
|
2013-01-21 10:33:56 +01:00
|
|
|
end
|
2014-01-28 19:08:23 +01:00
|
|
|
|
2015-08-03 13:09:07 +01: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-03-07 18:05:56 +00:00
|
|
|
|
2014-01-28 19:08:23 +01:00
|
|
|
# Deprecated
|
2016-09-23 18:13:48 +02:00
|
|
|
alias to_s python_binary
|
2014-01-04 13:18:42 +00:00
|
|
|
end
|
2013-01-21 10:33:56 +01:00
|
|
|
|
2015-06-15 09:56:04 +01:00
|
|
|
class Python3Requirement < PythonRequirement
|
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
|
|
|
|
2016-09-17 15:32:44 +01:00
|
|
|
satisfy(build_env: false) { which_python }
|
2014-01-28 19:08:23 +01:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def python_binary
|
|
|
|
"python3"
|
|
|
|
end
|
2013-01-21 10:33:56 +01:00
|
|
|
end
|