Class: PyPI::Package Private
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.
PyPI Package
Instance Attribute Summary collapse
-
#extras ⇒ Object
private
-
#name ⇒ Object
private
-
#version ⇒ Object
private
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
private
-
#==(other) ⇒ Boolean
(also: #eql?)
private
Compare only names so we can use .include? and .uniq on a Package array.
-
#hash ⇒ Integer
private
-
#initialize(package_string, is_url: false) ⇒ void
constructor
private
-
#pypi_info(version: nil) ⇒ Array<String>?
private
Get name, URL, SHA-256 checksum, and latest version for a given PyPI package.
-
#same_package?(other) ⇒ Boolean
private
-
#to_s ⇒ String
private
-
#valid_pypi_package? ⇒ Boolean
private
Constructor Details
#initialize(package_string, is_url: false) ⇒ 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.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'utils/pypi.rb', line 18 def initialize(package_string, is_url: false) @pypi_info = nil if is_url match = if package_string.start_with?(PYTHONHOSTED_URL_PREFIX) File.basename(package_string).match(/^(.+)-([a-z\d.]+?)(?:.tar.gz|.zip)$/) end raise ArgumentError, "Package should be a valid PyPI URL" if match.blank? @name = PyPI.normalize_python_package(match[1]) @version = match[2] return end if package_string.include? "==" @name, @version = package_string.split("==") else @name = package_string end return unless (match = T.must(@name).match(/^(.*?)\[(.+)\]$/)) @name = match[1] @extras = T.must(match[2]).split "," end |
Instance Attribute Details
#extras ⇒ Object
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.
15 16 17 |
# File 'utils/pypi.rb', line 15 def extras @extras end |
#name ⇒ Object
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.
15 16 17 |
# File 'utils/pypi.rb', line 15 def name @name end |
#version ⇒ Object
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.
15 16 17 |
# File 'utils/pypi.rb', line 15 def version @version end |
Instance Method Details
#<=>(other) ⇒ Integer?
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.
106 107 108 |
# File 'utils/pypi.rb', line 106 def <=>(other) @name <=> other.name end |
#==(other) ⇒ Boolean Also known as: eql?
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.
Compare only names so we can use .include? and .uniq on a Package array
95 96 97 |
# File 'utils/pypi.rb', line 95 def ==(other) same_package?(other) end |
#hash ⇒ Integer
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.
101 102 103 |
# File 'utils/pypi.rb', line 101 def hash @name.tr("_", "-").downcase.hash end |
#pypi_info(version: nil) ⇒ 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 PyPI package.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'utils/pypi.rb', line 46 def pypi_info(version: nil) return @pypi_info if @pypi_info.present? && version.blank? version ||= @version = if version.present? "https://pypi.org/pypi/#{@name}/#{version}/json" else "https://pypi.org/pypi/#{@name}/json" end out, _, status = curl_output , "--location", "--fail" return unless status.success? begin json = JSON.parse out rescue JSON::ParserError return end sdist = json["urls"].find { |url| url["packagetype"] == "sdist" } return json["info"]["name"] if sdist.nil? @pypi_info = [ PyPI.normalize_python_package(json["info"]["name"]), sdist["url"], sdist["digests"]["sha256"], json["info"]["version"] ] 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.
89 90 91 |
# File 'utils/pypi.rb', line 89 def same_package?(other) T.must(@name.tr("_", "-").casecmp(other.name.tr("_", "-"))).zero? end |
#to_s ⇒ 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.
81 82 83 84 85 86 |
# File 'utils/pypi.rb', line 81 def to_s out = @name out += "[#{@extras.join(",")}]" if @extras.present? out += "==#{@version}" if @version.present? out 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.
75 76 77 78 |
# File 'utils/pypi.rb', line 75 def valid_pypi_package? info = pypi_info info.present? && info.is_a?(Array) end |