-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Content addressable gems support #9674
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
base: master
Are you sure you want to change the base?
Changes from all commits
83a870d
39e302b
1636f46
8574341
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -93,6 +93,8 @@ def fetch_gems | |||||
| specs_and_sources = filtered unless filtered.empty? | ||||||
| end | ||||||
|
|
||||||
| specs_and_sources = prefer_content_addressed(specs_and_sources) | ||||||
|
|
||||||
| spec, source = specs_and_sources.max_by {|s,| s } | ||||||
|
|
||||||
| if spec.nil? | ||||||
|
|
@@ -106,4 +108,16 @@ def fetch_gems | |||||
|
|
||||||
| exit_code | ||||||
| end | ||||||
|
|
||||||
| def prefer_content_addressed(specs_and_sources) | ||||||
| return specs_and_sources unless specs_and_sources.any? {|s,| s.content_addressable? } | ||||||
|
|
||||||
| compatible = specs_and_sources.select do |spec,| | ||||||
| spec.required_ruby_version.satisfied_by?(Gem.ruby_version) | ||||||
| end | ||||||
| specs_and_sources = compatible unless compatible.empty? | ||||||
|
|
||||||
| skinny = specs_and_sources.select {|s,| s.content_addressable? } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per the server-side work are we trying to avoid the term 'skinny' as a rule of thumb as it could be a bit obscure for maintainers? For the sake of cohesion, what about:
Suggested change
|
||||||
| skinny.empty? ? specs_and_sources : skinny | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for 'skinny' here! |
||||||
| end | ||||||
| end | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,16 +6,17 @@ | |
| # wrap the data returned from the indexes. | ||
|
|
||
| class Gem::NameTuple | ||
| def initialize(name, version, platform = Gem::Platform::RUBY) | ||
| def initialize(name, version, platform = Gem::Platform::RUBY, content_address = nil) | ||
| @name = name | ||
| @version = version | ||
|
|
||
| platform &&= platform.to_s | ||
| platform = Gem::Platform::RUBY if !platform || platform.empty? | ||
| @platform = platform | ||
| @content_address = content_address | ||
| end | ||
|
|
||
| attr_reader :name, :version, :platform | ||
| attr_reader :name, :version, :platform, :content_address | ||
|
|
||
| ## | ||
| # Turn an array of [name, version, platform] into an array of | ||
|
|
@@ -46,11 +47,15 @@ def self.null | |
| # of Gem::Specification#full_name. | ||
|
|
||
| def full_name | ||
| case @platform | ||
| when nil, "", Gem::Platform::RUBY | ||
| "#{@name}-#{@version}" | ||
| if @content_address | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: just for readability we could do |
||
| "#{@name}-#{@version}-#{@content_address}" | ||
| else | ||
| "#{@name}-#{@version}-#{@platform}" | ||
| case @platform | ||
| when nil, "", Gem::Platform::RUBY | ||
| "#{@name}-#{@version}" | ||
| else | ||
| "#{@name}-#{@version}-#{@platform}" | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -61,6 +66,13 @@ def match_platform? | |
| Gem::Platform.match_gem? @platform, @name | ||
| end | ||
|
|
||
| ## | ||
| # Indicate if this NameTuple is content-addressable (carries a content address). | ||
|
|
||
| def content_addressable? | ||
| !@content_address.nil? | ||
| end | ||
|
|
||
| ## | ||
| # Indicate if this NameTuple is for a prerelease version. | ||
| def prerelease? | ||
|
|
@@ -94,8 +106,8 @@ def inspect # :nodoc: | |
| alias_method :to_s, :inspect # :nodoc: | ||
|
|
||
| def <=>(other) | ||
| [@name, @version, Gem::Platform.sort_priority(@platform)] <=> | ||
| [other.name, other.version, Gem::Platform.sort_priority(other.platform)] | ||
| [@name, @version, Gem::Platform.sort_priority(@platform), @content_address.to_s] <=> | ||
| [other.name, other.version, Gem::Platform.sort_priority(other.platform), other.content_address.to_s] | ||
| end | ||
|
|
||
| include Comparable | ||
|
|
@@ -109,7 +121,8 @@ def ==(other) | |
| when self.class | ||
| @name == other.name && | ||
| @version == other.version && | ||
| @platform == other.platform | ||
| @platform == other.platform && | ||
| @content_address == other.content_address | ||
| when Array | ||
| to_a == other | ||
| else | ||
|
|
@@ -120,6 +133,6 @@ def ==(other) | |
| alias_method :eql?, :== | ||
|
|
||
| def hash | ||
| to_a.hash | ||
| [@name, @version, @platform, @content_address].hash | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,8 +31,7 @@ def initialize(set, api_data) | |||||||
| @set = set | ||||||||
| @name = api_data[:name] | ||||||||
| @version = Gem::Version.new(api_data[:number]).freeze | ||||||||
| @platform = Gem::Platform.new(api_data[:platform]).freeze | ||||||||
| @original_platform = api_data[:platform].freeze | ||||||||
| assign_platform api_data | ||||||||
| @dependencies = api_data[:dependencies].map do |name, ver| | ||||||||
| Gem::Dependency.new(name, ver.split(/\s*,\s*/)).freeze | ||||||||
| end.freeze | ||||||||
|
|
@@ -46,11 +45,12 @@ def ==(other) # :nodoc: | |||||||
| @set == other.set && | ||||||||
| @name == other.name && | ||||||||
| @version == other.version && | ||||||||
| @platform == other.platform | ||||||||
| @platform == other.platform && | ||||||||
| @content_address == other.content_address | ||||||||
| end | ||||||||
|
|
||||||||
| def hash | ||||||||
| @set.hash ^ @name.hash ^ @version.hash ^ @platform.hash | ||||||||
| @set.hash ^ @name.hash ^ @version.hash ^ @platform.hash ^ @content_address.hash | ||||||||
| end | ||||||||
|
|
||||||||
| def fetch_development_dependencies # :nodoc: | ||||||||
|
|
@@ -97,6 +97,7 @@ def spec # :nodoc: | |||||||
| s.version = @version | ||||||||
| s.platform = @platform | ||||||||
| s.original_platform = @original_platform | ||||||||
| s.content_address = @content_address | ||||||||
| s.required_ruby_version = @required_ruby_version | ||||||||
| s.required_rubygems_version = @required_rubygems_version | ||||||||
|
|
||||||||
|
|
@@ -112,6 +113,28 @@ def source # :nodoc: | |||||||
|
|
||||||||
| private | ||||||||
|
|
||||||||
| def required_platform_from(requirement) | ||||||||
| operator, platform = Array(requirement).last.to_s.strip.split(/\s+/, 2) | ||||||||
| return unless operator == "=" && platform | ||||||||
|
|
||||||||
| Gem::Platform.new(platform) | ||||||||
| end | ||||||||
|
|
||||||||
| def assign_platform(api_data) | ||||||||
| suffix = api_data[:suffix].freeze | ||||||||
| required_platform = required_platform_from(api_data.dig(:requirements, :platform)) | ||||||||
|
|
||||||||
| if required_platform | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could choose to add a check in here that the suffix is definitely a content_address:
Suggested change
|
||||||||
| @content_address = suffix | ||||||||
| @platform = required_platform.freeze | ||||||||
| @original_platform = required_platform.to_s.freeze | ||||||||
| else | ||||||||
| @content_address = nil | ||||||||
| @platform = Gem::Platform.new(suffix).freeze | ||||||||
| @original_platform = suffix | ||||||||
| end | ||||||||
| end | ||||||||
|
|
||||||||
| def parse_created_at(value) | ||||||||
| value = value.first if value.is_a?(Array) | ||||||||
| return unless value.is_a?(String) | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question - are the spec objects
NameTupleshere orSpecification? I expected that they would beNameTupleobjects which would mean they wouldn't have access torequired_ruby_versionbut I may have the mental model wrong.