Inconsistent drive letter case on Windows
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với mã xử lý đường dẫn Windows trong Modules/posixmodule.c quanh các dòng được liên kết, sau đó tái hiện hành vi bằng các lệnh os.path.abspath trong báo cáo. Xác nhận cách lấy ký tự ổ đĩa và xác định hoàn thành khi cách viết hoa của ký tự ổ đĩa trong các đường dẫn tuyệt đối của Windows nhất quán, với hành vi liên quan được các bài kiểm thử bao phủ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- c, python
- Lĩnh vực
- operating-systems
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100