diff --git a/Library/Homebrew/rubocops/urls.rb b/Library/Homebrew/rubocops/urls.rb index 7c339fb6b2..9158b8b2ca 100644 --- a/Library/Homebrew/rubocops/urls.rb +++ b/Library/Homebrew/rubocops/urls.rb @@ -292,16 +292,22 @@ module RuboCop # Check pypi urls pypi_pattern = %r{^https?://pypi.python.org/} - audit_urls(urls, pypi_pattern) do - problem "use the `files.pythonhosted.org` url found on the pypi downloads page" + audit_urls(urls, pypi_pattern) do |_, url| + problem "use the `Source` url found on PyPI downloads page (`#{get_pypi_url(url)}`)" end # Require long files.pythonhosted.org urls pythonhosted_pattern = %r{^https?://files.pythonhosted.org/packages/source/} - audit_urls(urls, pythonhosted_pattern) do - problem "use the url found on the pypi downloads page" + audit_urls(urls, pythonhosted_pattern) do |_, url| + problem "use the `Source` url found on PyPI downloads page (`#{get_pypi_url(url)}`)" end end + + def get_pypi_url(url) + package_file = File.basename(url) + package_name = package_file.match(/^(.+)-[a-z0-9.]+$/)[1] + "https://pypi.org/project/#{package_name}/#files" + end end end end diff --git a/Library/Homebrew/test/rubocops/urls_spec.rb b/Library/Homebrew/test/rubocops/urls_spec.rb index 477327f488..2d24b5735c 100644 --- a/Library/Homebrew/test/rubocops/urls_spec.rb +++ b/Library/Homebrew/test/rubocops/urls_spec.rb @@ -251,7 +251,7 @@ describe RuboCop::Cop::FormulaAudit::PyPiUrls do class Foo < Formula desc "foo" url "https://pypi.python.org/packages/source/foo/foo-0.1.tar.gz" - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use the `files.pythonhosted.org` url found on the pypi downloads page + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use the `Source` url found on PyPI downloads page (`https://pypi.org/project/foo/#files`) end RUBY end @@ -261,7 +261,7 @@ describe RuboCop::Cop::FormulaAudit::PyPiUrls do class Foo < Formula desc "foo" url "https://files.pythonhosted.org/packages/source/f/foo/foo-0.1.tar.gz" - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use the url found on the pypi downloads page + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use the `Source` url found on PyPI downloads page (`https://pypi.org/project/foo/#files`) end RUBY end