Skip to content
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

Add file option to ruby method in Gemfile #6876

Merged
merged 1 commit into from
Aug 17, 2023

Conversation

ngan
Copy link
Contributor

@ngan ngan commented Aug 13, 2023

Fixes #6742. Please read the original issue for full context.

You can now do this in your Gemfile:

ruby file: '.ruby-version'

@deivid-rodriguez
Copy link
Member

Thanks!

The original specification by indirect seems better to me though? I think it could get confusing if ruby '3.1.0', file: '.ruby-version' ends up using a different ruby than 3.1.0? What the use case for the extra flexibility?

@ngan
Copy link
Contributor Author

ngan commented Aug 15, 2023

Thanks!

The original specification by indirect seems better to me though? I think it could get confusing if ruby '3.1.0', file: '.ruby-version' ends up using a different ruby than 3.1.0? What the use case for the extra flexibility?

@deivid-rodriguez yeah, I can't think of one that doesn't cause even more confusion 😅

I've updated the logic to raise an error if you provide both.

@martinemde
Copy link
Member

I know @hsbt brought up something similar, but I'll ask anyway. Could ruby :file be a shortcut for the very most common filename of .ruby-version. 99% of all gemfiles will have ruby file: '.ruby-version' once this change is widely adopted.

@ngan
Copy link
Contributor Author

ngan commented Aug 15, 2023

Could ruby :file be a shortcut for the very most common filename of .ruby-version.

I personally think it's too much implicitness. Typing out .ruby-version (you only have to do it once) makes it very clear where it's coming from for new Ruby users. Similarly, source 'https://rubygems.org' is at the top of 99% of Gemfiles out there...but I'm guessing it's there for the same reason. 🤷

@martinemde
Copy link
Member

martinemde commented Aug 15, 2023

One last thought: should we add ruby version: '3.2.2' for consistency? (please ignore this for this PR though, I think it's good to go)

Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

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

Actually, this should be documented in the gemfile.5 man page. Can we add a note about the new option?

@ngan
Copy link
Contributor Author

ngan commented Aug 17, 2023

@deivid-rodriguez done!

Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

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

Awesome! Rebased and squashed, and going in!

@deivid-rodriguez deivid-rodriguez merged commit 1c70a55 into rubygems:master Aug 17, 2023
92 checks passed
deivid-rodriguez added a commit that referenced this pull request Aug 17, 2023
Add `file` option to `ruby` method in Gemfile

(cherry picked from commit 1c70a55)
@ngan ngan deleted the ruby-method-file-support branch August 18, 2023 04:23
@jasnow
Copy link

jasnow commented Aug 21, 2023

Does this feature work with ruby 3.3.0.preview1?
I'm getting an error message: Your Ruby version is 3.3.0.preview1, but your Gemfile specified

@simi
Copy link
Member

simi commented Aug 21, 2023

Does this feature work with ruby 3.3.0.preview1? I'm getting an error message: Your Ruby version is 3.3.0.preview1, but your Gemfile specified

It is not part of Ruby 3.3.0.preview1 per my understanding, but it was released in Bundler 2.4.19 version. Just ensure you have right version.

@jasnow
Copy link

jasnow commented Aug 21, 2023

This issue is "rvm list" shows "3.0.0.preview1" (period before preview1) where .ruby-versions and bundler want "-" before preview1. Now have a "fix".

@alec-c4
Copy link

alec-c4 commented Aug 22, 2023

What about support of asdf? Because they have slightly different syntax.

@simi
Copy link
Member

simi commented Aug 22, 2023

What about support of asdf? Because they have slightly different syntax.

@alec-c4 support for .tool-versions was added at #6898

@alec-c4
Copy link

alec-c4 commented Aug 22, 2023

What about support of asdf? Because they have slightly different syntax.

@alec-c4 support for .tool-versions was added at #6898

Yay!!!!!! Such an awesome news!!!!

@pboling
Copy link
Contributor

pboling commented Sep 12, 2023

This doesn't quite work right.

[!] There was an error parsing `Gemfile`: Illformed requirement ["ruby 2.7.8\ndirenv 2.32.2\nmongodb 6.2.1"]. Bundler cannot continue.

 #  from /Volumes/🐉🩸/src/apps/counting_sheep/Gemfile:1
 #  -------------------------------------------
 >  ruby file: ".tool-versions"
 #  
 #  -------------------------------------------

where my .tool-versions file has:

ruby 2.7.8
direnv 2.32.2
mongodb 6.2.1

Alternatively with .ruby-version:

[!] There was an error parsing `Gemfile`: Illformed requirement ["ruby-2.7.8"]. Bundler cannot continue.

 #  from /Volumes/🐉🩸/src/apps/counting_sheep/Gemfile:1
 #  -------------------------------------------
 >  ruby file: ".ruby-version"
 #  
 #  -------------------------------------------

where my .ruby-version file has:

ruby-2.7.8

@hsbt
Copy link
Member

hsbt commented Sep 12, 2023

@pboling Because we didn't backport #6898 into stable version yet.

@pboling
Copy link
Contributor

pboling commented Sep 12, 2023

The problem is Gem::Requirement.parse is not sufficient for either .ruby-version or .tool-versions, and the spec added in this PR is too mocky to detect the issue.

before { allow(Bundler).to receive(:read_file).with("foo").and_return("#{version}\n") }

@martinemde
Copy link
Member

It seems we need better tests for this. Thank you for reporting.

@pboling
Copy link
Contributor

pboling commented Sep 12, 2023

You could argue that it is not mocky enough. 👍 Perhaps a test that mocks the parse result for each distinct "standard" (not-a-real-standard) format of .ruby-version.

3.1.2
ruby-3.1.2
3.1.2@gemset
ruby-3.1.2@gemset

Not sure if there is a comprehensive list anywhere of all the formats of .ruby-version as it is a loosely shared standard between the many Ruby version managers, but here is rvm's incomplete documentation:
https://rvm.io/workflow/projects#project-file-ruby-version

@martinemde
Copy link
Member

martinemde commented Sep 12, 2023

I'm looking into fixing this now. FWIW this might be the original proposal for .ruby-version from 2012 and has received running updates along the way as things were decided.

I'm of two minds for this behavior. One the one hand, Bundler could be opinionated about the format. We could simply say that if you put something into .ruby-version that is not a simple version, then Bundler won't read it. (In other words, a Steve Jobs "Don't hold it that way")

On the other hand, this format is not up to bundler and has existed for a long time. It's used by rbenv, chruby, rvm and we have chosen to attempt to read asdf's format.

It's trivial to trim ruby- off the front and @gemset off the end, but if users of bundler can just tweak their .ruby-version file with no ill effect, then keeping this simple would also produce a narrowing of usage of .ruby-version, and dare I even say it, a standard format.

@pboling
Copy link
Contributor

pboling commented Sep 12, 2023

For those who rely on the @gemset to provide encapsulaiton between multiple installations on a single VPS, as I used to many years ago, not supporting it would mean they can't use the file: feature at all... but maybe that's not the end of the world? I do think that at minimum the ruby- can be stripped, because even those who are not using gemsets may be using it, and supporting it will prevent confused bug reports from users attempting to try out file: and having it blow up. I suppose the same could be said for supporting @gemset.

@martinemde
Copy link
Member

martinemde commented Sep 13, 2023

Thanks for taking up this discussion and for making sure we solve this as well as possible.

For @gemset, I see that RVM documents that @gemset is not compatible with other version managers. They suggest that users should rely on the .ruby-gemset file for that feature. I feel good excluding that behavior since it's definitely non-standard and the work around is easy and recommended.

I am patching this to support removing ruby- since that seems to be fairly common. I'll update with a ticket number when I push. (#6954)

Also for jruby/truffleruby folks out there, you might end up with something like this (this is not a recommendation, but just pointing out that the engine options are allowed with the file option)

ruby file: ".ruby-version", engine: "jruby", engine_version: "9.4.3.0"
$ cat .ruby-version
3.1.4

albertchae added a commit to albertchae/bundler-site that referenced this pull request Feb 6, 2024
albertchae added a commit to albertchae/bundler-site that referenced this pull request Feb 6, 2024
This is already documented on the
[manpage](https://bundler.io/v2.5/man/gemfile.5.html#VERSION-required-)
but it seems like it makes sense to have on this page as well.

Feature was implemented in rubygems/rubygems#6876

This copy is lifted from the manpage source https://github.com/rubygems/rubygems/blob/6bbc8bed344eeaadcbd8dfcc6e20c9e1eb734d96/bundler/lib/bundler/man/gemfile.5.ronn?plain=1#L72-L80
olleolleolle pushed a commit to rubygems/bundler-site that referenced this pull request Feb 7, 2024
This is already documented on the
[manpage](https://bundler.io/v2.5/man/gemfile.5.html#VERSION-required-)
but it seems like it makes sense to have on this page as well.

Feature was implemented in rubygems/rubygems#6876

This copy is lifted from the manpage source https://github.com/rubygems/rubygems/blob/6bbc8bed344eeaadcbd8dfcc6e20c9e1eb734d96/bundler/lib/bundler/man/gemfile.5.ronn?plain=1#L72-L80

Co-authored-by: Albert Chae <albertchae@users.noreply.github.com>
robzolkos added a commit to robzolkos/rails that referenced this pull request Feb 9, 2024
Bundler [2.4.19](https://github.com/rubygems/rubygems/blob/master/bundler/CHANGELOG.md#2419-august-17-2023) [introduced](rubygems/rubygems#6876) the ability to read in the version of Ruby from the `.ruby-version` file.

`ruby file: '.ruby-version'`

Rails doesn't yet use this pattern, settling for explitely setting the Ruby version in both the `.ruby-version` file and the `Gemfile`.

However, a lot of developers _will_ update the Gemfile to use the new `file:` syntax.  When they do, the default Dockerfile will fail to build because when it attempts to bundle the gems, there is no `.ruby-version` file for it to refer to.

This update copies over the `.ruby-version` file at the same time as the `Gemfile` and `Gemfile.lock` so bundler has everything it needs to bundle regardless of how the Ruby version is specified in the Gemfile.
robzolkos added a commit to robzolkos/rails that referenced this pull request Feb 9, 2024
…dler/CHANGELOG.md#2419-august-17-2023) [introduced](rubygems/rubygems#6876) the ability to read in the version of Ruby from the `.ruby-version` file.

`ruby file: '.ruby-version'`

Rails doesn't yet use this pattern, settling for explitely setting the Ruby version in both the `.ruby-version` file and the `Gemfile`.

However, a lot of developers _will_ update the Gemfile to use the new `file:` syntax.  When they do, the default Dockerfile will fail to build because when it attempts to bundle the gems, there is no `.ruby-version` file for it to refer to.

This update copies over the `.ruby-version` file at the same time as the `Gemfile` and `Gemfile.lock` so bundler has everything it needs to bundle regardless of how the Ruby version is specified in the Gemfile.
robzolkos added a commit to robzolkos/rails that referenced this pull request Feb 9, 2024
…dler/CHANGELOG.md#2419-august-17-2023) [introduced](rubygems/rubygems#6876) the ability to read in the version of Ruby from the `.ruby-version` file.

`ruby file: '.ruby-version'`

Rails doesn't yet use this pattern, settling for explitely setting the Ruby version in both the `.ruby-version` file and the `Gemfile`.

However, a lot of developers _will_ update the Gemfile to use the new `file:` syntax.  When they do, the default Dockerfile will fail to build because when it attempts to bundle the gems, there is no `.ruby-version` file for it to refer to.

This update copies over the `.ruby-version` file at the same time as the `Gemfile` and `Gemfile.lock` so bundler has everything it needs to bundle regardless of how the Ruby version is specified in the Gemfile.
robzolkos added a commit to robzolkos/rails that referenced this pull request Feb 9, 2024
Bundler [2.4.19](https://github.com/rubygems/rubygems/blob/master/bundler/CHANGELOG.md#2419-august-17-2023) [introduced](rubygems/rubygems#6876) the ability to read in the version of Ruby from the `.ruby-version` file.

`ruby file: '.ruby-version'`

Rails doesn't yet use this pattern, settling for explitely setting the Ruby version in both the `.ruby-version` file and the `Gemfile`.

However, a lot of developers _will_ update the Gemfile to use the new `file:` syntax.  When they do, the default Dockerfile will fail to build because when it attempts to bundle the gems, there is no `.ruby-version` file for it to refer to.

This update copies over the `.ruby-version` file at the same time as the `Gemfile` and `Gemfile.lock` so bundler has everything it needs to bundle regardless of how the Ruby version is specified in the Gemfile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add file support to ruby method in Gemfile
8 participants