PythonInstalled: Don't require superenv
* The python do ... end block does no longer require 'superenv' but saves and restores the ENV by using ENV.to_hash and `ensure`. This should resolve some build problems with formulae using `env :std`! * `python_helper` is now in a module `Python`. * Imporoved some comments in python_dependency.rb
This commit is contained in:
parent
2fcc9bad42
commit
4e8aa8637f
@ -307,7 +307,7 @@ class Formula
|
|||||||
|
|
||||||
def python(options={:allowed_major_versions => [2, 3]}, &block)
|
def python(options={:allowed_major_versions => [2, 3]}, &block)
|
||||||
require 'python_helper'
|
require 'python_helper'
|
||||||
python_helper(options, &block)
|
Python::python_helper(options, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Explicitly only execute the block for 2.x (if a python 2.x is available)
|
# Explicitly only execute the block for 2.x (if a python 2.x is available)
|
||||||
|
|||||||
@ -2,16 +2,17 @@
|
|||||||
# The python_helper is used in the Formula class when the user calls
|
# The python_helper is used in the Formula class when the user calls
|
||||||
# `python`, `python2` or `python3`.
|
# `python`, `python2` or `python3`.
|
||||||
|
|
||||||
# This method has a dual nature. For one, it takes a &block and sets up
|
module Python
|
||||||
# the ENV such that a Python, as defined in the requirements, is the default.
|
# This method has a dual nature. For one, it takes a &block and sets up
|
||||||
# If there are multiple `PythonInstalled` requirements, the block is evaluated
|
# the ENV such that a Python, as defined in the requirements, is the default.
|
||||||
# once for each Python. This makes it possible to easily support 2.x and
|
# If there are multiple `PythonInstalled` requirements, the block is evaluated
|
||||||
# 3.x Python bindings without code duplication in formulae.
|
# once for each Python. This makes it possible to easily support 2.x and
|
||||||
# If you need to special case stuff, set :allowed_major_versions.
|
# 3.x Python bindings without code duplication in formulae.
|
||||||
# Second, inside the block, a formula author may call this method to access
|
# If you need to special case stuff, set :allowed_major_versions.
|
||||||
# certain convienience methods for the currently selected Python, e.g.
|
# Second, inside the block, a formula author may call this method to access
|
||||||
# `python.site_packages`.
|
# certain convienience methods for the currently selected Python, e.g.
|
||||||
def python_helper(options={:allowed_major_versions => [2, 3]}, &block)
|
# `python.site_packages`.
|
||||||
|
def python_helper(options={:allowed_major_versions => [2, 3]}, &block)
|
||||||
if !block_given? and !@current_python.nil?
|
if !block_given? and !@current_python.nil?
|
||||||
# We are already inside of a `python do ... end` block, so just return
|
# We are already inside of a `python do ... end` block, so just return
|
||||||
# the current_python or false if the version.major is not allowed.
|
# the current_python or false if the version.major is not allowed.
|
||||||
@ -51,9 +52,9 @@ def python_helper(options={:allowed_major_versions => [2, 3]}, &block)
|
|||||||
return py
|
return py
|
||||||
else
|
else
|
||||||
puts "brew: Python block (#{py.binary})..." if ARGV.verbose? && ARGV.debug?
|
puts "brew: Python block (#{py.binary})..." if ARGV.verbose? && ARGV.debug?
|
||||||
require 'superenv'
|
# Ensure env changes are only temporary
|
||||||
# Ensure env changes are only temporary by using `with_build_environment`
|
begin
|
||||||
ENV.with_build_environment do
|
old_env = ENV.to_hash
|
||||||
# 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
|
||||||
@ -72,8 +73,12 @@ def python_helper(options={:allowed_major_versions => [2, 3]}, &block)
|
|||||||
res = instance_eval(&block)
|
res = instance_eval(&block)
|
||||||
@current_python = nil
|
@current_python = nil
|
||||||
res
|
res
|
||||||
|
ensure
|
||||||
|
ENV.replace(old_env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end # enf of python_helper method
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -128,8 +128,8 @@ class PythonInstalled < Requirement
|
|||||||
"python#{version.major}.#{version.minor}"
|
"python#{version.major}.#{version.minor}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Homebrew's global site-packages. The local ones are populated by the
|
# Homebrew's global site-packages. The local ones (just `site_packages`) are
|
||||||
# python_helper method when the `prefix` of a formula is known.
|
# populated by the python_helper method when the `prefix` of a formula is known.
|
||||||
def global_site_packages
|
def global_site_packages
|
||||||
HOMEBREW_PREFIX/"lib/#{xy}/site-packages"
|
HOMEBREW_PREFIX/"lib/#{xy}/site-packages"
|
||||||
end
|
end
|
||||||
@ -230,7 +230,7 @@ class PythonInstalled < Requirement
|
|||||||
ENV.append 'CMAKE_INCLUDE_PATH', incdir, ':'
|
ENV.append 'CMAKE_INCLUDE_PATH', incdir, ':'
|
||||||
ENV.append 'PKG_CONFIG_PATH', pkg_config_path, ':' if pkg_config_path
|
ENV.append 'PKG_CONFIG_PATH', pkg_config_path, ':' if pkg_config_path
|
||||||
# We don't set the -F#{framework} here, because if Python 2.x and 3.x are
|
# We don't set the -F#{framework} here, because if Python 2.x and 3.x are
|
||||||
# used, `Python.framework` is ambuig. However, in the `python do` block
|
# used, `Python.framework` is ambiguous. However, in the `python do` block
|
||||||
# we can set LDFLAGS+="-F#{framework}" because only one is temporarily set.
|
# we can set LDFLAGS+="-F#{framework}" because only one is temporarily set.
|
||||||
|
|
||||||
# Udpate distutils.cfg (later we can remove this, but people still have
|
# Udpate distutils.cfg (later we can remove this, but people still have
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user