Python: Don't print warning about PYTHONPATH
Authors should use `python.standard_caveats` instead. * Accessor for python.binary * Made `python.brewed?` more robust if no python found at all * python.brewed? is more relaxed now and allows older versions of the Python formula. * Only print about wrining sitecustomize.py and distutils.cfg if verbose and debug.
This commit is contained in:
parent
386373da40
commit
4412df2c00
@ -18,6 +18,7 @@ class PythonInstalled < Requirement
|
|||||||
attr_reader :if3then3
|
attr_reader :if3then3
|
||||||
attr_reader :site_packages
|
attr_reader :site_packages
|
||||||
attr_accessor :site_packages
|
attr_accessor :site_packages
|
||||||
|
attr_accessor :binary # The python.rb formula needs to set the binary
|
||||||
|
|
||||||
fatal true # you can still make Python optional by `depends_on :python => :optional`
|
fatal true # you can still make Python optional by `depends_on :python => :optional`
|
||||||
|
|
||||||
@ -62,14 +63,14 @@ class PythonInstalled < Requirement
|
|||||||
# that binary for later usage. (See Formula#python)
|
# that binary for later usage. (See Formula#python)
|
||||||
satisfy :build_env => false do
|
satisfy :build_env => false do
|
||||||
@unsatisfied_because = ''
|
@unsatisfied_because = ''
|
||||||
if binary.nil?
|
if binary.nil? || !binary.executable?
|
||||||
@unsatisfied_because += "But no `#{@name}` found in your PATH! Consider to `brew install #{@name}`."
|
@unsatisfied_because += "No `#{@name}` found in your PATH! Consider to `brew install #{@name}`."
|
||||||
false
|
false
|
||||||
elsif pypy?
|
elsif pypy?
|
||||||
@unsatisfied_because += "Your #{@name} executable appears to be a PyPy, which is not supported."
|
@unsatisfied_because += "Your #{@name} executable appears to be a PyPy, which is not supported."
|
||||||
false
|
false
|
||||||
elsif version.major != @min_version.major
|
elsif version.major != @min_version.major
|
||||||
@unsatisfied_because += "No Python #{@min_version.major}.x found!"
|
@unsatisfied_because += "No Python #{@min_version.major}.x found in your PATH! --> `brew install #{@name}`?"
|
||||||
false
|
false
|
||||||
elsif version < @min_version
|
elsif version < @min_version
|
||||||
@unsatisfied_because += "Python version #{version} is too old (need at least #{@min_version})."
|
@unsatisfied_because += "Python version #{version} is too old (need at least #{@min_version})."
|
||||||
@ -77,30 +78,21 @@ class PythonInstalled < Requirement
|
|||||||
elsif @min_version.major == 2 && `python -c "import sys; print(sys.version_info[0])"`.strip == "3"
|
elsif @min_version.major == 2 && `python -c "import sys; print(sys.version_info[0])"`.strip == "3"
|
||||||
@unsatisfied_because += "Your `python` points to a Python 3.x. This is not supported."
|
@unsatisfied_because += "Your `python` points to a Python 3.x. This is not supported."
|
||||||
else
|
else
|
||||||
# If everything satisfied, we check the PYTHONPATH, that has to be set for non-brewed Python
|
|
||||||
if !brewed? && (ENV['PYTHONPATH'].nil? || !ENV['PYTHONPATH'].include?(global_site_packages)) then
|
|
||||||
opoo <<-EOS.undent
|
|
||||||
For non-brewed Python, you have to set the PYTHONPATH in order to
|
|
||||||
find brewed Python modules.
|
|
||||||
export PYTHONPATH=#{global_site_packages}:$PYTHONPATH
|
|
||||||
EOS
|
|
||||||
# This is just to shut up a second run of satisfy.
|
|
||||||
ENV['PYTHONPATH'] = global_site_packages.to_s
|
|
||||||
end
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The full path to the python or python3 executable, depending on `version`.
|
# The full path to the python or python3 executable, depending on `version`.
|
||||||
def binary
|
def binary
|
||||||
if brewed?
|
@binary ||= begin
|
||||||
# If the python is brewed we always prefer it!
|
if brewed?
|
||||||
# Note, we don't support homebrew/versions/pythonXX.rb, though.
|
# If the python is brewed we always prefer it!
|
||||||
Formula.factory(@name).opt_prefix/"bin/python#{@min_version.major}"
|
# Note, we don't support homebrew/versions/pythonXX.rb, though.
|
||||||
else
|
Formula.factory(@name).opt_prefix/"bin/python#{@min_version.major}"
|
||||||
p = which(@name)
|
else
|
||||||
raise "PythonInstalled: #{p} is not executable" if !p.nil? && !p.executable?
|
# This should find at least system python, because /usr/bin is in PATH:
|
||||||
p
|
which(@name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -168,8 +160,7 @@ class PythonInstalled < Requirement
|
|||||||
def brewed?
|
def brewed?
|
||||||
@brewed ||= begin
|
@brewed ||= begin
|
||||||
require 'formula'
|
require 'formula'
|
||||||
f = Formula.factory(@name)
|
(Formula.factory(@name).opt_prefix/"bin/#{@name}").executable?
|
||||||
f.installed? && f.linked_keg.exist?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -211,9 +202,12 @@ class PythonInstalled < Requirement
|
|||||||
end
|
end
|
||||||
|
|
||||||
def modify_build_environment
|
def modify_build_environment
|
||||||
|
# Most methods fail if we don't have a binary.
|
||||||
|
return false if binary.nil?
|
||||||
|
|
||||||
# Write our sitecustomize.py
|
# Write our sitecustomize.py
|
||||||
file = global_site_packages/"sitecustomize.py"
|
file = global_site_packages/"sitecustomize.py"
|
||||||
ohai "Writing #{file}" if ARGV.verbose? || ARGV.homebrew_developer?
|
ohai "Writing #{file}" if ARGV.verbose? && ARGV.debug?
|
||||||
[".pyc", ".pyo", ".py"].map{ |f|
|
[".pyc", ".pyo", ".py"].map{ |f|
|
||||||
global_site_packages/"sitecustomize#{f}"
|
global_site_packages/"sitecustomize#{f}"
|
||||||
}.each{ |f| f.delete if f.exist? }
|
}.each{ |f| f.delete if f.exist? }
|
||||||
@ -239,7 +233,7 @@ class PythonInstalled < Requirement
|
|||||||
if brewed?
|
if brewed?
|
||||||
require 'formula'
|
require 'formula'
|
||||||
file = Formula.factory(@name).prefix/"Frameworks/Python.framework/Versions/#{version.major}.#{version.minor}/lib/#{xy}/distutils/distutils.cfg"
|
file = Formula.factory(@name).prefix/"Frameworks/Python.framework/Versions/#{version.major}.#{version.minor}/lib/#{xy}/distutils/distutils.cfg"
|
||||||
ohai "Writing #{file}" if ARGV.verbose? || ARGV.homebrew_developer?
|
ohai "Writing #{file}" if ARGV.verbose? && ARGV.debug?
|
||||||
file.delete if file.exist?
|
file.delete if file.exist?
|
||||||
file.write <<-EOF.undent
|
file.write <<-EOF.undent
|
||||||
[global]
|
[global]
|
||||||
@ -249,6 +243,7 @@ class PythonInstalled < Requirement
|
|||||||
prefix=#{HOMEBREW_PREFIX}
|
prefix=#{HOMEBREW_PREFIX}
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def sitecustomize
|
def sitecustomize
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user