mise icon indicating copy to clipboard operation
mise copied to clipboard

Allow global tool-versions file to be in config dir from a setting in the config.toml file

Open triarius opened this issue 2 years ago • 2 comments

In this PR, I introduce a configuration value that changes the location of the global tool-versions file to be a sibling of the config.toml file. By default, the location is ~/.config/rtx/tool-versions (on linux). The config value is false by default to maintain backwards compatibility.

There are a few reasons one would want to do this. One is to eliminate yet another dotfile cluttering the $HOME directory. Motivated by this, I have expressed a more principled reason below:

The ~/.tool-verisons file is unlike the .tool-versions files in other directories in that it controls the versions of rtx managed executables in directories that are not descendants in its directory hierarchy. For example, if you're on a linux system and cd to the directory /tmp, rtx will set the path to match what is in $HOME/.tool-versions, even though neither directory is a descendant of the other. This is an exception to the usual rule that rtx will search all ancestors of the current directory and set the path according to the .tool-versions it finds.

Of course, this behaviour is intentional because ~/.tool-versions is the global tool versions file and such global configuration of tool versions is a feature that many users would want. However, I think it is important to separate the concepts because there is a collision between the global .tool-versions file and the local .tool-versions file for the $HOME directory. In my opinion, this collision warrants a different location for the global tool versions file. Furthermore, the global tool-versions file belongs in the same directory as the other global configuration in the config.toml file, so I have decided not to make the location configurable.

Something similar used to be achievable in asdf by setting the environment variable ASDF_DEFAULT_TOOL_VERSIONS_FILENAME, but it was changed in asdf to only affect the filename and not the path. I suspect rtx inherited this change as the equivalent RTX_DEFAULT_TOOL_VERSIONS_FILENAME behaves similarly. In any case, there are a few comments and issues floating around the asdf issue tracker by people that used to use that env variable to change the location of the global tool-versions file, for example: https://github.com/asdf-vm/asdf/issues/1365. I think this PR will address some, but not call of those concerns. In particular, due to the principles I expressed above, I don't think it is appropriate to allow the global tool versions file to be located in an arbitrary location.

PS: I added and ran unit tests, but the running the e2e tests locally did not work for me, even on the main branch.

triarius avatar Feb 21 '23 21:02 triarius

I realize this isn't clear or working yet, but my intention is that config.toml could store what's in .tool-versions as the global configuration so that you wouldn't need a global .tool-versions file.

jdx avatar Feb 21 '23 22:02 jdx

Codecov Report

Base: 81.39% // Head: 81.13% // Decreases project coverage by -0.27% :warning:

Coverage data is based on head (1dbe961) compared to base (7f68e71). Patch coverage: 76.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #171      +/-   ##
==========================================
- Coverage   81.39%   81.13%   -0.27%     
==========================================
  Files          90       90              
  Lines        2860     2878      +18     
==========================================
+ Hits         2328     2335       +7     
- Misses        532      543      +11     
Impacted Files Coverage Δ
src/cli/settings/unset.rs 100.00% <ø> (ø)
src/config/config_file/mod.rs 80.00% <28.57%> (-9.59%) :arrow_down:
src/config/settings.rs 82.19% <85.71%> (+0.37%) :arrow_up:
src/cli/global.rs 95.00% <100.00%> (-5.00%) :arrow_down:
src/config/config_file/rtxrc.rs 78.04% <100.00%> (+0.21%) :arrow_up:
src/config/mod.rs 74.69% <100.00%> (+1.28%) :arrow_up:
src/env.rs 72.11% <100.00%> (-1.16%) :arrow_down:
src/config/config_file/tool_versions.rs 92.20% <0.00%> (-2.60%) :arrow_down:
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Feb 21 '23 22:02 codecov[bot]

Cool, https://github.com/jdxcode/rtx/pull/253 mainly covers this use case now. It would be nice if we didn't have to resort to environment variables, but this is good enough until it lands in the main config file.

triarius avatar Mar 04 '23 03:03 triarius