Inconsistent drive letter case on Windows
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Bug report + suggested fix
The os.path.abspath method on windows is inconsistent when pre-pending the drive letter as it can be either upper or lowercase.
It is not entirely clear from Microsoft's documentation (https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew) when this happens exactly, but, a simple way of re-producing the issue is by changing directory and specifying the opposite case letter in the call
C:\Users\kieran>python -c "import os; print(os.path.abspath('.'))"
C:\Users\kieran
C:\Users\kieran>cd c:\Users\kieran\Projects
c:\Users\kieran\Projects>python -c "import os; print(os.path.abspath('.'))"
c:\Users\kieran\Projects
This is very frustrating when trying to compare paths, and, sometimes different tools in the same development environments will run in such a way that they change their drive letter case, leading to issues between those tools or differences inside tests.
I would like to suggest that we enforce the lowercase driver letters by making a small change to https://github.com/python/cpython/blob/0fe61d0838218b18bcff4bf434beba3e8dbcc42b/Modules/posixmodule.c#L4236-L4274
If we were to include an iteration (line 4266) of the buffered path that lowercased the chars up to the colon (guaranteed to be set), this would ensure consistent drive letters.
Your environment
Python 3.9.6
Microsoft Windows 10 Pro - 10.0.19044 Build 19044
x64-based PC
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Windows path-handling code in Modules/posixmodule.c around the linked lines, then reproduce the behavior using the os.path.abspath commands in the report. Confirm how the drive letter is obtained and define done as consistent drive-letter casing in Windows absolute paths, with the relevant behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100