depends_on :python sets PYTHONPATH internally

This applies only to non-brewed python:
The user will still have to set his PYTHONPATH
in order to import python modules in an
external python interpreter. However, a
warning will be displayed, now.

Further, during the build, the PYTHONPATH
will be set to Homebrew's global site-packages
so that software (like PyQt and others) that
need to `import sipconfig` in python can
find the brewed sip and its python module.
This commit is contained in:
Samuel John 2013-06-05 17:33:37 +02:00
parent 1deeb1c7ef
commit a3a8bee5b9
2 changed files with 13 additions and 3 deletions

View File

@ -57,7 +57,7 @@ def python_helper(options={:allowed_major_versions => [2, 3]}, &block)
# In order to install into the Cellar, the dir must exist and be in the # In order to install into the Cellar, the dir must exist and be in the
# PYTHONPATH. This will be executed in the context of the formula # PYTHONPATH. This will be executed in the context of the formula
# so that lib points to the HOMEBREW_PREFIX/Cellar/<formula>/<version>/lib # so that lib points to the HOMEBREW_PREFIX/Cellar/<formula>/<version>/lib
puts "brew: Setting PYTHONPATH=#{py.site_packages}" if ARGV.verbose? puts "brew: Appending to PYTHONPATH: #{py.site_packages}" if ARGV.verbose?
mkdir_p py.site_packages mkdir_p py.site_packages
ENV.append 'PYTHONPATH', py.site_packages, ':' ENV.append 'PYTHONPATH', py.site_packages, ':'
ENV['PYTHON'] = py.binary ENV['PYTHON'] = py.binary

View File

@ -61,7 +61,7 @@ class PythonInstalled < Requirement
# We look for a brewed python or an external Python and store the loc of # We look for a brewed python or an external Python and store the loc of
# 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 = "This formula needs #{@name}.\n" @unsatisfied_because = ''
if binary.nil? if binary.nil?
@unsatisfied_because += "But no `#{@name}` found in your PATH! Consider to `brew install #{@name}`." @unsatisfied_because += "But no `#{@name}` found in your PATH! Consider to `brew install #{@name}`."
false false
@ -76,8 +76,17 @@ class PythonInstalled < Requirement
false false
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."
false
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
@ -215,6 +224,7 @@ class PythonInstalled < Requirement
ENV['PYTHONHOME'] = nil # to avoid fuck-ups. ENV['PYTHONHOME'] = nil # to avoid fuck-ups.
ENV['PYTHONNOUSERSITE'] = '1' ENV['PYTHONNOUSERSITE'] = '1'
ENV['PYTHONPATH'] = global_site_packages.to_s unless brewed?
# Python respects the ARCHFLAGS var if set. Shall we set them here? # Python respects the ARCHFLAGS var if set. Shall we set them here?
# ENV['ARCHFLAGS'] = ??? # FIXME # ENV['ARCHFLAGS'] = ??? # FIXME
ENV.append 'CMAKE_INCLUDE_PATH', incdir, ':' ENV.append 'CMAKE_INCLUDE_PATH', incdir, ':'