Merge pull request #15942 from issyl0/audit-pypi-package-names-match-resource-names

Add an audit for mismatched Python resource and PyPi package names
This commit is contained in:
Mike McQuaid 2023-09-13 09:32:09 +01:00 committed by GitHub
commit c1f79499af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -106,6 +106,17 @@ module Homebrew
end end
end end
def audit_resource_name_matches_pypi_package_name_in_url
return unless url.match?(%r{^https?://files\.pythonhosted\.org/packages/})
return if name == owner.name # Skip the top-level package name as we only care about `resource "foo"` blocks.
url =~ %r{/(?<package_name>[^/]+)-}
pypi_package_name = Regexp.last_match(:package_name).to_s.gsub(/[_.]/, "-")
return if name.casecmp(pypi_package_name).zero?
problem "resource name should be `#{pypi_package_name}` to match the PyPI package name"
end
def audit_urls def audit_urls
urls = [url] + mirrors urls = [url] + mirrors

View File

@ -522,6 +522,27 @@ module Homebrew
end end
end end
describe "#audit_resource_name_matches_pypi_package_name_in_url" do
it "reports a problem if the resource name does not match the python package name" do
fa = formula_auditor "foo", <<~RUBY
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
sha256 "abc123"
homepage "https://brew.sh"
resource "Something" do
url "https://files.pythonhosted.org/packages/FooSomething-1.0.0.tar.gz"
sha256 "def456"
end
end
RUBY
fa.audit_specs
expect(fa.problems.first[:message])
.to match("resource name should be `FooSomething` to match the PyPI package name")
end
end
describe "#check_service_command" do describe "#check_service_command" do
specify "Not installed" do specify "Not installed" do
fa = formula_auditor "foo", <<~RUBY fa = formula_auditor "foo", <<~RUBY