New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-117587: Add C implementation of os.path.abspath
#117855
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
The same approach doesn't work on Window, because PS C:\Users\wanne\cpython> python -m timeit -s "import nt" "nt._getfullpathname('.')"; python -m timeit -s "import os" "os.path.join(r'C:\Users\wanne\cpython', '')"
1000000 loops, best of 5: 286 nsec per loop # _getfullpathname
200000 loops, best of 5: 1.41 usec per loop # join |
Preferably, A process has a working directory on each A-Z drive. This gets used to resolve drive-relative paths such as "Z:spam\eggs" -> "Z:\path\to\working_directory\spam\eggs". On NT based Windows systems, a process can optionally store the working directories on drives in special "=<letter>:" environment variables that are inherited by child processes, such as "=Z:". If the environment variable isn't set for a drive, or it refers to a path that doesn't exist, the drive's working directory defaults to the root directory. If the overall process working directory is on the same drive, it supersedes the environment variable. Python opts into this scheme on Windows by setting these environment variables in the implementation of Python also relies on In C, |
I didn't even get that far in the testing process. I already knew it wasn't going to work. |
…endo/cpython into speedup-posixpath.abspath
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Eryk Sun <eryksun@gmail.com>
@eryksun, are there still edge cases you would like to fix? Or did I cover everything? |
Let's leave optimising |
This reverts commit 5850c3b.
Benchmark
posixpath.py by @eryksun:
ntpath.py
script
posixpath.abspath()
for relative paths #117587