python: do not add main brewed Python site-package to virtualenv
If added, this makes the virtualenv read the main site-package from brewed Python, and especially makes it read our sitecustomize.py file, which will modify the sys.executable path. See the full discussion at: https://github.com/Homebrew/brew/pull/8873 I also took the opportunity to not include test deps, as these will be not be installed, so the .pth file should not contains references to site-packages from test deps. Previous packages on Linux did already contain the wrong lines in the pth file, for example: cat /home/linuxbrew/.linuxbrew/Cellar/aws-google-auth/0.0.36_1/libexec/lib/python3.8/site-packages/homebrew_deps.pth import site; site.addsitedir('/home/linuxbrew/.linuxbrew/opt/python@3.8/lib/python3.8/site-packages') import site; site.addsitedir('/home/linuxbrew/.linuxbrew/opt/libxml2/lib/python3.8/site-packages') This might have caused subtle bugs for some packages but not for others.
This commit is contained in:
parent
0732a86a24
commit
ddc73ffa0c
@ -159,7 +159,10 @@ module Language
|
||||
# Find any Python bindings provided by recursive dependencies
|
||||
formula_deps = formula.recursive_dependencies
|
||||
pth_contents = formula_deps.map do |d|
|
||||
next if d.build?
|
||||
next if d.build? || d.test?
|
||||
# Do not add the main site-package provided by the brewed
|
||||
# Python formula, to keep the virtual-env's site-package pristine
|
||||
next if python_names.include? d.name
|
||||
|
||||
dep_site_packages = Formula[d.name].opt_prefix/Language::Python.site_packages(python)
|
||||
next unless dep_site_packages.exist?
|
||||
@ -196,8 +199,7 @@ module Language
|
||||
def virtualenv_install_with_resources(options = {})
|
||||
python = options[:using]
|
||||
if python.nil?
|
||||
pythons = %w[python python3 pypy pypy3] + Formula.names.select { |name| name.start_with? "python@" }
|
||||
wanted = pythons.select { |py| needs_python?(py) }
|
||||
wanted = python_names.select { |py| needs_python?(py) }
|
||||
raise FormulaUnknownPythonError, self if wanted.empty?
|
||||
raise FormulaAmbiguousPythonError, self if wanted.size > 1
|
||||
|
||||
@ -210,6 +212,10 @@ module Language
|
||||
venv
|
||||
end
|
||||
|
||||
def python_names
|
||||
%w[python python3 pypy pypy3] + Formula.names.select { |name| name.start_with? "python@" }
|
||||
end
|
||||
|
||||
# Convenience wrapper for creating and installing packages into Python
|
||||
# virtualenvs.
|
||||
class Virtualenv
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user