classification
Title: pathlib missing Path.expandvars(env=os.environ)
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Alain.Mellan, berker.peksag, pitrou, serhiy.storchaka, tds333
Priority: normal Keywords: patch

Created on 2014-04-18 19:31 by Alain.Mellan, last changed 2017-04-13 16:37 by berker.peksag. This issue is now closed.

Files
File name Uploaded Description Edit
issue21301.diff berker.peksag, 2014-05-14 17:18 review
Messages (6)
msg216796 - (view) Author: Alain Mellan (Alain.Mellan) Date: 2014-04-18 19:31
A lot of times paths are manipulated with environment variables that may even be expanded multiple times in a loop. For example, I have a path defined as "$RUNDIR/logfile.txt" and expanding the path for a bunch of different RUNDIRs in a loop.

By default, it should take os.environ and optionally a different dictionary.

Just like os.path.expandvars(), it should expand $VAR, ${VAR} and %VAR%
msg218555 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-05-14 17:18
Here's a patch to implement expandvars() for PurePath (with tests and documentation update).
msg227680 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-27 14:49
expandvars() works with string, not with path, and I don't think there is a place for it in pathlib.
msg230943 - (view) Author: Wolfgang Langner (tds333) * Date: 2014-11-10 08:48
expandvars(), and expanduser() is part of os.path.

Boot functions are needed for path objects and very useful.
And yes it is a simple string substitution but very common.
msg290510 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-26 06:51
expanduser() is path handling function, but not expandvars(). expandvars() is defined in posixpath and ntpath because different OSes use different syntax for interpolated strings, and we sometimes need to use a foreign syntax. It doesn't have any special relations to paths, it handles them just as strings. Actually expandvars() functions are the fifth and the sixth ways of string formatting in Python.

I suggest to close this issue.
msg290535 - (view) Author: Alain Mellan (Alain.Mellan) Date: 2017-03-26 16:01
Yes, you can close it.

— alain.

On Mar 25, 2017, at 23:51 , Serhiy Storchaka <report@bugs.python.org> wrote:

http://bugs.python.org/issue21301 <http://bugs.python.org/issue21301>
History
Date User Action Args
2017-04-13 16:37:03berker.peksagsetstatus: open -> closed
resolution: rejected
stage: patch review -> resolved
2017-03-26 16:01:15Alain.Mellansetmessages: + msg290535
2017-03-26 06:51:19serhiy.storchakasetmessages: + msg290510
2014-11-10 08:48:05tds333setnosy: + tds333
messages: + msg230943
2014-09-27 14:49:48serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg227680
2014-05-14 17:18:55berker.peksagsetfiles: + issue21301.diff

nosy: + berker.peksag
messages: + msg218555

keywords: + patch
stage: patch review
2014-04-18 19:33:28pitrousetnosy: + pitrou

versions: + Python 3.5
2014-04-18 19:31:05Alain.Mellancreate