Merge pull request #13690 from carlocab/python-path-shebang
language/python: support `python3` from PATH in `#detected_python_shebang`
This commit is contained in:
commit
5047d4249e
@ -103,7 +103,10 @@ module Language
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def detected_python_shebang(formula = self)
|
def detected_python_shebang(formula = self, use_python_from_path: false)
|
||||||
|
python_path = if use_python_from_path
|
||||||
|
"/usr/bin/env python3"
|
||||||
|
else
|
||||||
python_deps = formula.deps.map(&:name).grep(/^python(@.*)?$/)
|
python_deps = formula.deps.map(&:name).grep(/^python(@.*)?$/)
|
||||||
|
|
||||||
raise ShebangDetectionError.new("Python", "formula does not depend on Python") if python_deps.empty?
|
raise ShebangDetectionError.new("Python", "formula does not depend on Python") if python_deps.empty?
|
||||||
@ -112,7 +115,10 @@ module Language
|
|||||||
end
|
end
|
||||||
|
|
||||||
python_dep = python_deps.first
|
python_dep = python_deps.first
|
||||||
python_shebang_rewrite_info(Formula[python_dep].opt_bin/python_dep.sub("@", ""))
|
Formula[python_dep].opt_bin/python_dep.sub("@", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
python_shebang_rewrite_info(python_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ describe Language::Python::Shebang do
|
|||||||
|
|
||||||
before do
|
before do
|
||||||
file.write <<~EOS
|
file.write <<~EOS
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/python2
|
||||||
a
|
a
|
||||||
b
|
b
|
||||||
c
|
c
|
||||||
@ -34,7 +34,7 @@ describe Language::Python::Shebang do
|
|||||||
describe "#detected_python_shebang" do
|
describe "#detected_python_shebang" do
|
||||||
it "can be used to replace Python shebangs" do
|
it "can be used to replace Python shebangs" do
|
||||||
expect(Formulary).to receive(:factory).with(python_f.name).and_return(python_f)
|
expect(Formulary).to receive(:factory).with(python_f.name).and_return(python_f)
|
||||||
Utils::Shebang.rewrite_shebang described_class.detected_python_shebang(f), file
|
Utils::Shebang.rewrite_shebang described_class.detected_python_shebang(f, use_python_from_path: false), file
|
||||||
|
|
||||||
expect(File.read(file)).to eq <<~EOS
|
expect(File.read(file)).to eq <<~EOS
|
||||||
#!#{HOMEBREW_PREFIX}/opt/python@3.11/bin/python3.11
|
#!#{HOMEBREW_PREFIX}/opt/python@3.11/bin/python3.11
|
||||||
@ -43,5 +43,16 @@ describe Language::Python::Shebang do
|
|||||||
c
|
c
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can be pointed to a `python3` in PATH" do
|
||||||
|
Utils::Shebang.rewrite_shebang described_class.detected_python_shebang(f, use_python_from_path: true), file
|
||||||
|
|
||||||
|
expect(File.read(file)).to eq <<~EOS
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
EOS
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user