Inconsistent drive letter case on Windows
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた行の周辺にある Modules/posixmodule.c の Windows パス処理コードから始め、次に、報告に記載された os.path.abspath コマンドを使ってその動作を再現します。ドライブ文字がどのように取得されるかを確認し、Windows の絶対パスにおけるドライブ文字の大文字・小文字が一貫しており、関連する動作がテストでカバーされていることを完了条件とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, python
- 領域
- operating-systems
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100