On Wed, Dec 15, 2021, 8:32 PM Finn Mason <finnjavie...@gmail.com> wrote:

> It would be a good idea to add something like appdirs to the stdlib. Maybe
> something like os.path.userdata() (as an example name). I have four
> questions:
>
> 1. What should the functions be called, and module should they go in? I
> personally say os.path module, with names such as userdata() for
> consistency with the rest of the os module.
>
> 2. Should the functions take the app name and author, or just return the
> base path, e.g. ~/. local/share? The latter makes more sense to me if I had
> to pick one, but my personal recommendation would be to make the name and
> author optional arguments, so userdata() returned (on Linux)
> ~/.local/share, but userdata(appname="foo") returned ~/.local/share/foo.
> This seems to be the behavior of the appdirs functions.
>
> 3. Should we include something like the AppDirs class, which is a wrapper
> of sorts for the functions? I personally say no, it's not necessary or
> important.
>
> 4. Should this also be added to pathlib? I say definitely, probably in the
> form of class constructors (e.g. Path.user_data()).
>

Tildes would be expanded, of course. (I forgot to mention that.)



--
Finn (Mobile)


--
> Finn (Mobile)
>
> On Wed, Dec 15, 2021, 5:35 PM Christopher Barker <python...@gmail.com>
> wrote:
>
>> On Wed, Dec 15, 2021 at 4:29 PM Christopher Barker <python...@gmail.com>
>> wrote:
>>
>>> On Wed, Dec 15, 2021 at 2:57 PM Neil Girdhar <mistersh...@gmail.com>
>>> wrote:
>>>
>>>> +1 for appdirs.  It's a shame that more projects don't yet use it.
>>>>
>>>
>> I agree -- I've wanted something like that for years in the stdlib.
>>
>> wxPython has wx.StandardPaths -- and it's really handy. But a wrapper
>> around a C++ version, so not useful outside of wx.
>>
>> -CHB
>>
>>
>>>
>>>> On Wednesday, December 15, 2021 at 9:03:07 AM UTC-5 Matt del Valle
>>>> 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...@python.org> wrote:
>>>>>
>>>>>> 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.
>>>>>> _______________________________________________
>>>>>> Python-ideas mailing list -- python...@python.org
>>>>>> To unsubscribe send an email to python-id...@python.org
>>>>>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>>>>>> Message archived at
>>>>>> https://mail.python.org/archives/list/python...@python.org/message/MHEWO4U6SBDU7OU3JH4A62EWCANDM7I2/
>>>>>> <https://mail.python.org/archives/list/python-ideas@python.org/message/MHEWO4U6SBDU7OU3JH4A62EWCANDM7I2/>
>>>>>> Code of Conduct: http://python.org/psf/codeofconduct/
>>>>>>
>>>>> _______________________________________________
>>>> Python-ideas mailing list -- python-ideas@python.org
>>>> To unsubscribe send an email to python-ideas-le...@python.org
>>>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>>>> Message archived at
>>>> https://mail.python.org/archives/list/python-ideas@python.org/message/IV3W2LRZ2KRYERYOYOGYWLI4TO7NXUHI/
>>>> Code of Conduct: http://python.org/psf/codeofconduct/
>>>>
>>>
>>>
>>> --
>>> Christopher Barker, PhD (Chris)
>>>
>>> Python Language Consulting
>>>   - Teaching
>>>   - Scientific Software Development
>>>   - Desktop GUI and Web Development
>>>   - wxPython, numpy, scipy, Cython
>>>
>>
>>
>> --
>> Christopher Barker, PhD (Chris)
>>
>> Python Language Consulting
>>   - Teaching
>>   - Scientific Software Development
>>   - Desktop GUI and Web Development
>>   - wxPython, numpy, scipy, Cython
>> _______________________________________________
>> Python-ideas mailing list -- python-ideas@python.org
>> To unsubscribe send an email to python-ideas-le...@python.org
>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>> Message archived at
>> https://mail.python.org/archives/list/python-ideas@python.org/message/PNFWSYYXR5MXVXWOKEV2B26TABVZYL6A/
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/APVEHE4R3Q3LPFJITPG37ERQUQLBKUN6/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to