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 Gem.default_user_install
to be overridden
#7243
Conversation
After tinkering with this, I am less interested in the PR, while there still might be some merit. Let me explain. There are historically two ways we used to configure RubyGems on Fedora for user installation:
For the first case, the situation is similar as always specifying For the second case, the So the question is if it is worth of it. The small benefit is that this PR would help to resolve one small corner case, where the chances this would bother anybody are really small. OTOH, from the code readability POV, I think something like this would help and why not to make it configurable then? At this point, I'm going to remove the WIP, because it probably is good as it is. If it is merged, then fine. If it is closed, then fine as well. Any other feedback is welcome as well 👼 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like an improvement to the code regardless. It's much easier to read.
Hmm, this was passing. I'm thinking there's a conflict between this and something we merged. Did I mess up the conflict resolution? |
Yeah, not as pretty anymore but after the fix in #7255, you now want diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 6eaf110e28..4c65468136 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -684,7 +684,7 @@ def process_options # :nodoc:
# * `true`: `--user-install`
# * `false`: `--no-user-install` and
# * `nil`: option was not specified
- if options[:user_install] || Gem.auto_user_install
+ if options[:user_install] || (options[:user_install].nil? && Gem.auto_user_install)
@gem_home = Gem.user_dir
end or something equivalent. |
Ha, you already fixed it! 😃 |
Exactly. I updated it through a comment, though now I've made the commits fairly ugly in this PR. |
Let me squash back to one commit, it's good to stress our CI a bit now that we merged #7267 :) |
If you are happy even with the naming etc, them I am also happy 😊 |
68b4ee9
to
87e33a3
Compare
Yeah, I'm also not sure it's the most descriptive name, maybe |
d398eee
to
f51bb9b
Compare
Ok, I updated the branch to fix my merge mistake and to change the method name. cc @voxik |
Gem.fallback_to_user_install?
to be overridden.
With the method name, I was looking for consistency with the Otherwise it LGTM |
I think we're coming up with a pretty neat version of this. How about this last tweak? diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 4c65468136..124b3000d2 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -675,21 +675,17 @@ def process_options # :nodoc:
@build_args = options[:build_args]
- @gem_home = @install_dir
-
- unless @gem_home
- # `--build-root` overrides `--user-install` and auto-user-install
- if @build_root.nil?
- # Please note that `options[:user_install]` might have three states:
- # * `true`: `--user-install`
- # * `false`: `--no-user-install` and
- # * `nil`: option was not specified
- if options[:user_install] || (options[:user_install].nil? && Gem.auto_user_install)
- @gem_home = Gem.user_dir
- end
+ @gem_home = @install_dir || Gem.dir
+
+ # `--install-dir` and `--build-root` override `--user-install` and `Gem.fallback_to_user_install?`
+ if @install_dir.nil? && @build_root.nil?
+ # Please note that `options[:user_install]` might have three states:
+ # * `true`: `--user-install`
+ # * `false`: `--no-user-install` and
+ # * `nil`: option was not specified
+ if options[:user_install] || (options[:user_install].nil? && Gem.fallack_to_user_install?)
+ @gem_home = Gem.user_dir
end
-
- @gem_home ||= Gem.dir
end
# If the user has asked for the gem to be installed in a directory that is |
So you mean omitting the question mark for consistency? I'm good with that too. |
How about
And that would mean that the old behavior is in place. This could be possible implementation for Fedora, because we do this almost forever via different means.
IOW the "fallback" is implied by the current implementation, but it might be changed by operating_system.rb or so. |
Ok with me! |
How about my suggestion at #7243 (comment) @voxik. Do you think it's an improvement? |
This ^^ is the part I am most concerned with. IMHO, the current version can be read as it is written. E.g.
But with what is proposed, I read the code such as:
This disturbs the flow. It does not click for me. And I literally spend hours to wrap my head around. |
I see That's why it feels a bit weird to have a comment about Anyways, I also get the way you look at it, let's discard my suggestion and move on with what we have. |
@voxik Want to do the update? I had fixed the branch to solve my conflict resolution but I don't want to keep force pushing your branches. 😉 If we switch the name to |
I was considering to remove the comment. To me, the comment was a sign of unreadable code. But since it was not mine, I decided to leave it there after all.
👍 Thx |
I'd be more then happy, but I won't do it sooner then tomorrow. If you like, please be my guest and force push my branch for one last time 😊 |
For Ruby re-distributors, automatic user-install might be the right default. Therefore printing warning about installing into user directory is not always desirable. Let the default_user_install method be customizable.
f51bb9b
to
2320dba
Compare
Gem.fallback_to_user_install?
to be overridden.Gem.default_user_install
to be overridden
@voxik Done. |
Nice work team! |
Funny how the code I suggested in #7243 (comment) is exactly what we had before #7236, I had not noticed 😅. I came up with just one more attempt trying to please everyone, inspired on @skipkayhil's suggestion at #7236 (comment). |
For Ruby re-distributors, the "auto-user-install" might be the right default. Therefore printing warning about installing into user directory is not always desirable. Let the "auto-user-install" feature to be customizable.
I have mentioned this is coming in #7236. But I have not really tested this yet.
And of course, the naming ... Not sure if the
auto_user_install
is the most descriptive method name.Also, there is not test. Not sure if there should be one thought, because this will work only as long as it is not overridden by the Ruby executing the test suite. With such test case, we might end up with similar issues as #7187