aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/requirements/python_requirement.rb
diff options
context:
space:
mode:
authorMike McQuaid2015-06-15 09:56:04 +0100
committerMike McQuaid2015-06-16 08:12:01 +0100
commit1e867302891f04ba7857d86ea641315d2e1c8e4d (patch)
tree0ea500fbe4039445995282260b8fe7a465b7995c /Library/Homebrew/requirements/python_requirement.rb
parentf13ac9b0c8c03ccb72aeed29d2969014d7f660e8 (diff)
downloadbrew-1e867302891f04ba7857d86ea641315d2e1c8e4d.tar.bz2
Rename requirements named *Dependency.
Dependency is another similar, related class and it's super confusing to have some Requirements that are named *Dependency. Closes Homebrew/homebrew#38891. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Diffstat (limited to 'Library/Homebrew/requirements/python_requirement.rb')
-rw-r--r--Library/Homebrew/requirements/python_requirement.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/Library/Homebrew/requirements/python_requirement.rb b/Library/Homebrew/requirements/python_requirement.rb
new file mode 100644
index 000000000..df9d7328c
--- /dev/null
+++ b/Library/Homebrew/requirements/python_requirement.rb
@@ -0,0 +1,58 @@
+require "language/python"
+
+class PythonRequirement < Requirement
+ fatal true
+ default_formula "python"
+ cask "python"
+
+ satisfy :build_env => false do
+ 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")
+ end
+
+ def pour_bottle?
+ build? || system_python?
+ end
+
+ env do
+ if system_python?
+ if python_binary == "python"
+ version = python_short_version
+ ENV["PYTHONPATH"] = "#{HOMEBREW_PREFIX}/lib/python#{version}/site-packages"
+ end
+ elsif which_python
+ ENV.prepend_path "PATH", which_python.dirname
+ end
+ end
+
+ def python_short_version
+ @short_version ||= Language::Python.major_minor_version which_python
+ end
+
+ def which_python
+ python = which python_binary
+ return unless python
+ Pathname.new Utils.popen_read(python, "-c", "import sys; print(sys.executable)").strip
+ 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
+ alias_method :to_s, :python_binary
+end
+
+class Python3Requirement < PythonRequirement
+ fatal true
+ default_formula "python3"
+ cask "python3"
+
+ satisfy(:build_env => false) { which_python }
+
+ def python_binary; "python3" end
+end