mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
language/python: optionally link manpages
This commit is contained in:
parent
b93a90f5af
commit
776d6b934d
@ -182,7 +182,7 @@ module Language
|
||||
# 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
|
||||
# default guess.
|
||||
def virtualenv_install_with_resources(using: nil, system_site_packages: true)
|
||||
def virtualenv_install_with_resources(using: nil, system_site_packages: true, link_manpages: false)
|
||||
python = using
|
||||
if python.nil?
|
||||
wanted = python_names.select { |py| needs_python?(py) }
|
||||
@ -194,7 +194,7 @@ module Language
|
||||
end
|
||||
venv = virtualenv_create(libexec, python.delete("@"), system_site_packages: system_site_packages)
|
||||
venv.pip_install resources
|
||||
venv.pip_install_and_link buildpath
|
||||
venv.pip_install_and_link(buildpath, link_manpages: link_manpages)
|
||||
venv
|
||||
end
|
||||
|
||||
@ -281,14 +281,22 @@ module Language
|
||||
#
|
||||
# @param (see #pip_install)
|
||||
# @return (see #pip_install)
|
||||
def pip_install_and_link(targets)
|
||||
def pip_install_and_link(targets, link_manpages: false)
|
||||
bin_before = Dir[@venv_root/"bin/*"].to_set
|
||||
man_before = Dir[@venv_root/"share/man/man*/*"].to_set if link_manpages
|
||||
|
||||
pip_install(targets)
|
||||
|
||||
bin_after = Dir[@venv_root/"bin/*"].to_set
|
||||
bin_to_link = (bin_after - bin_before).to_a
|
||||
@formula.bin.install_symlink(bin_to_link)
|
||||
return unless link_manpages
|
||||
|
||||
man_after = Dir[@venv_root/"share/man/man*/*"].to_set
|
||||
man_to_link = (man_after - man_before).to_a
|
||||
man_to_link.each do |manpage|
|
||||
(@formula.man/Pathname.new(manpage).dirname.basename).install_symlink manpage
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -11,7 +11,8 @@ describe Language::Python::Virtualenv::Virtualenv, :needs_python do
|
||||
|
||||
let(:resource) { double("resource", stage: true) }
|
||||
let(:formula_bin) { dir/"formula_bin" }
|
||||
let(:formula) { double("formula", resource: resource, bin: formula_bin) }
|
||||
let(:formula_man) { dir/"formula_man" }
|
||||
let(:formula) { double("formula", resource: resource, bin: formula_bin, man: formula_man) }
|
||||
|
||||
describe "#create" do
|
||||
it "creates a venv" do
|
||||
@ -70,7 +71,9 @@ describe Language::Python::Virtualenv::Virtualenv, :needs_python do
|
||||
|
||||
describe "#pip_install_and_link" do
|
||||
let(:src_bin) { dir/"bin" }
|
||||
let(:src_man) { dir/"share/man" }
|
||||
let(:dest_bin) { formula.bin }
|
||||
let(:dest_man) { formula.man }
|
||||
|
||||
it "can link scripts" do
|
||||
src_bin.mkpath
|
||||
@ -94,5 +97,39 @@ describe Language::Python::Virtualenv::Virtualenv, :needs_python do
|
||||
expect((src_bin/"kilroy").realpath).to eq((dest_bin/"kilroy").realpath)
|
||||
expect(dest_bin/"irrelevant").not_to exist
|
||||
end
|
||||
|
||||
it "can link manpages" do
|
||||
(src_man/"man1").mkpath
|
||||
(src_man/"man3").mkpath
|
||||
|
||||
expect(src_man/"man1/kilroy.1").not_to exist
|
||||
expect(dest_man/"man1").not_to exist
|
||||
expect(dest_man/"man3").not_to exist
|
||||
expect(dest_man/"man5").not_to exist
|
||||
|
||||
FileUtils.touch src_man/"man1/irrelevant.1"
|
||||
FileUtils.touch src_man/"man3/irrelevant.3"
|
||||
man_before = Dir.glob(src_man/"**/*")
|
||||
(src_man/"man5").mkpath
|
||||
FileUtils.touch src_man/"man1/kilroy.1"
|
||||
FileUtils.touch src_man/"man5/kilroy.5"
|
||||
man_after = Dir.glob(src_man/"**/*")
|
||||
|
||||
expect(virtualenv).to receive(:pip_install).with("foo")
|
||||
expect(Dir).to receive(:[]).with(src_bin/"*").and_return([])
|
||||
expect(Dir).to receive(:[]).with(src_man/"man*/*").and_return(man_before)
|
||||
expect(Dir).to receive(:[]).with(src_bin/"*").and_return([])
|
||||
expect(Dir).to receive(:[]).with(src_man/"man*/*").and_return(man_after)
|
||||
|
||||
virtualenv.pip_install_and_link("foo", link_manpages: true)
|
||||
|
||||
expect(src_man/"man1/kilroy.1").to exist
|
||||
expect(dest_man/"man1/kilroy.1").to exist
|
||||
expect(dest_man/"man5/kilroy.5").to exist
|
||||
expect(dest_man/"man1/kilroy.1").to be_a_symlink
|
||||
expect((src_man/"man1/kilroy.1").realpath).to eq((dest_man/"man1/kilroy.1").realpath)
|
||||
expect(dest_man/"man1/irrelevant.1").not_to exist
|
||||
expect(dest_man/"man3").not_to exist
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user