Issue 14550: os.path.abspath() should have an option to use PWD (original) (raw)

Created on 2012-04-11 17:17 by csawyer-yumaed, last changed 2022-04-11 14:57 by admin.

Messages (4)
msg158056 - (view) Author: Craig Sawyer (csawyer-yumaed) Date: 2012-04-11 17:17
we have os.path.abspath() and os.path.realpath(). the difference according to the documentation is realpath() returns the physical path (i.e. no symlinks in the path). while abspath() uses getcwd() but because of POSIX.1-2008 (IEEE Std 1003.1-2008) says os.getcwd() returns without symbolic links as well, so os.path.abspath() == os.path.realpath() near as I can tell. I think os.path.abspath() should return a logical path(i.e. one with symlinks). The only solution I know of is to getenv('PWD') except that is not guaranteed to be around in POSIX (some BSD's don't offer PWD I understand). The other option is to ask /bin/pwd which is part of the POSIX standard. Anyways, I couldn't find a previous bug around this issue, but I think there should be a way in the standard library to get a logical path, as well as a realpath().
msg158058 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-04-11 17:22
> while abspath() uses getcwd() but because of POSIX.1-2008 (IEEE Std > 1003.1-2008) says os.getcwd() returns without symbolic links as well, > so os.path.abspath() == os.path.realpath() near as I can tell. Just because getcwd() doesn't contain any symbolic links doesn't mean the rest of the path is stripped of all symlinks. > I think there should be a way in the standard library to get a logical > path, as well as a realpath(). This doesn't make sense. There could be an arbitrary number of "logical" paths pointing to a single physical one. Which one should Python choose?
msg158060 - (view) Author: Craig Sawyer (csawyer-yumaed) Date: 2012-04-11 17:33
Antoine, I see your point about getcwd() not having symlinks, doesn't mean any path outside of getcwd() might have symlinks, and I agree this is true. I apologize. As for which one to choose, it should choose based on PWD (i.e. the current working directory's parent directories). I'd love to see something like os.path.abspath(path, logical=True) which would use PWD instead of getcwd() to get the current working directories path. i.e. symlinks are honored within the current path. From a language perspective this probably means needing os.getpwd() or something similar, that would return the pwd information. I know pwd isn't always guaranteed to be around, so the failsafe should be to return getcwd() in that case, just like os.path.abspath() does now.
msg158061 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-04-11 17:39
Ok, reformulating the title a bit.
History
Date User Action Args
2022-04-11 14:57:29 admin set github: 58755
2012-04-11 17:39:24 pitrou set title: os.path.abspath() returns physical path, not logical path. -> os.path.abspath() should have an option to use PWDmessages: + components: + Library (Lib), - Noneversions: - Python 2.6, Python 3.1, Python 2.7, Python 3.2, Python 3.4
2012-04-11 17:33:37 csawyer-yumaed set messages: +
2012-04-11 17:22:14 pitrou set nosy: + pitroumessages: +
2012-04-11 17:17:50 csawyer-yumaed create