aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/requirements/python_dependency.rb
blob: 5fe51efda92fb24dd3369d15600f941cd3cfa6fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'requirement'

class PythonDependency < Requirement
  fatal true

  satisfy :build_env => false do
    which_python
  end

  def which_python
    @which_python ||= which python_binary
  end

  def modify_build_environment
    if python_binary == 'python'
      ENV['PYTHONPATH'] = "#{HOMEBREW_PREFIX}/lib/python2.7/site-packages"
    end

    if !system_python? && which_python
      ENV.prepend_path 'PATH', which_python.dirname
    end
  end

  def system_python?
    which_python.to_s == "/usr/bin/#{python_binary}"
  end

  def python_binary
    'python'
  end

  # Deprecated
  alias_method :to_s, :python_binary
end

class Python3Dependency < PythonDependency
  default_formula 'python3'

  satisfy :build_env => false do
    which_python
  end

  def python_binary
    'python3'
  end
end