Use a platform-appropriate location for user configuration#215
Conversation
|
|
||
| fn find_user_pyproject_toml() -> Option<PathBuf> { | ||
| dirs::home_dir().map(|path| path.join(".ruff")) | ||
| dirs::config_dir().map(|path| path.join("ruff")) |
There was a problem hiding this comment.
There was a problem hiding this comment.
(I would also be comfortable getting rid of the global config and only supporting local pyproject.toml, if this is causing problems.)
There was a problem hiding this comment.
I did some investigation into Black’s behavior. psf/black#1899 says it was inherited from pycodestyle. PyCQA/pycodestyle@b1ada24 says it fixed a TypeError on Windows (PyCQA/pycodestyle#95)—but the part that actually fixed the TypeError was switching from os.getenv("HOME") to os.expanduser('~'), so that doesn’t explain the point of using ~\.pep8 on Windows.
I can say as a Linux user that an XDG path $XDG_CONFIG_HOME/foo or ~/.config/foo is more idiomatic for modern tools than ~/.foo. Windows users don’t expect to use dotfiles at all—they aren’t hidden and they’re awkward to deal with in the UI, so ~\.foo seems like a very weird choice. I’m not sure what macOS users expect.
There was a problem hiding this comment.
If we want ~/.config/ruff on all platforms, we could use xdg::BaseDirectories::new().ok().and_then(|dirs| dirs.find_config_file("ruff")) from the xdg crate.
There was a problem hiding this comment.
I think for macOS I'd expect ~/.ruff, so if we can do that and then ~/.config/ruff for Linux (and then ~/ruff or whatever you like for Windows), that would be awesome.
There was a problem hiding this comment.
Wow great collation! Thanks for doing that. It seems like in each case, they're storing a configuration file within those directories rather than as a dotfile? I.e., there's a config.toml or config.ini or whatever within the directory. So maybe we do this?
- Linux:
XDG ~/.config/ruff/pyproject.toml? (Would be nice if this was calledconfig.tomlI guess in the global case but I don't feel strongly.) - macOS:
~/Library/Application Support/ruff/pyproject.toml? (I'd prefer~/Library/Preferencesbut I don't feel strongly enough to workaround thedirsmodule.) - Windows:
%APPDATA%\ruff\pyproject.toml?
What do you think?
There was a problem hiding this comment.
Sounds good to me. Updated.
An advantage of the pyproject.toml name is that it makes it obvious that the format is the same (e.g. a [tool.ruff] section is still expected).
There was a problem hiding this comment.
And portable (can copy into projects if needed).
There was a problem hiding this comment.
By the way, I noticed that virtualenv --help prints its config file location, which is a nice discoverability touch. I tried to do this with clap’s after_help, but it seems you can only use an owned String there in the Git version of clap with the string feature, so we should revisit that when clap 4 is released.
See https://docs.rs/dirs/4.0.0/dirs/fn.config_dir.html. Signed-off-by: Anders Kaseorg <andersk@mit.edu>

See https://docs.rs/dirs/4.0.0/dirs/fn.config_dir.html.