Skip to content

Allow loading multiple irb files - #859

Merged
st0012 merged 1 commit into
ruby:masterfrom
hahmed:ha/allow-multiple-irbrb-files
Mar 5, 2024
Merged

st0012 merged 1 commit into
ruby:masterfrom
hahmed:ha/allow-multiple-irbrb-files

Conversation

@hahmed

@hahmed hahmed commented Feb 2, 2024 •

Copy link
Copy Markdown
Contributor

Opening this PR for early feedback, issue: #674

Add the ability to load multiple irb files.

e.g. if user defines an irb file in "/Users/user_name/.irbrc" and inside the project "/Users/user_name/projects/ruby/irb/.irbrc" both configs are loaded.

  • The existing method rc_file is deprecated with a deprecation notice, informing about a new method called rc_files to use instead.
  • In the tests the deprecation notice is displayed for the existing tests test_rc_file and test_rc_file_in_subdir, not sure what we want to do with that, silence?

todo

  • figure out what to do with _history files, do we only want the first one?
  • Add a test for history, EDIT: since we are only getting the first file I did not add a test as there will be no change in behaviour
  • Add a test for rbinfo -- also, do we want to display a comma separated list of rc_files?, EDIT: updated existing test that checks for .irbrc and _irbrc

@st0012

st0012 commented Feb 15, 2024

Copy link
Copy Markdown
Member

figure out what to do with _history files, do we only want the first one?

Probably always at the user level? I can't think of any reason to keep a history file in the project folder, which users need to be careful not to commit 🤔

do we want to display a comma separated list of rc_files?

I think it's fine to separate them with just comma. The info is mainly for issue reporting purpose and we can always improve it later.

Comment thread lib/irb/cmd/irb_info.rb Resolved
@hahmed
hahmed force-pushed the ha/allow-multiple-irbrb-files branch 2 times, most recently from f95e8fe to 57f26ed Compare February 15, 2024 23:12
@hahmed hahmed changed the title [wip] Allow loading multiple .irbrc files Allow loading multiple irb files Feb 15, 2024
@hahmed
hahmed force-pushed the ha/allow-multiple-irbrb-files branch 2 times, most recently from 262026b to 4885d71 Compare February 19, 2024 22:28
@hahmed
hahmed requested a review from st0012 February 19, 2024 22:52
Comment thread lib/irb/command/irb_info.rb Resolved
@hahmed
hahmed force-pushed the ha/allow-multiple-irbrb-files branch from 09e4c67 to d79a4b0 Compare February 21, 2024 22:01
@hahmed
hahmed requested a review from tompng February 21, 2024 22:10
Comment thread test/irb/test_init.rb Resolved
Comment thread lib/irb/init.rb Outdated
def IRB.rc_files(ext = IRBRC_EXT)
if !@CONF[:RC_NAME_GENERATOR]
@CONF[:RC_NAME_GENERATOR] ||= []
existing_rc_files = []

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since it's not actually a collection of files or file paths, but a collection of Procs, I think it should be called existing_rc_file_generators instead. Otherwise the CONF[:RC_NAME_GENERATOR] = existing_rc_files below looks a bit confusing.

Comment thread lib/irb/init.rb Resolved
Comment thread lib/irb/init.rb Outdated
break
end
@CONF[:RC_NAME_GENERATOR] << rcgen
existing_rc_files << rcgen if File.exist?(rcgen.call(IRBRC_EXT))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be ext instead? If it is, then we probably need more cases to cover the case where ext is not rc?

@st0012 st0012 added the enhancement New feature or request label Feb 22, 2024
This allows hierarchy when loading rc files for example both files below
are loaded;

project/.irbrc
~/.irbrc

Co-authored-by: Stan Lo <stan001212@gmail.com>
@hahmed
hahmed force-pushed the ha/allow-multiple-irbrb-files branch from d79a4b0 to 84668c8 Compare February 27, 2024 22:18
Comment thread test/irb/test_init.rb
hash[env] = ENV.delete(env)
end
ENV["HOME"] = @tmpdir = Dir.mktmpdir("test_irb_init_#{$$}")
ENV["HOME"] = @tmpdir = File.realpath(Dir.mktmpdir("test_irb_init_#{$$}"))

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.

by using realpath I avoid the scenario where in tests I was getting files in the absolute or sym link path, this will resolve any symbolic links, example output of rcfiles which caused this issue:

  <["/var/folders/mf/xxf7lzbx2ml7m2dx1dz8fw3c0000gn/T/test_irb_init_5716020240227-57160-q6cm7w/.irbrc",
   "/private/var/folders/mf/xxf7lzbx2ml7m2dx1dz8fw3c0000gn/T/test_irb_init_5716020240227-57160-q6cm7w/.irbrc",
   "/private/var/folders/mf/xxf7lzbx2ml7m2dx1dz8fw3c0000gn/T/test_irb_init_5716020240227-57160-q6cm7w/_irbrc",
   "/private/var/folders/mf/xxf7lzbx2ml7m2dx1dz8fw3c0000gn/T/test_irb_init_5716020240227-57160-q6cm7w/$irbrc"]> was expected to include
  <"/var/folders/mf/xxf7lzbx2ml7m2dx1dz8fw3c0000gn/T/test_irb_init_5716020240227-57160-q6cm7w/_irbrc">.

@hahmed
hahmed requested a review from st0012 March 3, 2024 21:25
@hahmed

hahmed commented Mar 3, 2024

Copy link
Copy Markdown
Contributor Author

@st0012 I think I addressed all the comments, could you take another look please?

@st0012 st0012 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will be a great improvement for IRB. Thank you!

@st0012
st0012 merged commit b53ebc6 into ruby:master Mar 5, 2024
matzbot pushed a commit to ruby/ruby that referenced this pull request Mar 5, 2024
(ruby/irb#859)

This allows hierarchy when loading rc files for example both files below
are loaded;

project/.irbrc
~/.irbrc

ruby/irb@b53ebc6655

Co-authored-by: Stan Lo <stan001212@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants