Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils/pypi: carry over non-PyPI resources #16758

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 23 additions & 14 deletions Library/Homebrew/utils/pypi.rb
Expand Up @@ -76,13 +76,14 @@
return
end

info = json["info"]
return if info.nil?

sdist = json["urls"].find { |url| url["packagetype"] == "sdist" }
return if sdist.nil?
url = sdist["url"] unless sdist.nil?
sha256 = sdist["digests"]["sha256"] unless sdist.nil?

@pypi_info = [
PyPI.normalize_python_package(json["info"]["name"]), sdist["url"],
sdist["digests"]["sha256"], json["info"]["version"]
]
@pypi_info = [PyPI.normalize_python_package(info["name"]), url, sha256, info["version"]]
end

sig { returns(String) }
Expand Down Expand Up @@ -286,11 +287,7 @@
input_packages << extra_package unless input_packages.include? extra_package
end

formula.resources.each do |resource|
if !print_only && !resource.url.start_with?(PYTHONHOSTED_URL_PREFIX)
odie "\"#{formula.name}\" contains non-PyPI resources. Please update the resources manually."
end
end
non_pypi_resources = formula.resources.reject { |resource| resource.url.start_with?(PYTHONHOSTED_URL_PREFIX) }

Check warning on line 290 in Library/Homebrew/utils/pypi.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L290

Added line #L290 was not covered by tests

ensure_formula_installed!(python_name)

Expand Down Expand Up @@ -318,10 +315,17 @@
if name.blank?
odie "Unable to resolve some dependencies. Please update the resources for \"#{formula.name}\" manually."
elsif url.blank? || checksum.blank?
odie <<~EOS
Unable to find the URL and/or sha256 for the "#{name}" resource.
Please update the resources for "#{formula.name}" manually.
EOS
existing_resource = formula.resource(name)
if existing_resource.present? && existing_resource.version == package.version

Check warning on line 319 in Library/Homebrew/utils/pypi.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L319

Added line #L319 was not covered by tests
non_pypi_resources.delete existing_resource
Comment on lines +319 to +320
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO:

  • Try to piggy back on some formula bump logic to allow replacing version in URL.
  • non_pypi_resources.delete on situation where a non-PyPI resource is now sdist on PyPI

url = existing_resource.url
checksum = existing_resource.checksum

Check warning on line 322 in Library/Homebrew/utils/pypi.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/pypi.rb#L321-L322

Added lines #L321 - L322 were not covered by tests
else
odie <<~EOS
Unable to find the URL and/or sha256 for the "#{name}" resource.
Please update the resources for "#{formula.name}" manually.
EOS
end
end

# Append indented resource block
Expand All @@ -339,6 +343,11 @@
if print_only
puts new_resource_blocks.chomp
return
elsif non_pypi_resources.present?
odie <<~EOS
"#{formula.name}" contains non-PyPI resources: #{non_pypi_resources.map(&:name).join(", ")}.
Please update the resources manually.
EOS
end

# Check whether resources already exist (excluding virtualenv dependencies)
Expand Down