homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.abspath() should have an option to use PWD
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: csawyer-yumaed, pitrou
Priority: normal Keywords:

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:29adminsetgithub: 58755
2012年04月11日 17:39:24pitrousettitle: os.path.abspath() returns physical path, not logical path. -> os.path.abspath() should have an option to use PWD
messages: + msg158061
components: + Library (Lib), - None
versions: - Python 2.6, Python 3.1, Python 2.7, Python 3.2, Python 3.4
2012年04月11日 17:33:37csawyer-yumaedsetmessages: + msg158060
2012年04月11日 17:22:14pitrousetnosy: + pitrou
messages: + msg158058
2012年04月11日 17:17:50csawyer-yumaedcreate

AltStyle によって変換されたページ (->オリジナル) /