Applications user/system directories functions

Hello, The idea is to add 3 functions to get "config", "data" and "cache" directories that are commonly used to store application files in user home / system. This look very straightforward to get theses directories path, but in practices it depends on many factors like OS, environnement variables, user or system dir. For instance, with the "config" directory: * Linux, user: os.path.join(os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config")), app_name) * Linux, system: os.path.join("/etc", app_name) * Windows, user: os.path.join(os.path.expandvars("%APPDATA%"), app_name) * Windows, system: os.path.join(os.path.expandvars("%CSIDL_COMMON_APPDATA%"), app_name) For linux, the full spec is here: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html I see many applications that just use "~/.app_name" to not have to handle theses cases. The functions prototypes may look like and may be added to "shutil" (or "os.path" ?): def getcachedir(app_name: str=None, system: bool=False): With * app_name: The application name * system: If the required directory is the systemd directory or user direcotry. This may also be implemented as an external library, but I am not sure I would like add add a dependency to my projects "just for this". I can implement this if people are interested with this feature.

Hi, [xdg](https://pypi.org/project/xdg).xdg_config_home seems to give you the parent of what you need, doesn't it? Cheers, E On Wed, 15 Dec 2021 at 13:47, JGoutin via Python-ideas < python-ideas@python.org> wrote:

There is appdirs which does precisely what you're looking for: https://pypi.org/project/appdirs/ That said, it does seem to be a core bit of functionality that would be nice to have in the os and pathlib modules without needing an external dependency. I'm not going to weigh in on the pros/cons of adding it to the stdlib, I'll leave that to others who I'm sure will have strong opinions on the matter :) On Wed, Dec 15, 2021 at 1:47 PM JGoutin via Python-ideas < python-ideas@python.org> wrote:

https://pypi.org/project/platformdirs/ is intended to cover this sort of requirement. Paul On Wed, 15 Dec 2021 at 13:47, JGoutin via Python-ideas <python-ideas@python.org> wrote:

Hello, Thanks for the suggested packages. "platfromdirs" look to be a fork of "appdirs", both seems to support many OS and cases. That look to be good non stdlib solutions. The "xdg" module seem to only support Linux, but provides more dirs on it.

I wrote this https://pypi.org/project/config-path/ to solve the problem for macOs, windows and unix. There are subtle points to consider on each platform. Barry

Hi, [xdg](https://pypi.org/project/xdg).xdg_config_home seems to give you the parent of what you need, doesn't it? Cheers, E On Wed, 15 Dec 2021 at 13:47, JGoutin via Python-ideas < python-ideas@python.org> wrote:

There is appdirs which does precisely what you're looking for: https://pypi.org/project/appdirs/ That said, it does seem to be a core bit of functionality that would be nice to have in the os and pathlib modules without needing an external dependency. I'm not going to weigh in on the pros/cons of adding it to the stdlib, I'll leave that to others who I'm sure will have strong opinions on the matter :) On Wed, Dec 15, 2021 at 1:47 PM JGoutin via Python-ideas < python-ideas@python.org> wrote:

https://pypi.org/project/platformdirs/ is intended to cover this sort of requirement. Paul On Wed, 15 Dec 2021 at 13:47, JGoutin via Python-ideas <python-ideas@python.org> wrote:

Hello, Thanks for the suggested packages. "platfromdirs" look to be a fork of "appdirs", both seems to support many OS and cases. That look to be good non stdlib solutions. The "xdg" module seem to only support Linux, but provides more dirs on it.

I wrote this https://pypi.org/project/config-path/ to solve the problem for macOs, windows and unix. There are subtle points to consider on each platform. Barry
participants (6)
-
Barry
-
Evpok Padding
-
JGoutin
-
Matt del Valle
-
Neil Girdhar
-
Paul Moore