Add link to pypi downloads page to problem message

This commit is contained in:
Rylan Polster 2020-07-18 14:22:05 -04:00
parent 5f3f7d010b
commit 70dfaf3b42
2 changed files with 12 additions and 6 deletions

View File

@ -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

View File

@ -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