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:
		
							parent
							
								
									de50e84184
								
							
						
					
					
						commit
						5d2ae98d0c
					
				@ -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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user