Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5248,6 +5248,17 @@ def link_overwrite(*paths)
paths.flatten!
T.must(link_overwrite_paths).merge(paths)
end

# Returns the major.minor {Version} for the given Python executable,
# as a shorthand for `Language::Python.major_minor_version` in the formula DSL.
#
# @param python [String, Pathname] the Python executable (e.g. `"python3"`)
# @return [Version, nil] the major.minor version, or `nil` when the version cannot be determined
# @api public
sig { params(python: T.any(String, Pathname)).returns(T.nilable(Version)) }
def python_major_minor_version(python)
Language::Python.major_minor_version(python)
end
end
end

Expand Down
9 changes: 9 additions & 0 deletions Library/Homebrew/test/formula_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@
end
end

describe ".python_major_minor_version" do
it "delegates to Language::Python.major_minor_version" do
version = instance_double(Version, "version")
expect(Language::Python).to receive(:major_minor_version).with("python3").and_return(version)

expect(described_class.python_major_minor_version("python3")).to be(version)
end
end

describe "#versioned_formulae" do
let(:f) do
formula "foo" do
Expand Down
Loading