Skip to content

Respect XDG_CONFIG_HOME in _get_user_dirs_folder#453

Merged
gaborbernat merged 3 commits intotox-dev:mainfrom
bysiber:fix/unix-user-dirs-xdg-config
Feb 23, 2026
Merged

Respect XDG_CONFIG_HOME in _get_user_dirs_folder#453
gaborbernat merged 3 commits intotox-dev:mainfrom
bysiber:fix/unix-user-dirs-xdg-config

Conversation

@bysiber
Copy link
Contributor

@bysiber bysiber commented Feb 20, 2026

Summary

_get_user_dirs_folder hardcodes ~/.config as the location for reading the user-dirs.dirs configuration file, ignoring the XDG_CONFIG_HOME environment variable.

Problem

The XDG Base Directory Specification defines $XDG_CONFIG_HOME as the base directory for user-specific configuration files, defaulting to $HOME/.config only when unset or empty. The _get_user_dirs_folder function always reads from ~/.config/user-dirs.dirs, so users who have set a custom XDG_CONFIG_HOME will have the wrong config file read (or the file won't be found at all).

This is especially inconsistent since the rest of the Unix implementation correctly respects XDG_CONFIG_HOME for user_config_dir.

Fix

Read XDG_CONFIG_HOME from the environment first, falling back to ~/.config when unset or empty:

config_home = os.environ.get("XDG_CONFIG_HOME", "").strip() or os.path.expanduser("~/.config")
user_dirs_config_path = Path(config_home) / "user-dirs.dirs"

The _get_user_dirs_folder function hardcodes ~/.config as the
location for user-dirs.dirs, ignoring XDG_CONFIG_HOME. According
to the XDG Base Directory Specification, XDG_CONFIG_HOME should be
checked first, falling back to ~/.config only when unset or empty.

This is particularly relevant for users who have a custom
XDG_CONFIG_HOME set, as the function would read the wrong
user-dirs.dirs file (or fail to find it).
Copy link
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

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

Tests?

Verify that user-dirs.dirs is read from a custom XDG_CONFIG_HOME
directory instead of always using ~/.config.
@bysiber
Copy link
Contributor Author

bysiber commented Feb 21, 2026

Added a test that sets XDG_CONFIG_HOME to a custom directory and verifies user-dirs.dirs is read from there instead of ~/.config.

@gaborbernat gaborbernat enabled auto-merge (squash) February 23, 2026 08:27
@gaborbernat gaborbernat merged commit 57c7eae into tox-dev:main Feb 23, 2026
29 checks passed
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