mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
python: create venv's --without-pip
This commit is contained in:
parent
c531a35ae7
commit
98323cd7e6
@ -134,10 +134,12 @@ module Language
|
|||||||
# or "python3.x")
|
# or "python3.x")
|
||||||
# @param formula [Formula] the active {Formula}
|
# @param formula [Formula] the active {Formula}
|
||||||
# @return [Virtualenv] a {Virtualenv} instance
|
# @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
|
ENV.refurbish_args
|
||||||
venv = Virtualenv.new formula, venv_root, python
|
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
|
# Find any Python bindings provided by recursive dependencies
|
||||||
formula_deps = formula.recursive_dependencies
|
formula_deps = formula.recursive_dependencies
|
||||||
@ -180,7 +182,8 @@ module Language
|
|||||||
# formula preference for python or python@x.y, or to resolve an ambiguous
|
# formula preference for python or python@x.y, or to resolve an ambiguous
|
||||||
# case where it's not clear whether python or python@x.y should be the
|
# case where it's not clear whether python or python@x.y should be the
|
||||||
# default guess.
|
# 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
|
python = using
|
||||||
if python.nil?
|
if python.nil?
|
||||||
wanted = python_names.select { |py| needs_python?(py) }
|
wanted = python_names.select { |py| needs_python?(py) }
|
||||||
@ -190,7 +193,8 @@ module Language
|
|||||||
python = wanted.first
|
python = wanted.first
|
||||||
python = "python3" if python == "python"
|
python = "python3" if python == "python"
|
||||||
end
|
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 resources
|
||||||
venv.pip_install_and_link(buildpath, link_manpages: link_manpages)
|
venv.pip_install_and_link(buildpath, link_manpages: link_manpages)
|
||||||
venv
|
venv
|
||||||
@ -221,11 +225,12 @@ module Language
|
|||||||
# Obtains a copy of the virtualenv library and creates a new virtualenv on disk.
|
# Obtains a copy of the virtualenv library and creates a new virtualenv on disk.
|
||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def create(system_site_packages: true)
|
def create(system_site_packages: true, without_pip: true)
|
||||||
return if (@venv_root/"bin/python").exist?
|
return if (@venv_root/"bin/python").exist?
|
||||||
|
|
||||||
args = ["-m", "venv"]
|
args = ["-m", "venv"]
|
||||||
args << "--system-site-packages" if system_site_packages
|
args << "--system-site-packages" if system_site_packages
|
||||||
|
args << "--without-pip" if without_pip
|
||||||
@formula.system @python, *args, @venv_root
|
@formula.system @python, *args, @venv_root
|
||||||
|
|
||||||
# Robustify symlinks to survive python patch upgrades
|
# Robustify symlinks to survive python patch upgrades
|
||||||
@ -250,6 +255,9 @@ module Language
|
|||||||
prefix_path.sub! %r{^#{HOMEBREW_CELLAR}/python#{version}/[^/]+}, Formula["python#{version}"].opt_prefix
|
prefix_path.sub! %r{^#{HOMEBREW_CELLAR}/python#{version}/[^/]+}, Formula["python#{version}"].opt_prefix
|
||||||
prefix_file.atomic_write prefix_path
|
prefix_file.atomic_write prefix_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Remove unnecessary activate scripts
|
||||||
|
(@venv_root/"bin").glob("[Aa]ctivate*").map(&:unlink)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Installs packages represented by `targets` into the virtualenv.
|
# Installs packages represented by `targets` into the virtualenv.
|
||||||
@ -302,7 +310,7 @@ module Language
|
|||||||
def do_install(targets, build_isolation: true)
|
def do_install(targets, build_isolation: true)
|
||||||
targets = Array(targets)
|
targets = Array(targets)
|
||||||
args = @formula.std_pip_args(prefix: false, build_isolation: build_isolation)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,9 +15,14 @@ describe Language::Python::Virtualenv::Virtualenv, :needs_python do
|
|||||||
|
|
||||||
describe "#create" do
|
describe "#create" do
|
||||||
it "creates a venv" do
|
it "creates a venv" do
|
||||||
expect(formula).to receive(:system).with("python", "-m", "venv", "--system-site-packages", dir)
|
expect(formula).to receive(:system).with("python", "-m", "venv", "--system-site-packages", "--without-pip", dir)
|
||||||
virtualenv.create
|
virtualenv.create
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "creates a venv with pip" do
|
||||||
|
expect(formula).to receive(:system).with("python", "-m", "venv", "--system-site-packages", dir)
|
||||||
|
virtualenv.create(without_pip: false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#pip_install" do
|
describe "#pip_install" do
|
||||||
@ -25,7 +30,7 @@ describe Language::Python::Virtualenv::Virtualenv, :needs_python do
|
|||||||
expect(formula).to receive(:std_pip_args).with(prefix: false,
|
expect(formula).to receive(:std_pip_args).with(prefix: false,
|
||||||
build_isolation: true).and_return(["--std-pip-args"])
|
build_isolation: true).and_return(["--std-pip-args"])
|
||||||
expect(formula).to receive(:system)
|
expect(formula).to receive(:system)
|
||||||
.with(dir/"bin/pip", "install", "--std-pip-args", "foo")
|
.with("python", "-m", "pip", "--python=#{dir}/bin/python", "install", "--std-pip-args", "foo")
|
||||||
.and_return(true)
|
.and_return(true)
|
||||||
virtualenv.pip_install "foo"
|
virtualenv.pip_install "foo"
|
||||||
end
|
end
|
||||||
@ -34,7 +39,7 @@ describe Language::Python::Virtualenv::Virtualenv, :needs_python do
|
|||||||
expect(formula).to receive(:std_pip_args).with(prefix: false,
|
expect(formula).to receive(:std_pip_args).with(prefix: false,
|
||||||
build_isolation: true).and_return(["--std-pip-args"])
|
build_isolation: true).and_return(["--std-pip-args"])
|
||||||
expect(formula).to receive(:system)
|
expect(formula).to receive(:system)
|
||||||
.with(dir/"bin/pip", "install", "--std-pip-args", "foo", "bar")
|
.with("python", "-m", "pip", "--python=#{dir}/bin/python", "install", "--std-pip-args", "foo", "bar")
|
||||||
.and_return(true)
|
.and_return(true)
|
||||||
|
|
||||||
virtualenv.pip_install <<~EOS
|
virtualenv.pip_install <<~EOS
|
||||||
@ -47,13 +52,13 @@ describe Language::Python::Virtualenv::Virtualenv, :needs_python do
|
|||||||
expect(formula).to receive(:std_pip_args).with(prefix: false,
|
expect(formula).to receive(:std_pip_args).with(prefix: false,
|
||||||
build_isolation: true).and_return(["--std-pip-args"])
|
build_isolation: true).and_return(["--std-pip-args"])
|
||||||
expect(formula).to receive(:system)
|
expect(formula).to receive(:system)
|
||||||
.with(dir/"bin/pip", "install", "--std-pip-args", "foo")
|
.with("python", "-m", "pip", "--python=#{dir}/bin/python", "install", "--std-pip-args", "foo")
|
||||||
.and_return(true)
|
.and_return(true)
|
||||||
|
|
||||||
expect(formula).to receive(:std_pip_args).with(prefix: false,
|
expect(formula).to receive(:std_pip_args).with(prefix: false,
|
||||||
build_isolation: true).and_return(["--std-pip-args"])
|
build_isolation: true).and_return(["--std-pip-args"])
|
||||||
expect(formula).to receive(:system)
|
expect(formula).to receive(:system)
|
||||||
.with(dir/"bin/pip", "install", "--std-pip-args", "bar")
|
.with("python", "-m", "pip", "--python=#{dir}/bin/python", "install", "--std-pip-args", "bar")
|
||||||
.and_return(true)
|
.and_return(true)
|
||||||
|
|
||||||
virtualenv.pip_install ["foo", "bar"]
|
virtualenv.pip_install ["foo", "bar"]
|
||||||
@ -66,7 +71,7 @@ describe Language::Python::Virtualenv::Virtualenv, :needs_python do
|
|||||||
expect(formula).to receive(:std_pip_args).with(prefix: false,
|
expect(formula).to receive(:std_pip_args).with(prefix: false,
|
||||||
build_isolation: true).and_return(["--std-pip-args"])
|
build_isolation: true).and_return(["--std-pip-args"])
|
||||||
expect(formula).to receive(:system)
|
expect(formula).to receive(:system)
|
||||||
.with(dir/"bin/pip", "install", "--std-pip-args", Pathname.pwd)
|
.with("python", "-m", "pip", "--python=#{dir}/bin/python", "install", "--std-pip-args", Pathname.pwd)
|
||||||
.and_return(true)
|
.and_return(true)
|
||||||
|
|
||||||
virtualenv.pip_install res
|
virtualenv.pip_install res
|
||||||
@ -76,7 +81,7 @@ describe Language::Python::Virtualenv::Virtualenv, :needs_python do
|
|||||||
expect(formula).to receive(:std_pip_args).with(prefix: false,
|
expect(formula).to receive(:std_pip_args).with(prefix: false,
|
||||||
build_isolation: false).and_return(["--std-pip-args"])
|
build_isolation: false).and_return(["--std-pip-args"])
|
||||||
expect(formula).to receive(:system)
|
expect(formula).to receive(:system)
|
||||||
.with(dir/"bin/pip", "install", "--std-pip-args", "foo")
|
.with("python", "-m", "pip", "--python=#{dir}/bin/python", "install", "--std-pip-args", "foo")
|
||||||
.and_return(true)
|
.and_return(true)
|
||||||
virtualenv.pip_install("foo", build_isolation: false)
|
virtualenv.pip_install("foo", build_isolation: false)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user