
This is particularly useful for third-party Python formulae that have a ton of resources, not all of which may adhere to homebrew/core's strict policies. See #19240 for context. I've also added logic that ignores `--ignore-errors` on `homebrew/core`, although I personally think this new behavior is also useful for mainline formula creation. Before: error out on a single non-conforming resource, zero resource blocks added to formula, scary stacktrace. After: all conforming resources added, all non-conforming resources identified in comments, error message at end, `brew` exits non-zero without scary stacktrace:- ``` % brew update-python-resources --ignore-errors gromgit/test/auto-coder || echo OOPS ==> Retrieving PyPI dependencies for "auto-coder==0.1.243"... ==> Retrieving PyPI dependencies for excluded ""... ==> Getting PyPI info for "aiohappyeyeballs==2.4.4" [200+ resource lines elided] ==> Getting PyPI info for "zhipuai==2.1.5.20250106" ==> Updating resource blocks Error: Unable to resolve some dependencies. Please check /opt/homebrew/Library/Taps/gromgit/homebrew-test/Formula/auto-coder.rb for RESOURCE-ERROR comments. OOPS % brew cat gromgit/test/auto-coder | ggrep -C10 RESOURCE-ERROR license "Apache-2.0" depends_on "python@3.11" # Additional dependency # resource "" do # url "" # sha256 "" # end # RESOURCE-ERROR: Unable to resolve "azure-cognitiveservices-speech==1.42.0" (no suitable source distribution on PyPI) # RESOURCE-ERROR: Unable to resolve "ray==2.42.0" (no suitable source distribution on PyPI) resource "aiohappyeyeballs" do url "e4373e888f/aiohappyeyeballs-2.4.4.tar.gz
" sha256 "5fdd7d87889c63183afc18ce9271f9b0a7d32c2303e394468dd45d514a757745" end resource "aiohttp" do url "952d49c730/aiohttp-3.11.12.tar.gz
" sha256 "7603ca26d75b1b86160ce1bbe2787a0b706e592af5b2504e12caa88a217767b0" end ```
63 lines
2.4 KiB
Ruby
63 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "tapioca/dsl"
|
|
require "sorbet/tapioca/compilers/args"
|
|
|
|
RSpec.describe Tapioca::Compilers::Args do
|
|
let(:compiler) { described_class.new(Tapioca::Dsl::Pipeline.new(requested_constants: []), RBI::Tree.new, Homebrew) }
|
|
let(:list_parser) do
|
|
require "cmd/list"
|
|
Homebrew::Cmd::List.parser
|
|
end
|
|
|
|
# Good testing candidate because it has multiple for each of `switch`, `flag` and `comma_array` args:
|
|
let(:update_python_resources_parser) do
|
|
require "dev-cmd/update-python-resources"
|
|
Homebrew::DevCmd::UpdatePythonResources.parser
|
|
end
|
|
|
|
describe "#args_table" do
|
|
it "returns a mapping of list args to default values" do
|
|
expect(compiler.args_table(list_parser)).to contain_exactly(
|
|
:"1?", :built_from_source?, :cask?, :casks?, :d?, :debug?, :formula?, :formulae?, :full_name?, :h?, :help?,
|
|
:installed_as_dependency?, :installed_on_request?, :l?, :multiple?, :pinned?, :poured_from_bottle?, :q?,
|
|
:quiet?, :r?, :t?, :v?, :verbose?, :versions?
|
|
)
|
|
end
|
|
|
|
it "returns a mapping of update-python-resources args to default values" do
|
|
expect(compiler.args_table(update_python_resources_parser)).to contain_exactly(
|
|
:d?, :debug?, :exclude_packages, :extra_packages, :h?, :help?, :ignore_errors?, :ignore_non_pypi_packages?,
|
|
:install_dependencies?, :p?, :package_name, :print_only?, :q?, :quiet?, :s?, :silent?, :v?, :verbose?,
|
|
:version
|
|
)
|
|
end
|
|
end
|
|
|
|
describe "#comma_arrays" do
|
|
it "returns an empty list when there are no comma_array args" do
|
|
expect(compiler.comma_arrays(list_parser)).to eq([])
|
|
end
|
|
|
|
it "returns the comma_array args when they exist" do
|
|
expect(compiler.comma_arrays(update_python_resources_parser)).to eq([:extra_packages, :exclude_packages])
|
|
end
|
|
end
|
|
|
|
describe "#get_return_type" do
|
|
let(:comma_arrays) { compiler.comma_arrays(update_python_resources_parser) }
|
|
|
|
it "returns the correct type for switches" do
|
|
expect(compiler.get_return_type(:silent?, comma_arrays)).to eq("T::Boolean")
|
|
end
|
|
|
|
it "returns the correct type for flags" do
|
|
expect(compiler.get_return_type(:package_name, comma_arrays)).to eq("T.nilable(String)")
|
|
end
|
|
|
|
it "returns the correct type for comma_arrays" do
|
|
expect(compiler.get_return_type(:extra_packages, comma_arrays)).to eq("T.nilable(T::Array[String])")
|
|
end
|
|
end
|
|
end
|