-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15792 from branchvincent/venv-no-pip
python: create venv's `--without-pip`
- Loading branch information
Showing
2 changed files
with
26 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,10 +134,12 @@ module Virtualenv | |
# or "python3.x") | ||
# @param formula [Formula] the active {Formula} | ||
# @return [Virtualenv] a {Virtualenv} instance | ||
def virtualenv_create(venv_root, python = "python", formula = self, system_site_packages: true) | ||
def virtualenv_create(venv_root, python = "python", formula = self, system_site_packages: true, | ||
without_pip: true) | ||
# odeprecated "Language::Python::Virtualenv.virtualenv_create's without_pip" unless without_pip | ||
ENV.refurbish_args | ||
venv = Virtualenv.new formula, venv_root, python | ||
venv.create(system_site_packages: system_site_packages) | ||
venv.create(system_site_packages: system_site_packages, without_pip: without_pip) | ||
|
||
# Find any Python bindings provided by recursive dependencies | ||
formula_deps = formula.recursive_dependencies | ||
|
@@ -180,7 +182,8 @@ def needs_python?(python) | |
# formula preference for python or [email protected], or to resolve an ambiguous | ||
# case where it's not clear whether python or [email protected] should be the | ||
# default guess. | ||
def virtualenv_install_with_resources(using: nil, system_site_packages: true, link_manpages: false) | ||
def virtualenv_install_with_resources(using: nil, system_site_packages: true, without_pip: true, | ||
link_manpages: false) | ||
python = using | ||
if python.nil? | ||
wanted = python_names.select { |py| needs_python?(py) } | ||
|
@@ -190,7 +193,8 @@ def virtualenv_install_with_resources(using: nil, system_site_packages: true, li | |
python = wanted.first | ||
python = "python3" if python == "python" | ||
end | ||
venv = virtualenv_create(libexec, python.delete("@"), system_site_packages: system_site_packages) | ||
venv = virtualenv_create(libexec, python.delete("@"), system_site_packages: system_site_packages, | ||
without_pip: without_pip) | ||
venv.pip_install resources | ||
venv.pip_install_and_link(buildpath, link_manpages: link_manpages) | ||
venv | ||
|
@@ -221,11 +225,12 @@ def initialize(formula, venv_root, python) | |
# Obtains a copy of the virtualenv library and creates a new virtualenv on disk. | ||
# | ||
# @return [void] | ||
def create(system_site_packages: true) | ||
def create(system_site_packages: true, without_pip: true) | ||
return if (@venv_root/"bin/python").exist? | ||
|
||
args = ["-m", "venv"] | ||
args << "--system-site-packages" if system_site_packages | ||
args << "--without-pip" if without_pip | ||
@formula.system @python, *args, @venv_root | ||
|
||
# Robustify symlinks to survive python patch upgrades | ||
|
@@ -250,6 +255,9 @@ def create(system_site_packages: true) | |
prefix_path.sub! %r{^#{HOMEBREW_CELLAR}/python#{version}/[^/]+}, Formula["python#{version}"].opt_prefix | ||
prefix_file.atomic_write prefix_path | ||
end | ||
|
||
# Remove unnecessary activate scripts | ||
(@venv_root/"bin").glob("[Aa]ctivate*").map(&:unlink) | ||
end | ||
|
||
# Installs packages represented by `targets` into the virtualenv. | ||
|
@@ -302,7 +310,7 @@ def pip_install_and_link(targets, link_manpages: false, build_isolation: true) | |
def do_install(targets, build_isolation: true) | ||
targets = Array(targets) | ||
args = @formula.std_pip_args(prefix: false, build_isolation: build_isolation) | ||
@formula.system @venv_root/"bin/pip", "install", *args, *targets | ||
@formula.system @python, "-m", "pip", "--python=#{@venv_root}/bin/python", "install", *args, *targets | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters