Use a regex instead of splitting the URL on / etc

This commit is contained in:
Issy Long 2023-09-12 00:30:21 +01:00
parent 08f58ab5f7
commit bf163013d9
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4

View File

@ -104,7 +104,8 @@ module Homebrew
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.
pypi_package_name = url.split("/").last.split(/[-.]\d+?./).first.gsub(/[_.]/, "-")
url =~ %r{/(?<package_name>[^/]+)-}
pypi_package_name = Regexp.last_match(:package_name).gsub(/[_.]/, "-")
return if name.casecmp(pypi_package_name).zero?
problem "resource name should be `#{pypi_package_name}` to match the PyPI package name"