Add an audit for mismatched Python resource and PyPi package names

- Issue 14537.
- When people manually add or modify PyPI resources the `Resource#name`
  sometimes ends up out-of-sync with the PyPI package name.
This commit is contained in:
Issy Long 2023-09-03 00:18:15 +01:00
parent de50e84184
commit 5d2ae98d0c
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
2 changed files with 30 additions and 0 deletions

View File

@ -100,6 +100,15 @@ module Homebrew
end
end
def audit_resource_name_matches_pypi_package_name_in_url
return unless url.match?(%r{^https?://files\.pythonhosted\.org/packages/})
pypi_package_name = url.split("/").last.split(/-\d+\.\d+./).first.tr("_", "-")
return if name.casecmp(pypi_package_name).zero?
problem "resource name should be `#{pypi_package_name}` to closer match the PyPI package name"
end
def audit_urls
urls = [url] + mirrors

View File

@ -522,6 +522,27 @@ module Homebrew
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 closer match the PyPI package name")
end
end
describe "#check_service_command" do
specify "Not installed" do
fa = formula_auditor "foo", <<~RUBY