language/python: create venvs with access to system site packages

A user may wish to use two use two brew-installed Python packages
together. For example, one might want to `import numpy` when using
`jupyterlab` or `ptpython`.

Currently, the only ways to do this I'm aware of is with some hacking of
`PYTHONPATH` or the creation of `.pth` files in a formula's prefix.

A better solution is to allow the virtualenvs that `brew` creates to
have access to system site-packages by default, so that `import numpy`
inside `ptpython` or `jupyterlab` just works.

Partially resolves Homebrew/homebrew-core#76950.
This commit is contained in:
Carlo Cabrera 2021-06-28 03:20:03 +01:00
parent aa14e48f4e
commit 3d3b9874f9
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
2 changed files with 2 additions and 2 deletions

View File

@ -218,7 +218,7 @@ module Language
def create
return if (@venv_root/"bin/python").exist?
@formula.system @python, "-m", "venv", @venv_root
@formula.system @python, "-m", "venv", "--system-site-packages", @venv_root
# Robustify symlinks to survive python patch upgrades
@venv_root.find do |f|

View File

@ -15,7 +15,7 @@ describe Language::Python::Virtualenv::Virtualenv, :needs_python do
describe "#create" do
it "creates a venv" do
expect(formula).to receive(:system).with("python", "-m", "venv", dir)
expect(formula).to receive(:system).with("python", "-m", "venv", "--system-site-packages", dir)
virtualenv.create
end
end