Description
Hi, and thanks for platformdirs
.
After using the library in a cross-platform Python application, I've noticed that it ignores common environment variable overrides that define directory locations on most systems. This includes:
TMPDIR
,TEMP
,TMP
on Unix/Linux/macOSXDG_CONFIG_HOME
,XDG_DATA_HOME
,XDG_CACHE_HOME
on Linux- Any user-specified overrides for
Documents
,Downloads
, etc.
Example: Temp Directory
import os
from platformdirs import PlatformDirs
os.environ["TMPDIR"] = "/custom/tmp"
dirs = PlatformDirs("MyApp", "MyCompany")
print(dirs.user_cache_dir) # Does NOT reflect TMPDIR override
Compare that with:
import tempfile
print(tempfile.gettempdir()) # Respects TMPDIR
Example: XDG Override Ignored
export XDG_CONFIG_HOME=/tmp/testconfig
python -c "from platformdirs import PlatformDirs; print(PlatformDirs('a', 'b').user_config_dir)"
# Still prints ~/.config/a
Expected Behavior
platformdirs
should:
- Use environment variable overrides as per platform conventions
- Match the behavior of
tempfile.gettempdir()
(for temp dirs) - Match freedesktop spec on Linux (for XDG-based paths)
Current Result
The library hardcodes the path logic and doesn't reflect system/user overrides, making it unsuitable for any situation where the environment is customized — which is very common in packaging, CI/CD, containerized apps, multi-user systems, or advanced user environments.
Suggested Fix / Feature Request
- Fall back to current logic only if the environment variable is unset.
- Document clearly how the library deals with environment overrides.
- Optionally expose a
temp_dir
property that usestempfile.gettempdir()
.
Conclusion
In its current state, platformdirs
is nearly useless for real-world use cases where configuration directories, data paths, or temporary locations are customized by the environment. I'd strongly suggest making it respect the standard overrides, or at least make this behavior configurable.
Thanks for considering this!