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.
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 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.
-
#extras ⇒ Array<String, nil>
private
-
#hash ⇒ Integer
private
-
#initialize(package_string, is_url: false) ⇒ void
constructor
private
-
#name ⇒ String
private
-
#pypi_info(new_version: nil) ⇒ Array<String>?
private
Get name, URL, SHA-256 checksum, and latest version for a given package.
-
#same_package?(other) ⇒ Boolean
private
-
#to_s ⇒ String
private
-
#valid_pypi_package? ⇒ Boolean
private
-
#version ⇒ String?
private
-
#version=(new_version) ⇒ void
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.
17 18 19 20 21 22 |
# File 'utils/pypi.rb', line 17 def initialize(package_string, is_url: false) @pypi_info = nil @package_string = package_string @is_url = is_url @is_pypi_url = package_string.start_with? PYTHONHOSTED_URL_PREFIX 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.
118 119 120 |
# File 'utils/pypi.rb', line 118 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
107 108 109 |
# File 'utils/pypi.rb', line 107 def ==(other) same_package?(other) end |
#extras ⇒ Array<String, nil>
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.
31 32 33 34 |
# File 'utils/pypi.rb', line 31 def extras if @extras.blank? @extras 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.
113 114 115 |
# File 'utils/pypi.rb', line 113 def hash name.hash 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.
25 26 27 28 |
# File 'utils/pypi.rb', line 25 def name if @name.blank? @name end |
#pypi_info(new_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 package.
This only works for packages from PyPI or from a PyPI URL; packages
derived from non-PyPI URLs will produce nil
here.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'utils/pypi.rb', line 58 def pypi_info(new_version: nil) 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 out, _, status = Utils::Curl.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 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.
100 101 102 103 |
# File 'utils/pypi.rb', line 100 def same_package?(other) # These names are pre-normalized, so we can compare them directly. name == other.name 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.
88 89 90 91 92 93 94 95 96 97 |
# File 'utils/pypi.rb', line 88 def to_s if valid_pypi_package? out = name out += "[#{extras.join(",")}]" if extras.present? out += "==#{version}" if version.present? out else @package_string end 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.
50 51 52 |
# File 'utils/pypi.rb', line 50 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.
37 38 39 40 |
# File 'utils/pypi.rb', line 37 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.
43 44 45 46 47 |
# File 'utils/pypi.rb', line 43 def version=(new_version) raise ArgumentError, "can't update version for non-PyPI packages" unless valid_pypi_package? @version = new_version end |