ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "Eregon (Benoit Daloze)" <noreply@ruby-lang.org>
To: ruby-core@neon.ruby-lang.org
Subject: [ruby-core:110831] [Ruby master Feature#19089] Load bundler/setup in gem_prelude.rb when "bundle exec" is used
Date: Mon, 21 Nov 2022 10:54:57 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-100189.20221121105454.18@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-19089.20221028070347.18@ruby-lang.org

Issue #19089 has been updated by Eregon (Benoit Daloze).


naruse (Yui NARUSE) wrote in #note-12:
> People shouldn't use and recommend others to use --disable-gem as a workaround for a bug. It's only for debugging.
> If people use --disable-gem for such use case widely, we need to remove the option.

There is no need for `--disable-gem` here.
`--disable-did-you-mean` / `--disable-error-highlight` are different and are supported AFAIK (e.g., some found that some error_highlight version was significantly slowing down Ruby in production).

As I said above, supporting this means giving up on some significant startup optimizations.
IMHO it's not worth it by default, probably very few people need to use a newer did_you_mean/error_highlight via Gemfile.
Also `error_highlight` would IMHO make more sense to be implemented in core (so e.g. it can always reliably find the source and not hope it can reread from disk) and then it's obvious it can't be updated.

----------------------------------------
Feature #19089: Load bundler/setup in gem_prelude.rb when "bundle exec" is used
https://bugs.ruby-lang.org/issues/19089#change-100189

* Author: mame (Yusuke Endoh)
* Status: Closed
* Priority: Normal
----------------------------------------
### Problem

Currently, we cannot specify the version of did_you_mean by using Gemfile.

For example, Ruby master bundles with did_you_mean 1.6.1 by default:

```
$ ruby -e 'p DidYouMean::VERSION'
"1.6.1"
```

Consider that we want to use did_you_mean 1.5.0 with this version of ruby:

```
$ cat Gemfile
source "https://rubygems.org"
gem "did_you_mean", "= 1.5.0"
```

But the attempt fails:

```
$ bundle exec ruby -e 'p DidYouMean::VERSION'
/home/mame/work/ruby/local/lib/ruby/gems/3.2.0+3/gems/bundler-2.3.19/lib/bundler/runtime.rb:308:in `check_for_activated_spec!': You have already activated did_you_mean 1.6.1, but your Gemfile requires did_you_mean 1.5.0. Since did_you_mean is a default gem, you can either remove your dependency on it or try updating to a newer version of bundler that supports did_you_mean as a default gem. (Gem::LoadError)
...
```

This issue is not only with did_you_mean, but also with error_highlight and syntax_suggest which are automatically loaded at the interpreter startup.

This example is specifying an older version of did_you_mean, but typically you will want to specify a newer version. Actually, in https://github.com/rails/rails/pull/45818, I wanted to use error_highlight 0.4.0 with Ruby 3.1. (Note that Ruby 3.1 bundles with error_highlight 0.3.0.)

The cause of this problem is that `bundle exec` makes the interpreter load `bundler/setup` using `RUBYOPT=-rbundler/setup`, but this load is too late.

### Proposed solution

Let's load `bundler/setup` in gem_prelude.rb when `bundle exec` is used.

```diff
diff --git a/gem_prelude.rb b/gem_prelude.rb
index f382021ca3..825508f571 100644
--- a/gem_prelude.rb
+++ b/gem_prelude.rb
@@ -6,6 +6,10 @@
   warn "`RubyGems' were not loaded."
 end if defined?(Gem)

+if ENV["BUNDLE_BIN_PATH"]
+  require File.join(File.dirname(ENV["BUNDLE_BIN_PATH"], 2), "lib/bundler/setup")
+end
+
 begin
   require 'error_highlight'
 rescue LoadError
```

The key is that bundler/setup is loaded immediately after rubygems is loaded, and before error_highlight and did_you_mean are loaded. This patch allows to specify the version of did_you_mean gem by Gemfile:

```
$ cat Gemfile
source "https://rubygems.org"
gem "did_you_mean", "= 1.5.0"

$ bundle exec ruby -e 'p DidYouMean::VERSION'
"1.5.0"
```

@deivid What do you think?



-- 
https://bugs.ruby-lang.org/

      parent reply	other threads:[~2022-11-21 10:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28  7:03 [ruby-core:110529] [Ruby master Feature#19089] Load bundler/setup in gem_prelude.rb when "bundle exec" is used mame (Yusuke Endoh)
2022-10-28  8:40 ` [ruby-core:110530] " vo.x (Vit Ondruch)
2022-10-28  9:46 ` [ruby-core:110531] " deivid
2022-10-28 11:30 ` [ruby-core:110534] " mame (Yusuke Endoh)
2022-10-28 11:40 ` [ruby-core:110535] " mame (Yusuke Endoh)
2022-10-28 14:50 ` [ruby-core:110536] " jeremyevans0 (Jeremy Evans)
2022-10-28 16:36 ` [ruby-core:110538] " mame (Yusuke Endoh)
2022-10-28 17:20 ` [ruby-core:110539] " Eregon (Benoit Daloze)
2022-10-28 18:12 ` [ruby-core:110540] " vo.x (Vit Ondruch)
2022-10-29  1:55 ` [ruby-core:110541] " mame (Yusuke Endoh)
2022-11-02 13:11 ` [ruby-core:110582] " deivid
2022-11-21  3:32 ` [ruby-core:110829] " naruse (Yui NARUSE)
2022-11-21 10:54 ` Eregon (Benoit Daloze) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-100189.20221121105454.18@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=ruby-core@neon.ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).