Allow user to override ~/.bundle with environment variables #6024
Conversation
Recognize new environment variables, with the following fallbacks: $BUNDLE_USER_HOME -> $HOME/.bundle $BUNDLE_USER_CACHE -> $BUNDLE_USER_HOME/cache $BUNDLE_USER_CONFIG -> $BUNDLE_USER_HOME/config $BUNDLE_USER_PLUGIN -> $BUNDLE_USER_HOME/plugin TODOs: - Error handling in Bundler.user_bundle_path when an invalid option is passed - Add tests (see rubygems@47fbe99) - Draft PR with reference to GitHub issue numbers (not linked here as per contributing guidelines) + Issue: 4333 + Pull request: 5787
Mostly unmodified tests from PR 5787 (not linked here to respect contribution guidelines).
Thanks for opening a pull request and helping make Bundler better! Someone from the Bundler team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality. We use Travis CI to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of Travis CI in the PR status window below. If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #bundler channel on Slack. For more information about contributing to the Bundler project feel free to review our CONTRIBUTING guide |
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.
This seems reasonable to me. Thoughts @colby-swandale @indirect ?
lib/bundler.rb
Outdated
@@ -193,8 +193,26 @@ def tmp_home_path(login, warning) | |||
raise e.exception("#{warning}\nBundler also failed to create a temporary home directory at `#{path}':\n#{e}") | |||
end | |||
|
|||
def user_bundle_path | |||
Pathname.new(user_home).join(".bundle") | |||
def user_bundle_path(dir="home") |
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.
space around =
I have a few issues with this PR, mainly it's making things relating to the bundle path pretty confusing but this can be addressed in a later PR. @bundlerbot r+ |
📌 Commit b3108fa has been approved by |
Allow user to override ~/.bundle with environment variables ### What was the end-user problem that led to this PR? As in #4333, users wanted a way to make Bundler respect the XDG specification. ### What was your diagnosis of the problem? The directory `~/.bundle` was hard-coded and could not be configured. ### What is your fix for the problem, implemented in this PR? Allow users to configure `~/.bundle` and its relevant sub-directories by setting environment variables. The environment variables and their fallbacks are as follows: | variable | fallback if unset | |---|---| | `BUNDLE_USER_HOME` | `$HOME/.bundle` | | `BUNDLE_USER_CACHE` | `$BUNDLE_USER_HOME/cache` | | `BUNDLE_USER_CONFIG` | `$BUNDLE_USER_HOME/config` | | `BUNDLE_USER_PLUGIN` | `$BUNDLE_USER_HOME/plugin` | ### Why did you choose this fix out of the possible options? Unlike #5787, This solution is not specific to the XDG specification. Users have all kinds of setups, and this is a very general system for allowing them to configure their development machines however they need. It tries to keep all files created by Bundler in the same place (as per #5787 (comment)), but allows the user to override that convention _if they really want to and they know what they are doing_. If they want to use XDG for everything, they can do it by explicitly setting the `BUNDLE_USER_*` variables to the equivalent `XDG_DATA_*`. If they just want to get `.bundle` out of their home directory, they can do it by setting `BUNDLE_USER_HOME` and don't have to mess with the more specific env variables if they don't want to. To me, this solution strikes the right balance between "fine-grained control for power users" and "simple, sane defaults for everyone else". Please let me know if my tests can be improved. My only Ruby experience so far has been writing Homebrew formulas and configuring Jekyll, so I'm sure I have a lot to learn.
☀️ Test successful - status-travis |
@colby-swandale what issues do you have in mind? Obviously I'm happy to have my PR merged ("it works for me"), but I don't want to be responsible for any design debt in the future. |
@gwerbin The discussion above (mainly the env var fallbacks table) seemed to imply that the vars all indicate directories.
The code seems to indicate that Is this the case? Can this be documented somewhere? |
@jasonkarns the relevant diff from my patch corresponding to that snippet is here: e6cc7a2#diff-75219bd6bc0defc0e7f4ba322d92f950 As you can see, I didn't change anything that was previously stored under It would have been more correct if I had written:
In the documentation it's implied but not explicitly stated that |
@gwerbin cool. Since this feature was significantly driven by (but not solely by) the XDG request, I was easily mislead by the directories vs files. Was having an issue with Anyway, thanks for the clarification. |
Welp, I've found my problem!!! This apparently hasn't been released yet? I figured that since it was merged in September, and both 1.16.0 and 1.16.1 were released in October, December respectively, that this would have been included. Does anyone have any rough ideas on when this might land? |
@jasonkarns I'm pretty confused about the whole state of this, too. I also checked this a while ago and assumed the change wasn't shipped because it failed to fix the problem people reported in #4333, and devs wanted to rework this before officially releasing it. |
We cut the 1.16 branch before this was merged, and have been focusing on getting the 2.0 train out the door, and tend to not backport new features after a branch cut |
@segiddins Is there a chance to fix #4333 before 2.0 is released? |
Since its a feature rather than a bug fix, it's likely it wont ship before 2.0 |
Sorry, my comment could be interpreted two ways. What I meant is whether #4333 will be actually fixed in 2.0. |
Allow user to override ~/.bundle with environment variables ### What was the end-user problem that led to this PR? As in #4333, users wanted a way to make Bundler respect the XDG specification. ### What was your diagnosis of the problem? The directory `~/.bundle` was hard-coded and could not be configured. ### What is your fix for the problem, implemented in this PR? Allow users to configure `~/.bundle` and its relevant sub-directories by setting environment variables. The environment variables and their fallbacks are as follows: | variable | fallback if unset | |---|---| | `BUNDLE_USER_HOME` | `$HOME/.bundle` | | `BUNDLE_USER_CACHE` | `$BUNDLE_USER_HOME/cache` | | `BUNDLE_USER_CONFIG` | `$BUNDLE_USER_HOME/config` | | `BUNDLE_USER_PLUGIN` | `$BUNDLE_USER_HOME/plugin` | ### Why did you choose this fix out of the possible options? Unlike #5787, This solution is not specific to the XDG specification. Users have all kinds of setups, and this is a very general system for allowing them to configure their development machines however they need. It tries to keep all files created by Bundler in the same place (as per #5787 (comment)), but allows the user to override that convention _if they really want to and they know what they are doing_. If they want to use XDG for everything, they can do it by explicitly setting the `BUNDLE_USER_*` variables to the equivalent `XDG_DATA_*`. If they just want to get `.bundle` out of their home directory, they can do it by setting `BUNDLE_USER_HOME` and don't have to mess with the more specific env variables if they don't want to. To me, this solution strikes the right balance between "fine-grained control for power users" and "simple, sane defaults for everyone else". Please let me know if my tests can be improved. My only Ruby experience so far has been writing Homebrew formulas and configuring Jekyll, so I'm sure I have a lot to learn. (cherry picked from commit e6cc7a2)
* 1-17-stable: (38 commits) Version 1.17.0 with changelog Merge #6754 Version 1.17.0.pre.2 with changelog fix failing bundle remove specs Still document the `--force` option scope specs testing bundler 2 deprecations to bundler 1 only Merge #6718 Merge #6707 Merge #6702 Merge #6316 Auto merge of #6447 - agrim123:agr-update-error-message, r=segiddins Auto merge of #6513 - agrim123:agr-bundler-remove, r=indirect Auto merge of #6318 - jhawthorn:fix_incorrect_test_in_requires_sudo, r=segiddins Auto merge of #6450 - bundler:segiddins/bundle-binstubs-all, r=colby-swandale Auto merge of #6024 - gwerbin:custom-user-bundle-dir, r=colby-swandale Version 1.17.0.pre.1 with changelog Auto merge of #5964 - bundler:colby/deprecate-viz-command, r=segiddins Auto merge of #5986 - bundler:seg-jobs-count, r=indirect Auto merge of #5995 - bundler:seg-gvp-major, r=indirect Auto merge of #5803 - igorbozato:path_relative_to_pwd, r=indirect ...
6885: Don't check for the existence of a writable home directory if BUNDLE_USER_HOME is set r=deivid-rodriguez a=jturkel #6024 added support for specifying an alternate bundler home directory via the `BUNDLE_USER_HOME` environment variable. Unfortunately bundler still checks for a writable user home directory even if the `BUNDLE_USER_HOME` override is specified resulting in warnings like this: ``` `/home/appuser` is not a directory. Bundler will use `/tmp/bundler/home/unknown' as your home directory temporarily. ``` The fix for this problem is to only evaluate bundler path fallbacks if environment variable overrides are not specified. Co-authored-by: Joel Turkel <jturkel@salsify.com>
What was the end-user problem that led to this PR?
As in #4333, users wanted a way to make Bundler respect the XDG specification.
What was your diagnosis of the problem?
The directory
~/.bundle
was hard-coded and could not be configured.What is your fix for the problem, implemented in this PR?
Allow users to configure
~/.bundle
and its relevant sub-directories by setting environment variables. The environment variables and their fallbacks are as follows:BUNDLE_USER_HOME
$HOME/.bundle
BUNDLE_USER_CACHE
$BUNDLE_USER_HOME/cache
BUNDLE_USER_CONFIG
$BUNDLE_USER_HOME/config
BUNDLE_USER_PLUGIN
$BUNDLE_USER_HOME/plugin
Why did you choose this fix out of the possible options?
Unlike #5787, This solution is not specific to the XDG specification. Users have all kinds of setups, and this is a very general system for allowing them to configure their development machines however they need. It tries to keep all files created by Bundler in the same place (as per #5787 (comment)), but allows the user to override that convention if they really want to and they know what they are doing.
If they want to use XDG for everything, they can do it by explicitly setting the
BUNDLE_USER_*
variables to the equivalentXDG_DATA_*
. If they just want to get.bundle
out of their home directory, they can do it by settingBUNDLE_USER_HOME
and don't have to mess with the more specific env variables if they don't want to.To me, this solution strikes the right balance between "fine-grained control for power users" and "simple, sane defaults for everyone else".
Please let me know if my tests can be improved. My only Ruby experience so far has been writing Homebrew formulas and configuring Jekyll, so I'm sure I have a lot to learn.