ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:119041] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb`
@ 2024-09-04 14:17 Earlopain (A S) via ruby-core
  2024-09-04 15:51 ` [ruby-core:119042] " Eregon (Benoit Daloze) via ruby-core
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Earlopain (A S) via ruby-core @ 2024-09-04 14:17 UTC (permalink / raw)
  To: ruby-core; +Cc: Earlopain (A S)

Issue #20714 has been reported by Earlopain (A S).

----------------------------------------
Bug #20714: Handle optional dependencies in `bundled_gems.rb`
https://bugs.ruby-lang.org/issues/20714

* Author: Earlopain (A S)
* Status: Open
* ruby -v: 3.3.5
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I've encountered a few places around bundled gems where the library doesn't care if the gem is available, but will still provide some functionallity if it is.

The way to accomplish that right now seems to be by setting `$VERBOSE = nil` and resetting it later again to not bother the user with the warning about the gem. However, this has the effect of silencing the warning about other gems as well, that may not be prepared about the bundling. 

>From `ruby/reline` for example: https://github.com/ruby/reline/blob/c90f08f7e308d2f1cdd7cfaf9939fe45ce546fd2/lib/reline/terminfo.rb#L1-L15
Or the `logging` gem: https://github.com/TwP/logging/blob/df41715364f7eb8c65098cd3c3316677ef1f3784/lib/logging.rb#L9-L15

I propose to simply delay the warning to the next require. GitHub PR at ...



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:119042] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb`
  2024-09-04 14:17 [ruby-core:119041] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb` Earlopain (A S) via ruby-core
@ 2024-09-04 15:51 ` Eregon (Benoit Daloze) via ruby-core
  2024-09-04 16:06 ` [ruby-core:119043] " Eregon (Benoit Daloze) via ruby-core
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2024-09-04 15:51 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

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


One potential problem with setting `$VERBOSE` to nil is that's not thread-safe, and so might hide valid warnings from other threads requiring around the same time.
Maybe it should be some explicit method in `Gem` or so to suppress that warning, or a keyword argument like `require "foo", optional: true`.

----------------------------------------
Bug #20714: Handle optional dependencies in `bundled_gems.rb`
https://bugs.ruby-lang.org/issues/20714#change-109620

* Author: Earlopain (A S)
* Status: Open
* ruby -v: 3.3.5
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I've encountered a few places around bundled gems where the library doesn't care if the gem is available, but will still provide some functionallity if it is.

The way to accomplish that right now seems to be by setting `$VERBOSE = nil` and resetting it later again to not bother the user with the warning about the gem. However, this has the effect of silencing the warning about other gems as well, that may not be prepared about the bundling. 

>From `ruby/reline` for example: https://github.com/ruby/reline/blob/c90f08f7e308d2f1cdd7cfaf9939fe45ce546fd2/lib/reline/terminfo.rb#L1-L15
Or the `logging` gem: https://github.com/TwP/logging/blob/df41715364f7eb8c65098cd3c3316677ef1f3784/lib/logging.rb#L9-L15

I propose to simply delay the warning to the next require.

GitHub PR at https://github.com/ruby/ruby/pull/11545



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:119043] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb`
  2024-09-04 14:17 [ruby-core:119041] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb` Earlopain (A S) via ruby-core
  2024-09-04 15:51 ` [ruby-core:119042] " Eregon (Benoit Daloze) via ruby-core
@ 2024-09-04 16:06 ` Eregon (Benoit Daloze) via ruby-core
  2024-09-04 16:20 ` [ruby-core:119044] " Earlopain (A S) via ruby-core
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2024-09-04 16:06 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

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


The problem is any new API would be rather cumbersome to use (in a way that still works on older Rubies), so probably this fix is good as a quick measure.

I think it would be good to think about a longer-term solution too though.

----------------------------------------
Bug #20714: Handle optional dependencies in `bundled_gems.rb`
https://bugs.ruby-lang.org/issues/20714#change-109621

* Author: Earlopain (A S)
* Status: Open
* ruby -v: 3.3.5
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I've encountered a few places around bundled gems where the library doesn't care if the gem is available, but will still provide some functionallity if it is.

The way to accomplish that right now seems to be by setting `$VERBOSE = nil` and resetting it later again to not bother the user with the warning about the gem. However, this has the effect of silencing the warning about other gems as well, that may not be prepared about the bundling. 

>From `ruby/reline` for example: https://github.com/ruby/reline/blob/c90f08f7e308d2f1cdd7cfaf9939fe45ce546fd2/lib/reline/terminfo.rb#L1-L15
Or the `logging` gem: https://github.com/TwP/logging/blob/df41715364f7eb8c65098cd3c3316677ef1f3784/lib/logging.rb#L9-L15

I propose to simply delay the warning to the next require.

GitHub PR at https://github.com/ruby/ruby/pull/11545



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:119044] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb`
  2024-09-04 14:17 [ruby-core:119041] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb` Earlopain (A S) via ruby-core
  2024-09-04 15:51 ` [ruby-core:119042] " Eregon (Benoit Daloze) via ruby-core
  2024-09-04 16:06 ` [ruby-core:119043] " Eregon (Benoit Daloze) via ruby-core
@ 2024-09-04 16:20 ` Earlopain (A S) via ruby-core
  2024-09-04 16:38 ` [ruby-core:119045] " Eregon (Benoit Daloze) via ruby-core
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Earlopain (A S) via ruby-core @ 2024-09-04 16:20 UTC (permalink / raw)
  To: ruby-core; +Cc: Earlopain (A S)

Issue #20714 has been updated by Earlopain (A S).


Thanks for you reply, I was about to write something similar about the older rubies.

At first I was writing about how I don't think a new api is really necessary since the compatibility code can simply be dropped once `required_ruby_version` is at or above the ruby version that would error but I don't think that is entirely true. For example, on ruby 3.4 the following script produces this output:

```rb
begin
  require "webrick"
rescue LoadError
end

if defined?(Webrick)
  puts "Do some things"
end

# test.rb:2: warning: webrick was loaded from the standard library, but is not part of the default gems starting from Ruby 3.0.0.
# You can add webrick to your Gemfile or gemspec to silence this warning.
```

So even though webrick is gone since Ruby 3.0, I'd still have to do some trickery to optionally enhance it without triggering the warning.

I see two solutions:
* `require "foo", optional: true` like you suggested
* Drop warnings when ruby would throw an error [here]. When the require will raise, it doesn't need to warn. This is how I already imagined it works. I guess it doesn't for visibility?

[here]: https://github.com/ruby/ruby/blob/294dad22d7ac5f307d567cff897507b9fd9d05e9/lib/bundled_gems.rb#L6-L36

----------------------------------------
Bug #20714: Handle optional dependencies in `bundled_gems.rb`
https://bugs.ruby-lang.org/issues/20714#change-109622

* Author: Earlopain (A S)
* Status: Open
* ruby -v: 3.3.5
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I've encountered a few places around bundled gems where the library doesn't care if the gem is available, but will still provide some functionallity if it is.

The way to accomplish that right now seems to be by setting `$VERBOSE = nil` and resetting it later again to not bother the user with the warning about the gem. However, this has the effect of silencing the warning about other gems as well, that may not be prepared about the bundling. 

>From `ruby/reline` for example: https://github.com/ruby/reline/blob/c90f08f7e308d2f1cdd7cfaf9939fe45ce546fd2/lib/reline/terminfo.rb#L1-L15
Or the `logging` gem: https://github.com/TwP/logging/blob/df41715364f7eb8c65098cd3c3316677ef1f3784/lib/logging.rb#L9-L15

I propose to simply delay the warning to the next require.

GitHub PR at https://github.com/ruby/ruby/pull/11545



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:119045] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb`
  2024-09-04 14:17 [ruby-core:119041] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb` Earlopain (A S) via ruby-core
                   ` (2 preceding siblings ...)
  2024-09-04 16:20 ` [ruby-core:119044] " Earlopain (A S) via ruby-core
@ 2024-09-04 16:38 ` Eregon (Benoit Daloze) via ruby-core
  2024-09-04 20:02 ` [ruby-core:119046] " deivid via ruby-core
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2024-09-04 16:38 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

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


Maybe a good solution is to make `$VERBOSE` thread-local or fiber-local at some point, then at least this concern and related ones would be solved once and for all.

----------------------------------------
Bug #20714: Handle optional dependencies in `bundled_gems.rb`
https://bugs.ruby-lang.org/issues/20714#change-109623

* Author: Earlopain (A S)
* Status: Open
* ruby -v: 3.3.5
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I've encountered a few places around bundled gems where the library doesn't care if the gem is available, but will still provide some functionallity if it is.

The way to accomplish that right now seems to be by setting `$VERBOSE = nil` and resetting it later again to not bother the user with the warning about the gem. However, this has the effect of silencing the warning about other gems as well, that may not be prepared about the bundling. 

>From `ruby/reline` for example: https://github.com/ruby/reline/blob/c90f08f7e308d2f1cdd7cfaf9939fe45ce546fd2/lib/reline/terminfo.rb#L1-L15
Or the `logging` gem: https://github.com/TwP/logging/blob/df41715364f7eb8c65098cd3c3316677ef1f3784/lib/logging.rb#L9-L15

I propose to simply delay the warning to the next require.

GitHub PR at https://github.com/ruby/ruby/pull/11545



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:119046] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb`
  2024-09-04 14:17 [ruby-core:119041] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb` Earlopain (A S) via ruby-core
                   ` (3 preceding siblings ...)
  2024-09-04 16:38 ` [ruby-core:119045] " Eregon (Benoit Daloze) via ruby-core
@ 2024-09-04 20:02 ` deivid via ruby-core
  2024-09-05  6:24 ` [ruby-core:119056] " Earlopain (A S) via ruby-core
  2024-09-05  6:26 ` [ruby-core:119057] " hsbt (Hiroshi SHIBATA) via ruby-core
  6 siblings, 0 replies; 8+ messages in thread
From: deivid via ruby-core @ 2024-09-04 20:02 UTC (permalink / raw)
  To: ruby-core; +Cc: deivid

Issue #20714 has been updated by deivid (David Rodríguez).


> Drop warnings when ruby would throw an error here. When the require will raise, it doesn't need to warn. This is how I already imagined it works. I guess it doesn't for visibility?

I think this is the best solution. The warning is also misleading if the require fails because it suggests that the require succeeded ("webrick was loaded from...").

Is it as simple as https://github.com/ruby/ruby/pull/11550?

----------------------------------------
Bug #20714: Handle optional dependencies in `bundled_gems.rb`
https://bugs.ruby-lang.org/issues/20714#change-109624

* Author: Earlopain (A S)
* Status: Open
* ruby -v: 3.3.5
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I've encountered a few places around bundled gems where the library doesn't care if the gem is available, but will still provide some functionallity if it is.

The way to accomplish that right now seems to be by setting `$VERBOSE = nil` and resetting it later again to not bother the user with the warning about the gem. However, this has the effect of silencing the warning about other gems as well, that may not be prepared about the bundling. 

>From `ruby/reline` for example: https://github.com/ruby/reline/blob/c90f08f7e308d2f1cdd7cfaf9939fe45ce546fd2/lib/reline/terminfo.rb#L1-L15
Or the `logging` gem: https://github.com/TwP/logging/blob/df41715364f7eb8c65098cd3c3316677ef1f3784/lib/logging.rb#L9-L15

I propose to simply delay the warning to the next require.

GitHub PR at https://github.com/ruby/ruby/pull/11545



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:119056] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb`
  2024-09-04 14:17 [ruby-core:119041] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb` Earlopain (A S) via ruby-core
                   ` (4 preceding siblings ...)
  2024-09-04 20:02 ` [ruby-core:119046] " deivid via ruby-core
@ 2024-09-05  6:24 ` Earlopain (A S) via ruby-core
  2024-09-05  6:26 ` [ruby-core:119057] " hsbt (Hiroshi SHIBATA) via ruby-core
  6 siblings, 0 replies; 8+ messages in thread
From: Earlopain (A S) via ruby-core @ 2024-09-05  6:24 UTC (permalink / raw)
  To: ruby-core; +Cc: Earlopain (A S)

Issue #20714 has been updated by Earlopain (A S).


deivid (David Rodríguez) wrote in #note-6:
> Is it as simple as https://github.com/ruby/ruby/pull/11550?

I had something a little different in mind (trim `SINCE`) but I think that is a nice solution. The PR looks reasonable to me.

----------------------------------------
Bug #20714: Handle optional dependencies in `bundled_gems.rb`
https://bugs.ruby-lang.org/issues/20714#change-109634

* Author: Earlopain (A S)
* Status: Open
* ruby -v: 3.3.5
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I've encountered a few places around bundled gems where the library doesn't care if the gem is available, but will still provide some functionallity if it is.

The way to accomplish that right now seems to be by setting `$VERBOSE = nil` and resetting it later again to not bother the user with the warning about the gem. However, this has the effect of silencing the warning about other gems as well, that may not be prepared about the bundling. 

>From `ruby/reline` for example: https://github.com/ruby/reline/blob/c90f08f7e308d2f1cdd7cfaf9939fe45ce546fd2/lib/reline/terminfo.rb#L1-L15
Or the `logging` gem: https://github.com/TwP/logging/blob/df41715364f7eb8c65098cd3c3316677ef1f3784/lib/logging.rb#L9-L15

I propose to simply delay the warning to the next require.

GitHub PR at https://github.com/ruby/ruby/pull/11545



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:119057] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb`
  2024-09-04 14:17 [ruby-core:119041] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb` Earlopain (A S) via ruby-core
                   ` (5 preceding siblings ...)
  2024-09-05  6:24 ` [ruby-core:119056] " Earlopain (A S) via ruby-core
@ 2024-09-05  6:26 ` hsbt (Hiroshi SHIBATA) via ruby-core
  6 siblings, 0 replies; 8+ messages in thread
From: hsbt (Hiroshi SHIBATA) via ruby-core @ 2024-09-05  6:26 UTC (permalink / raw)
  To: ruby-core; +Cc: hsbt (Hiroshi SHIBATA)

Issue #20714 has been updated by hsbt (Hiroshi SHIBATA).

Status changed from Open to Assigned
Assignee set to hsbt (Hiroshi SHIBATA)

----------------------------------------
Bug #20714: Handle optional dependencies in `bundled_gems.rb`
https://bugs.ruby-lang.org/issues/20714#change-109635

* Author: Earlopain (A S)
* Status: Assigned
* Assignee: hsbt (Hiroshi SHIBATA)
* ruby -v: 3.3.5
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I've encountered a few places around bundled gems where the library doesn't care if the gem is available, but will still provide some functionallity if it is.

The way to accomplish that right now seems to be by setting `$VERBOSE = nil` and resetting it later again to not bother the user with the warning about the gem. However, this has the effect of silencing the warning about other gems as well, that may not be prepared about the bundling. 

>From `ruby/reline` for example: https://github.com/ruby/reline/blob/c90f08f7e308d2f1cdd7cfaf9939fe45ce546fd2/lib/reline/terminfo.rb#L1-L15
Or the `logging` gem: https://github.com/TwP/logging/blob/df41715364f7eb8c65098cd3c3316677ef1f3784/lib/logging.rb#L9-L15

I propose to simply delay the warning to the next require.

GitHub PR at https://github.com/ruby/ruby/pull/11545



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-09-05  6:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-04 14:17 [ruby-core:119041] [Ruby master Bug#20714] Handle optional dependencies in `bundled_gems.rb` Earlopain (A S) via ruby-core
2024-09-04 15:51 ` [ruby-core:119042] " Eregon (Benoit Daloze) via ruby-core
2024-09-04 16:06 ` [ruby-core:119043] " Eregon (Benoit Daloze) via ruby-core
2024-09-04 16:20 ` [ruby-core:119044] " Earlopain (A S) via ruby-core
2024-09-04 16:38 ` [ruby-core:119045] " Eregon (Benoit Daloze) via ruby-core
2024-09-04 20:02 ` [ruby-core:119046] " deivid via ruby-core
2024-09-05  6:24 ` [ruby-core:119056] " Earlopain (A S) via ruby-core
2024-09-05  6:26 ` [ruby-core:119057] " hsbt (Hiroshi SHIBATA) via ruby-core

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 NNTP newsgroup(s).