Class: PyPI::Package Private
- Inherits:
-
Object
- Object
- PyPI::Package
- Extended by:
- T::Sig
- Defined in:
- brew/Library/Homebrew/utils/pypi.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
PyPI Package
Instance Attribute Summary collapse
-
#extras ⇒ Object
private
-
#name ⇒ Object
private
-
#version ⇒ Object
private
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer?
private
-
#==(other) ⇒ Boolean
private
Compare only names so we can use .include? on a Package array.
-
#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. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'brew/Library/Homebrew/utils/pypi.rb', line 28 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 = match[1] @version = match[2] return end @name = package_string @name, @version = @name.split("==") if @name.include? "==" return unless match = @name.match(/^(.*?)\[(.+)\]$/) @name = match[1] @extras = match[2].split "," end |
Instance Attribute Details
#extras ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 |
# File 'brew/Library/Homebrew/utils/pypi.rb', line 24 def extras @extras end |
#name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 |
# File 'brew/Library/Homebrew/utils/pypi.rb', line 23 def name @name end |
#version ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 |
# File 'brew/Library/Homebrew/utils/pypi.rb', line 25 def version @version end |
Instance Method Details
#<=>(other) ⇒ Integer?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
104 105 106 |
# File 'brew/Library/Homebrew/utils/pypi.rb', line 104 def <=>(other) @name <=> other.name end |
#==(other) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compare only names so we can use .include? on a Package array
99 100 101 |
# File 'brew/Library/Homebrew/utils/pypi.rb', line 99 def ==(other) same_package?(other) end |
#pypi_info(version: nil) ⇒ Array<String>?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get name, URL, SHA-256 checksum, and latest version for a given PyPI package.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'brew/Library/Homebrew/utils/pypi.rb', line 53 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" 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 = [json["info"]["name"], sdist["url"], sdist["digests"]["sha256"], json["info"]["version"]] end |
#same_package?(other) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
93 94 95 |
# File 'brew/Library/Homebrew/utils/pypi.rb', line 93 def same_package?(other) @name.tr("_", "-").casecmp(other.name.tr("_", "-")).zero? end |
#to_s ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
85 86 87 88 89 90 |
# File 'brew/Library/Homebrew/utils/pypi.rb', line 85 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. You should avoid using this method if possible, as it may be removed or be changed in the future.
79 80 81 82 |
# File 'brew/Library/Homebrew/utils/pypi.rb', line 79 def valid_pypi_package? info = pypi_info info.present? && info.is_a?(Array) end |