[Python-ideas] Re: Applications user/system directories functions

2021-12-15 Thread Christopher Barker
On Wed, Dec 15, 2021 at 7:35 PM Finn Mason  wrote:

> 4. Should this also be added to pathlib? I say definitely, probably in the
>> form of class constructors (e.g. Path.user_data()).
>>
>
putting it in pathlib makes a lot of sense, but I wouldn't make them a
bunch of Path classmethods -- why thot their own names, but would return
Path objects?

Despite "flat being better than nested" I kind of like a namespace for the
standar paths"

path.lib.standard_paths.user_data

or some such.

As for the names themselves -- prior art -- I think there were two
packages on PyPi with some of this, if they are popular, let's use those
names.

Here's appdirs:

https://github.com/ActiveState/appdirs

pathlib.appdirs.user_data_dir()

done :-)

-CHB

+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/
>>> 
>>> 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] Re: Applications user/system directories functions

2021-12-15 Thread Finn Mason
On Wed, Dec 15, 2021, 8:32 PM Finn Mason  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 
> wrote:
>
>> On Wed, Dec 15, 2021 at 4:29 PM Christopher Barker 
>> wrote:
>>
>>> On Wed, Dec 15, 2021 at 2:57 PM Neil Girdhar 
>>> 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/
>> 
>> 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 

[Python-ideas] Re: Applications user/system directories functions

2021-12-15 Thread Finn Mason
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()).


--
Finn (Mobile)

On Wed, Dec 15, 2021, 5:35 PM Christopher Barker 
wrote:

> On Wed, Dec 15, 2021 at 4:29 PM Christopher Barker 
> wrote:
>
>> On Wed, Dec 15, 2021 at 2:57 PM Neil Girdhar 
>> 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/
> 
> 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 

[Python-ideas] Re: Applications user/system directories functions

2021-12-15 Thread Christopher Barker
On Wed, Dec 15, 2021 at 4:29 PM Christopher Barker 
wrote:

> On Wed, Dec 15, 2021 at 2:57 PM Neil Girdhar 
> 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/
 
 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] Re: Applications user/system directories functions

2021-12-15 Thread Neil Girdhar
+1 for appdirs.  It's a shame that more projects don't yet use it.

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/
>>  
>> 
>> 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/


[Python-ideas] Re: Applications user/system directories functions

2021-12-15 Thread Barry


> On 15 Dec 2021, at 13:45, JGoutin via Python-ideas  
> 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.

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



> ___
> 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/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/LZP4ISNMJETVHCVMOTQR4YKBRY3RODEU/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Applications user/system directories functions

2021-12-15 Thread JGoutin via Python-ideas
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.
___
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/NVUD2ZVINI5Z3QHYUGOGGQHY67NSYHGV/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Applications user/system directories functions

2021-12-15 Thread Paul Moore
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
 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-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/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/JZ4D2ZLW4XAESJ4EPBB2UWJODTJSNVBZ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Applications user/system directories functions

2021-12-15 Thread Matt del Valle
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:

> 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-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/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/54LEXSHDHC2SXTZWIYMSF7WR3JTDBDAJ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Applications user/system directories functions

2021-12-15 Thread Evpok Padding
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:

> 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-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/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/WPFCHEJMG7OZA5KDBK5J2AIDZHSUQM6I/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Applications user/system directories functions

2021-12-15 Thread JGoutin via Python-ideas
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-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/MHEWO4U6SBDU7OU3JH4A62EWCANDM7I2/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Runtime-accessible attribute docstrings – take 2

2021-12-15 Thread Stephen J. Turnbull
Christopher Barker writes:

 > but it is clear that the whole "are annotations only for typing"
 > question will be made more clear.

Can we please stop posting this?  AFAICS, the basic principle is
absolutely clear.  For the foreseeable future:

1.  Annotations are NOT "only for typing".
2.  Uses of annotations that get in the way of typing will be NOT
adopted or enabled in the Python language, builtins, or stdlib.
3.  typing.Annotated means that there is no conflict between 1 and 2,
although there may be inconvenience, ugliness, or lower
performance implied for some non-typing applications.

Guido and the typing PEP authors have stated 1 (repeatedly!) and 2
(more recently) below.  However, the definition of "typing" may get
clarified, if that's what you mean (runtime vs. static, are
dataclasses a typing use case, etc).

 > Anyway, I had the idea that one could create a subclass of
 > typing.Annotated, and call it "Documented", and then have it do
 > something a little special, while still looking like an Annotated
 > to the Typing system, e.g. get_type_hints().

I imagine this can be done by a Sufficiently Persistent Pythonista,
but I suppose a factory function would be easier.  I have PoC (too
embarrassing to post) given the existence of an open slot in Annotated
instances (see below).

The main problems (as pointed out by multiple Steves) are
- Any *syntax* (language change) for creating docstrings MUST be
  approved by the SC, and given the rejection of PEP 224 (exactly the
  original proposal for "docstrings below attributes and variables")
  and the bikeshedding that already has taken place in this iteration,
  this could take years.
- Any change to help(), which is a builtin, will require SC
  approval, and great care will have to be taken with the design
  i.e. #2 above for sure, and #3 should be minimized.

By #3 be minimized I have in mind that there are probably existing
clients that moved to annotated and expect their strings as the second
argument to Annotated[].  It would be rude to make them move again.
So that kind of convention for the use of Annotated.__metadata__
should be avoided IMO.

Although Annotated can't be subclassed, a minimal, noninvasive, change
to Annotated that makes both #2 and #3 possible would be adding a new
slot __attr_doc__ into which to stuff the docstring.  That could be
done with a class of a different name for experimentation.  This would
give people working out how to use this info in help() a single
protocol for getting the docstring (even if in the end there's a
different protocol used in typing.Annotated, it should be amenable to
abstraction, making adaptation to a new protocol simple).  Another
possibility would be a specific new type DocstringType that could be
placed anywhere in __metadata__ and the first instance would be
considered the docstring for the identifier so Annotated.

I really do think that if we can keep a lid on the bikeshedding this
could be in 3.11.

Note that the DocstringType approach doesn't get around the SC because
we still want to change help() to recognize these docstrings.

___
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/I2URHK5P4HV4JFMA6B6JMJ3LLCACCCFM/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: List comprehension operators

2021-12-15 Thread Ben Rudiak-Gould
If you didn't know, range objects already support most non-mutating list
methods:

>>> fakelist = range(1, 101)
>>> fakelist[-1]
100
>>> fakelist[-10:]
range(91, 101)
>>> 50 in fakelist
True
>>> fakelist.index(50)
49

Range objects are more efficient than lists since they use O(1) memory
instead of O(n), and many of the methods take O(1) time instead of O(n).
___
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/VTRVLDZU35OZEMWITGZU64B6HNQZGWV4/
Code of Conduct: http://python.org/psf/codeofconduct/