Skip to content

Fix required_ruby_version with prereleases and improve error message#2344

Merged
11 commits merged intoruby:masterfrom
deivid-rodriguez:ruby_version_check_and_prereleases
Nov 16, 2018
Merged

Fix required_ruby_version with prereleases and improve error message#2344
11 commits merged intoruby:masterfrom
deivid-rodriguez:ruby_version_check_and_prereleases

Conversation

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

Description:

Fixes #2343, by making the required_ruby_version gemspec setting work with prereleases and shows a better error message when the check does not pass.

Not sure how stable the RUBY_DESCRIPTION string is across ruby releases, maybe I can check the format is what we expect?


Tasks:

  • Describe the problem / feature
  • Write tests
  • Write code to solve the problem
  • Get code review from coworkers / friends

I will abide by the code of conduct.

@deivid-rodriguez deivid-rodriguez force-pushed the ruby_version_check_and_prereleases branch 2 times, most recently from 07b7d9f to 1c3f022 Compare July 4, 2018 22:50
Object.const_set :RUBY_REVISION, @RUBY_REVISION if
defined?(@RUBY_REVISION)
Object.const_set :RUBY_DESCRIPTION, @RUBY_DESCRIPTION if
defined?(@RUBY_DESCRIPTION)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the big diff in this method, this is the gotcha of this aligment style: keeping it obscures the point of commits.

@deivid-rodriguez deivid-rodriguez force-pushed the ruby_version_check_and_prereleases branch 3 times, most recently from a50bbc3 to 2008df2 Compare July 4, 2018 23:37
@MSP-Greg
Copy link
Copy Markdown
Contributor

MSP-Greg commented Jul 4, 2018

@deivid-rodriguez

I haven't had the time to think about this, and I'm not sure of it's application. I'm also not sure about how many people use trunk builds or preview builds. If it's as few as I think, most are probably capable of building/installing a gem from a specific git repo branch, so requirements don't need to be tight like a published gem. I think that made sense...

While gem releases are a discrete set, trunk is a little different. In some respects, I think a requirement for trunk/head should be done in terms of the svn/revision, not whether it's dev, preview, or whatever.

Either way, the message and to some respects, even gem env could provide more helpful info.

@deivid-rodriguez deivid-rodriguez force-pushed the ruby_version_check_and_prereleases branch from 2008df2 to 88b3ec4 Compare July 4, 2018 23:48
@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

Yeah, I see your point.

But when we read the issue, we seem to all acknowledged this as a bug and expected this to work with a prerelease (spec.required_ruby_version = ">= 2.6.0.preview2"). We're used to rubygems not knowing about specific revisions of gems (only bundler can handle that), but knowing about gem pre-releases, so it seems reasonable that rubygems can equally handle ruby prereleases in required_ruby_version, even if it can't really compare specific revisions.

With this patch, rubygems resolves 2.6.0.preview1 < 2.6.0.preview2 < 2.6.0.rc1 < 2.6.0.rc2 < 2.6.0. I think that's good enough. Aiming for correct comparison with specific revisions is out of the scope, since it's not even defined how the required_ruby_version option would look if we allowed specifying revisions.

@MSP-Greg
Copy link
Copy Markdown
Contributor

MSP-Greg commented Jul 5, 2018

I know, just kick the trunk guys to the curb...

You're right. One thing, I dl'd a preview tarball, and, as in trunk, in RUBY_DESCRIPTION, there isn't a period between RUBY_VERSION and RUBY_PATCHLEVEL_STR.

IOW, in RUBY_DESCRIPTION, I believe it's 2.6.0preview2, not 2.6.0.preview2.

Thanks, Greg

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

Correct, that's how I'm parsing it from RUBY_DESCRIPTION. But to play nice with how rubygems interprets versions, every segment needs to be separated with dots, I think, otherwise rubygems considers 2.6 as the release, and 0preview2 as the prerelease segment.

@deivid-rodriguez deivid-rodriguez force-pushed the ruby_version_check_and_prereleases branch 2 times, most recently from 083d1bc to a763b2d Compare July 5, 2018 00:48
@MSP-Greg
Copy link
Copy Markdown
Contributor

MSP-Greg commented Jul 5, 2018

@deivid-rodriguez

Sorry, I just saw the change in Gem.ruby_version (added period):

version << ".#{RUBY_DESCRIPTION.match(/\Aruby #{RUBY_VERSION}([^ ]+) /)[1]}"

Will \Aruby be an issue with JRuby? Maybe \A[a-z]+?

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

deivid-rodriguez commented Jul 5, 2018

Nice catch! Too bad that we don't test against jruby 😢

So I tried it and jruby keeps MRI constants to define the version of the ruby specification they support (RUBY_VERSION, RUBY_PATCHLEVEL), and uses extra variables for its own versioning (RUBY_ENGINE, RUBY_ENGINE_VERSION). So in my opinion the correct thing to do is to keep required_ruby_version for MRI versioning (RUBY_VERSION, RUBY_PATCHLEVEL), which is actually what defines the compatibiliy of the language, so it makes more sense.

I added a spec to "prove" what the behavior would be for jruby and that the current implementation would work.

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

Actually this could break if a non mri release had minimum compatibility with a prerelease of MRI (in that case I guess RUBY_PATCHLEVEL would be -1 and the regexp would break). I don't know if such a ruby implementation exists or will exist, but to be safest we should probably use a separate regexp for non mri RUBY_DESCRIPTIONs?

@MSP-Greg
Copy link
Copy Markdown
Contributor

MSP-Greg commented Jul 5, 2018

I don't know if such a ruby implementation exists or will exist

Neither do I. Nor do I know if non mri's have previews, betas, rc's, etc, which is what the regex is picking up now?

and the regexp would break

By break, return nil? Could always or it with ""...

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

The RUBY_DESCRIPTION in the case of jruby looks like this: "jruby 9.2.1.0 (2.5.0)...", that's why we'd need to change the regexp if the case I mentioned before wants to be supported. Otherwise we'd call [] on nil since the regexp won't match, I think.

@MSP-Greg
Copy link
Copy Markdown
Contributor

MSP-Greg commented Jul 5, 2018

The RUBY_DESCRIPTION in the case of jruby looks like this: "jruby 9.2.1.0

I should have been clearer. What about if it's a preview/beta/rc? I don't know myself...

Maybe change

version << ".#{RUBY_DESCRIPTION.match(/\Aruby #{RUBY_VERSION}([^ ]+) /)[1]}" 
 -- to --
version << ".#{RUBY_DESCRIPTION[/\A[a-z]+ #{RUBY_VERSION}([^ ]+) /, 1] || ''}"

Not sure if the ending period will mess things up, but I don't think so...

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

The thing is we're not trying to match the version of jruby but the version of the compatible MRI counterpart, namely, the string between the parentheses. At least that would seem like the most reasonable behavior to me.

@MSP-Greg
Copy link
Copy Markdown
Contributor

MSP-Greg commented Jul 5, 2018

I just looked at JRuby versions of Puma & Eventmachine, and neither seemed to have 'ruby' version requirements.

At least that would seem like the most reasonable behavior to me.

With different ruby engines, (ruby vs jruby), I don't know...

Hence, LGTM...

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

I think requiring a minimum engine version would be a separate feature that was proposed in the past, but rejected because the ecosystem was not ready yet. See #1468.

@ioquatix
Copy link
Copy Markdown
Member

ioquatix commented Jul 9, 2018

Thanks for working on this and I really appreciate everyones effort sorting this out.

@segiddins
Copy link
Copy Markdown
Contributor

This seems reasonable, but I really dont have enough experience with the different ruby version constants set by different implementations to be confident this will work universally. I'd like those with more relevant experience to weigh in.

@deivid-rodriguez
Copy link
Copy Markdown
Contributor Author

Yeah, I also wonder if we should add a feature request to ruby so that they expose this info and we don't have to parse RUBY_DESCRIPTION.

@MSP-Greg
Copy link
Copy Markdown
Contributor

Yeah, I also wonder if we should add a feature request to ruby so that they expose this info and we don't have to parse RUBY_DESCRIPTION

Considering this, and looking over test_case.rb and the handling of ENV & RUBY_ elements, might a later PR refactor the code to use constant arrays holding all the elements that are saved/restored?

At present, a change to either results in changes to both the save and restore portions of the code, where using arrays would require one change.

IOW, use arrays for the names of all the ENV & RUBY_ items saved/restored, and hashes like orig_env and orig_ruby_info for the original values, rather than all the separate instance variables...

We can't really make comparison work with them, they are not documented,
and they mess up prerelease comparison (since previously `2.6.0.preview2
< 2.6.0.preview2.63539` when they are really the same thing).
This reverts commit 1650306.

This made sense before ruby 2.1.0, when the same patch level
specification (2.0.0) would have several different releases (2.0.0-p648,
2.0.0-p647, and so on). However, since ruby 2.1.0, every minor release
of ruby has a different patch level, so these docs are now misleading.
@deivid-rodriguez deivid-rodriguez force-pushed the ruby_version_check_and_prereleases branch from a52304d to 8fe4320 Compare November 13, 2018 16:54
@hsbt
Copy link
Copy Markdown
Member

hsbt commented Nov 16, 2018

@bundlerbot r+

ghost pushed a commit that referenced this pull request Nov 16, 2018
2344: Fix required_ruby_version with prereleases and improve error message r=hsbt a=deivid-rodriguez

# Description:

Fixes #2343, by making the `required_ruby_version` gemspec setting work with prereleases and shows a better error message when the check does not pass.

Not sure how stable the `RUBY_DESCRIPTION` string is across ruby releases, maybe I can check the format is what we expect?

______________

# Tasks:

- [x] Describe the problem / feature
- [x] Write tests
- [x] Write code to solve the problem
- [ ] Get code review from coworkers / friends

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).


Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
@ghost
Copy link
Copy Markdown

ghost commented Nov 16, 2018

Build succeeded

@ghost ghost merged commit 8fe4320 into ruby:master Nov 16, 2018
@deivid-rodriguez deivid-rodriguez deleted the ruby_version_check_and_prereleases branch November 16, 2018 10:16
matzbot pushed a commit to ruby/ruby that referenced this pull request Nov 21, 2018
  * Enable Style/MethodDefParentheses in Rubocop
    ruby/rubygems#2478
  * Enable Style/MultilineIfThen in Rubocop
    ruby/rubygems#2479
  * Fix required_ruby_version with prereleases and improve error message
    ruby/rubygems#2344
  * Fix bundler rubygems binstub not properly looking for bundler
    ruby/rubygems#2426

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
ioquatix pushed a commit to ioquatix/ruby that referenced this pull request Nov 22, 2018
  * Enable Style/MethodDefParentheses in Rubocop
    ruby/rubygems#2478
  * Enable Style/MultilineIfThen in Rubocop
    ruby/rubygems#2479
  * Fix required_ruby_version with prereleases and improve error message
    ruby/rubygems#2344
  * Fix bundler rubygems binstub not properly looking for bundler
    ruby/rubygems#2426

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
bannable pushed a commit to bannable/ruby that referenced this pull request Dec 10, 2018
  * Enable Style/MethodDefParentheses in Rubocop
    ruby/rubygems#2478
  * Enable Style/MultilineIfThen in Rubocop
    ruby/rubygems#2479
  * Fix required_ruby_version with prereleases and improve error message
    ruby/rubygems#2344
  * Fix bundler rubygems binstub not properly looking for bundler
    ruby/rubygems#2426

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants