Class: PyPI::Package Private
- Includes:
- Utils::Output::Mixin
- Defined in:
- utils/pypi.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Represents a Python package. This package can be a PyPI package (either by name/version or PyPI distribution URL), or it can be a non-PyPI URL.
Instance Attribute Summary collapse
-
#python_name ⇒ void
writeonly
private
The Python formula used to resolve package metadata.
Instance Method Summary collapse
- #extras ⇒ Array<String>? private
- #initialize(package_string, is_url: false, python_name: "python", resource: nil) ⇒ void constructor private
- #name ⇒ String? private
-
#pypi_info(new_version: nil, ignore_errors: false) ⇒ Array<String>?
private
Get name, URL, SHA-256 checksum and latest version for a given package.
-
#requirement ⇒ String, Resource
private
The source resource or package requirement to inspect with pip.
- #same_package?(other) ⇒ Boolean private
- #valid_pypi_package? ⇒ Boolean private
- #version ⇒ String? private
- #version=(new_version) ⇒ void private
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
#initialize(package_string, is_url: false, python_name: "python", resource: nil) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
30 31 32 33 34 35 36 37 |
# File 'utils/pypi.rb', line 30 def initialize(package_string, is_url: false, python_name: "python", resource: nil) @pypi_info = T.let(nil, T.nilable(T::Array[String])) @package_string = package_string @is_url = is_url @is_pypi_url = T.let(package_string.start_with?(PYTHONHOSTED_URL_PREFIX), T::Boolean) @python_name = python_name @resource = resource end |
Instance Attribute Details
#python_name=(value) ⇒ void (writeonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
The Python formula used to resolve package metadata.
27 28 29 |
# File 'utils/pypi.rb', line 27 def python_name=(value) @python_name = value end |
Instance Method Details
#extras ⇒ Array<String>?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
46 47 48 49 |
# File 'utils/pypi.rb', line 46 def extras if @extras.blank? @extras end |
#name ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
40 41 42 43 |
# File 'utils/pypi.rb', line 40 def name if @name.blank? @name end |
#pypi_info(new_version: nil, ignore_errors: false) ⇒ Array<String>?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Get name, URL, SHA-256 checksum and latest version for a given package.
This only works for packages from PyPI or from a PyPI URL; packages
derived from non-PyPI URLs will produce nil here.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'utils/pypi.rb', line 76 def pypi_info(new_version: nil, ignore_errors: false) return unless valid_pypi_package? return @pypi_info if @pypi_info.present? && new_version.blank? new_version ||= version = if new_version.present? "https://pypi.org/pypi/#{name}/#{new_version}/json" else "https://pypi.org/pypi/#{name}/json" end result = Utils::Curl.curl_output(, "--location", "--fail") return unless result.status.success? begin json = JSON.parse(result.stdout) rescue JSON::ParserError return end dist = json["urls"].find do |url| url["packagetype"] == "sdist" end # If there isn't an sdist, we use the first pure Python3 or universal wheel if dist.nil? dist = json["urls"].find do |url| url["filename"].match?("[.-]py3[^-]*-none-any.whl$") end end if dist.nil? return ["", "", "", "", "no suitable source distribution on PyPI"] if ignore_errors onoe "#{name} exists on PyPI but lacks a suitable source distribution" return end @pypi_info = [ PyPI.normalize_python_package(json["info"]["name"]), dist["url"], dist["digests"]["sha256"], json["info"]["version"] ] end |
#requirement ⇒ String, Resource
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
The source resource or package requirement to inspect with pip.
135 136 137 138 139 |
# File 'utils/pypi.rb', line 135 def requirement return to_s if valid_pypi_package? @resource || @package_string end |
#same_package?(other) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
142 143 144 145 |
# File 'utils/pypi.rb', line 142 def same_package?(other) # These names are pre-normalized, so we can compare them directly. name == other.name end |
#valid_pypi_package? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
65 66 67 |
# File 'utils/pypi.rb', line 65 def valid_pypi_package? @is_pypi_url || !@is_url end |
#version ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
52 53 54 55 |
# File 'utils/pypi.rb', line 52 def version if @version.blank? @version end |
#version=(new_version) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
58 59 60 61 62 |
# File 'utils/pypi.rb', line 58 def version=(new_version) raise ArgumentError, "can't update version for non-PyPI packages" unless valid_pypi_package? @version = T.let(new_version, T.nilable(String)) end |