Skip to content

Use a platform-appropriate location for user configuration#215

Merged
charliermarsh merged 1 commit into
astral-sh:mainfrom
andersk:config_dir
Sep 17, 2022
Merged

Use a platform-appropriate location for user configuration#215
charliermarsh merged 1 commit into
astral-sh:mainfrom
andersk:config_dir

Conversation

@andersk
Copy link
Copy Markdown
Contributor

@andersk andersk commented Sep 16, 2022

Comment thread src/pyproject.rs Outdated

fn find_user_pyproject_toml() -> Option<PathBuf> {
dirs::home_dir().map(|path| path.join(".ruff"))
dirs::config_dir().map(|path| path.join("ruff"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's more typical for users to write to the config dir than the home dir? To me the config dir paths seem more like internal than user-facing config (e.g., /Users/Alice/Library/Application Support).

I think the ideal IMO is to mimic Black's behavior:

Screen Shot 2022-09-16 at 5 59 47 PM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I would also be comfortable getting rid of the global config and only supporting local pyproject.toml, if this is causing problems.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 called config.toml I guess in the global case but I don't feel strongly.)
  • macOS: ~/Library/Application Support/ruff/pyproject.toml? (I'd prefer ~/Library/Preferences but I don't feel strongly enough to workaround the dirs module.)
  • Windows: %APPDATA%\ruff\pyproject.toml?

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And portable (can copy into projects if needed).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants