Feature Request: add support for global config using $XDG_CONFIG_HOME

Open
#2,465 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
cli

Research direction

Start by tracing isort's existing config-file discovery, then read the XDG_CONFIG_HOME and XDG_CONFIG_DIRS specification linked in the issue. Check how pyproject.toml, setup.py, and .git are used to identify a project boundary. Done means the requested XDG locations are supported without changing the current- or project-directory lookup behavior.

Written by the indexing model from the issue text.

Description

I would like to see support for using the XDG directory specification for config files.
https://specifications.freedesktop.org/basedir/latest/

XDG defines a set of standard environment variables in order to provide known locations for various kinds of files.
Regarding config files, $XDG_CONFIG_HOME (defaulted to ~/.config/) is used to set the default location for a user's config files. XDG_CONFIG_DIRS specifies a search path to use if the config file is not found in XDG_CONFIG_HOME.

The benefits of XDG_CONFIG_HOME aka ~/.config are:

  • is that it reduces file system clutter because the user's home directory is not full of dot files
  • it makes it easy to move configuration files to another machine or back them up
  • it certainly makes it very easy to see what programs have a global configuration
  • it allows the user to choose a different location, such as a shared file system

The configuration for a program may either be a single config file in ~/.config/, in which case it should not be hidden. Example would be moving ~/.isort.cfg to ~/.config/isort.cfg
If the configuration for a program is a directory, such as ~/.vim/ it should be a non-hidden directory in ~/.config such as ~/.config/vim.

Note:
I am not proposing changing looking in the current directory or the project directory first. However, I think looking at 25 parent directories is excessive. If the project directory can be recognized then the search should stop there and jump directly to the global config. The project directory can be recognized by the presence of:

  • a pyproject.toml directory
  • a setup.py directory
  • a .git directory

There might also be other ways, but the above is a quick and simple list.

Dominant language
Python
Stars
7k
Forks
838
Avg merge
2d 6h
Merged PRs (30d)
19

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PyCQA/isort

All issues in PyCQA/isort

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.