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:
commit
c1f79499af
@ -106,6 +106,17 @@ module Homebrew
|
||||
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
|
||||
urls = [url] + mirrors
|
||||
|
||||
|
@ -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 match the PyPI package name")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#check_service_command" do
|
||||
specify "Not installed" do
|
||||
fa = formula_auditor "foo", <<~RUBY
|
||||
|
Loading…
x
Reference in New Issue
Block a user