PythonInstalled: Adding a private_site_packages

that live in the `libexec` dir of a `Cellar`.
This commit is contained in:
Samuel John 2013-09-03 10:41:54 +02:00
parent 0d75de42bb
commit dbaac79f17
2 changed files with 10 additions and 7 deletions

View File

@ -51,22 +51,22 @@ def python_helper(options={:allowed_major_versions => [2, 3]}, &block)
filtered_python_reqs.sort_by{ |py| py.version }.map do |py|
# Now is the time to `site_packages` to the correct value in the Cellar.
py.site_packages = lib/py.xy/'site-packages'
py.private_site_packages = libexec/"lib"/py.xy/"site-packages"
return py if !block_given?
puts "brew: Python block (#{py.binary})..." if ARGV.verbose? && ARGV.debug?
# Ensure env changes are only temporary
# Ensure env changes are only temporary:
begin
old_env = ENV.to_hash
# 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
# so that lib points to the HOMEBREW_PREFIX/Cellar/<formula>/<version>/lib
puts "brew: setting PYTHONPATH to: #{py.site_packages}" if ARGV.verbose?
# 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 and
# lib points to the `HOMEBREW_PREFIX/Cellar/<formula>/<version>/lib`.
mkdir_p py.site_packages
ENV['PYTHONPATH'] = py.site_packages
ENV.append_path 'PYTHONPATH', py.site_packages
# Allow to --prefix=libexec if a private site-packages is needed.
mkdir_p py.private_site_packages
ENV.append_path 'PYTHONPATH', py.private_site_packages
puts "brew: PYTHONPATH=#{ENV['PYTHONPATH']}" if ARGV.verbose?
ENV['PYTHON'] = py.binary
ENV.prepend_path 'CMAKE_INCLUDE_PATH', py.incdir
ENV.prepend_path 'PKG_CONFIG_PATH', py.pkg_config_path if py.pkg_config_path
@ -76,13 +76,14 @@ def python_helper(options={:allowed_major_versions => [2, 3]}, &block)
# Track the state of the currently selected python for this block,
# so if this python_helper is called again _inside_ the block,
# we can just return the right python
# we can just return the right python.
@current_python = py
res = instance_eval(&block)
@current_python = nil
res
ensure
# Clean up if the private_site_packages has not been used.
py.private_site_packages.rmdir if py.private_site_packages.children.empty?
ENV.replace(old_env)
end
end

View File

@ -19,6 +19,7 @@ class PythonInstalled < Requirement
attr_reader :imports
attr_reader :python
attr_accessor :site_packages
attr_accessor :private_site_packages
attr_writer :binary # The python.rb formula needs to set the binary
fatal true # you can still make Python optional by `depends_on :python => :optional`
@ -70,6 +71,7 @@ class PythonInstalled < Requirement
# will be set later by the python_helper, because it needs the
# formula prefix to set site_packages
@site_packages = nil
@private_site_packages = nil
super tags
end