From dbaac79f175ca4c49082e5234e1c1d2914464076 Mon Sep 17 00:00:00 2001 From: Samuel John Date: Tue, 3 Sep 2013 10:41:54 +0200 Subject: [PATCH] PythonInstalled: Adding a private_site_packages that live in the `libexec` dir of a `Cellar`. --- Library/Homebrew/python_helper.rb | 15 ++++++++------- .../Homebrew/requirements/python_dependency.rb | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/python_helper.rb b/Library/Homebrew/python_helper.rb index bccdb7a4ec..8ebf0b7943 100644 --- a/Library/Homebrew/python_helper.rb +++ b/Library/Homebrew/python_helper.rb @@ -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///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///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 diff --git a/Library/Homebrew/requirements/python_dependency.rb b/Library/Homebrew/requirements/python_dependency.rb index 490a8f3c16..a647527668 100644 --- a/Library/Homebrew/requirements/python_dependency.rb +++ b/Library/Homebrew/requirements/python_dependency.rb @@ -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