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

Allow loading multiple irb files #859

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

hahmed
Copy link
Contributor

@hahmed hahmed commented Feb 2, 2024

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
Copy link
Member

st0012 commented Feb 15, 2024

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.

lib/irb/cmd/irb_info.rb Outdated Show resolved Hide 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
lib/irb/command/irb_info.rb Outdated Show resolved Hide 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
test/irb/test_init.rb Outdated Show resolved Hide resolved
lib/irb/init.rb Outdated
if !@CONF[:RC_NAME_GENERATOR]
@CONF[:RC_NAME_GENERATOR] ||= []
existing_rc_files = []
Copy link
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.

lib/irb/init.rb Show resolved Hide resolved
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
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
@@ -11,7 +11,7 @@ def setup
@backup_env = %w[HOME XDG_CONFIG_HOME IRBRC].each_with_object({}) do |env, hash|
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
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
Copy link
Contributor Author

hahmed commented Mar 3, 2024

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

Copy link
Member

@st0012 st0012 left a comment

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
29 checks passed
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
Development

Successfully merging this pull request may close these issues.

3 participants