From 3d3b9874f93e30b75d2d1595cb207cd7f03169b9 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 28 Jun 2021 03:20:03 +0100 Subject: [PATCH] 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. --- Library/Homebrew/language/python.rb | 2 +- Library/Homebrew/test/language/python/virtualenv_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/language/python.rb b/Library/Homebrew/language/python.rb index 8292e4c967..3026ca3d95 100644 --- a/Library/Homebrew/language/python.rb +++ b/Library/Homebrew/language/python.rb @@ -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| diff --git a/Library/Homebrew/test/language/python/virtualenv_spec.rb b/Library/Homebrew/test/language/python/virtualenv_spec.rb index 07ab7bcf35..04a465efa6 100644 --- a/Library/Homebrew/test/language/python/virtualenv_spec.rb +++ b/Library/Homebrew/test/language/python/virtualenv_spec.rb @@ -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