Project

General

Profile

Bug #15206

require_relative in std_lib

Added by marcandre (Marc-Andre Lafortune) 2 months ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:89291]

Description

I noticed that there are some require for internal files in lib/. Ideally, they would be using require_relative instead. This is faster and more explicit.

Note: require_relative had a potential issue with symlinks that was fixed in 2.5, so libraries that might be loaded from earlier Ruby, like rubygems, can not yet be updated.

I've created a PR and would like to know if there are comments / objections / things I'm missing.


Related issues

Is duplicate of Ruby trunk - Feature #8781: Use require_relative() instead of require() if possibleClosed

Associated revisions

Revision e859e668
Added by marcandre (Marc-Andre Lafortune) about 1 month ago

lib/*: Prefer require_relative over require.

[#15206] [Fix GH-1976]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 65505
Added by marcandre (Marc-Andre Lafortune) about 1 month ago

lib/*: Prefer require_relative over require.

[#15206] [Fix GH-1976]

Revision b9d42af0
Added by marcandre (Marc-Andre Lafortune) about 1 month ago

lib/*: Prefer require_relative over require, remove explicit extension

[#15206] [Fix GH-1976]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 65506
Added by marcandre (Marc-Andre Lafortune) about 1 month ago

lib/*: Prefer require_relative over require, remove explicit extension

[#15206] [Fix GH-1976]

Revision 6b1e4251
Added by nobu (Nobuyoshi Nakada) about 1 month ago

lib/cgi/util.rb: use require

  • lib/cgi/util.rb: reverted r65505. require_relative does not work for cgi/escape.so, as extension libraries are placed in other directories than ruby libraries. [Bug #15206]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65511 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 65511
Added by nobu (Nobuyoshi Nakada) about 1 month ago

lib/cgi/util.rb: use require

  • lib/cgi/util.rb: reverted r65505. require_relative does not work for cgi/escape.so, as extension libraries are placed in other directories than ruby libraries. [Bug #15206]

Revision 65514
Added by stomar (Marcus Stollsteimer) about 1 month ago

lib/racc/parser.rb: use require for racc/cparse

  • lib/racc/parser.rb: reverted r65505. require_relative does not work for racc/cparse.so, as extension libraries are placed in other directories than Ruby libraries.

History

#1 [ruby-core:89296] Updated by MSP-Greg (Greg L) 2 months ago

The Appveyor run on the PR passed.

Appveyor testing has been intermittently failing. With parallel/multi testing (test-all and/or test-spec), there can be a lot more files being checked and possibly loaded. Considering more than one CI VM may be exist on a system, and they may share drives, anything that lowers disk I/O is good.

#2 Updated by shyouhei (Shyouhei Urabe) 2 months ago

  • Is duplicate of Feature #8781: Use require_relative() instead of require() if possible added

#3 Updated by nobu (Nobuyoshi Nakada) about 1 month ago

  • Status changed from Open to Closed

Applied in changeset trunk|r65511.


lib/cgi/util.rb: use require

  • lib/cgi/util.rb: reverted r65505. require_relative does not work for cgi/escape.so, as extension libraries are placed in other directories than ruby libraries. [Bug #15206]

#4 [ruby-core:89701] Updated by stomar (Marcus Stollsteimer) about 1 month ago

For lib/racc/parser.rb I reverted this in r65514 for the require of racc/cparse.so (similar to r65511 for cgi/escape).

Possibly there might be other C extensions that are required from within /lib, where require_relative would not work?

(I only had a quick look into /lib and /ext, and racc was as an obvious other case, besides cgi, where this problem might occur.)

PS. The LoadError for racc/cparse is not that obvious because it is rescued and there is a Ruby fallback.

#5 [ruby-core:89727] Updated by marcandre (Marc-Andre Lafortune) about 1 month ago

Oh, good catch, I should have thought of that...

I modified my script to check if the path with .rb actually exists and it came back with only these two exceptions.

#6 [ruby-core:89750] Updated by znz (Kazuhiro NISHIYAMA) about 1 month ago

I revert examples in comment and replace numeric features too at r65548.

Also available in: Atom PDF