From a3a0146d7ccd89755439f1b8be7e1dd28b75a88b Mon Sep 17 00:00:00 2001 From: Samuel John Date: Mon, 17 Jun 2013 09:06:38 +0200 Subject: Python module deps, ext. python fix and 10.6 fix * Fixes Homebrew/homebrew#20572 by tweaking the logic that decides which python is used by the `python` object inside a formula. There was a bug when on 10.6 there is no Python 2.7 but a :recommended Python was still treated as being available. * Use the user's PATH when looking for an external Python. Until now only brewed or OS X system's python have been found by `depends_on :python`. But now we support any Python in PATH (e.g. pyenv's python). * Further, instead of handling python modules and import tests in LanguageModuleDependency, these are now handled by: depends_on :python => 'numpy' # for example The old style depends_on 'numpy' => :python is still supported and is only an alias for the newer style (only for :python, the other languages are not altered by this commit). The reasoning is that if a formula requires a python module, it basically also needs python itself - and further that specific version of python has to provide the module. So the `PythonInstalled` is the natural place to check for the availability of a python module. Using a python module and other tags like :optional or :recommended is done like so: depends_on :python => [:optional, 'numpy'] Specifying another PyPi (Python Package index) name than the module import name is seldom used but supported, too: depends_on :python => ['enchant'=>'pyenchant'] A last note: For clarity, you can define multiple depends_on statements with different modules to be importable.` --- Library/Homebrew/python_helper.rb | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'Library/Homebrew/python_helper.rb') diff --git a/Library/Homebrew/python_helper.rb b/Library/Homebrew/python_helper.rb index dcb698c9d..3db59b334 100644 --- a/Library/Homebrew/python_helper.rb +++ b/Library/Homebrew/python_helper.rb @@ -29,25 +29,30 @@ def python_helper(options={:allowed_major_versions => [2, 3]}, &block) if python_reqs.empty? raise "If you use python in the formula, you have to add `depends_on :python` (or :python3)!" end - # Now select those that are satisfied and matching the version.major - python_reqs = python_reqs.select do |p| - p.satisfied? && - options[:allowed_major_versions].include?(p.version.major) && - if p.optional? || p.recommended? - self.build.with?(p.name) - else - true + # Now select those that are satisfied and matching the version.major and + # check that no two python binaries are the same (which could be the case + # because more than one `depends_on :python => 'module_name' may be present). + filtered_python_reqs = [] + while !python_reqs.empty? + py = python_reqs.shift + # this is ulgy but Ruby 1.8 has no `uniq! { }` + if !filtered_python_reqs.map{ |fpr| fpr.binary }.include?(py.binary) && + py.satisfied? && + options[:allowed_major_versions].include?(py.version.major) && + self.build.with?(py.name) || !(py.optional? || py.recommended?) + then + filtered_python_reqs << py end end # Allow to use an else-branch like so: `if python do ... end; else ... end` - return false if python_reqs.empty? + return false if filtered_python_reqs.empty? # Sort by version, so the older 2.x will be used first and if no # block_given? then 2.x is preferred because it is returned. # Further note, having 3.x last allows us to run `2to3 --write .` # which modifies the sources in-place (for some packages that need this). - python_reqs.sort_by{ |py| py.version }.map do |py| + filtered_python_reqs.sort_by{ |py| py.version }.map do |py| # Now is the time to set the site_packages to the correct value py.site_packages = lib/py.xy/'site-packages' if !block_given? -- cgit v1.2.3