Title: `Shutil.which` incosistent with windows's `where`
Type: Stage: patch review
Components: Library (Lib), Windows Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: alkuzad, paul.moore, peanut-lord, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: easy, newcomer friendly, patch

Created on 2020-05-11 08:50 by alkuzad, last changed 2020-05-14 15:56 by peanut-lord.

Pull Requests
URL Status Linked Edit
PR 20088 open peanut-lord, 2020-05-14 15:56
Messages (3)
msg368620 - (view) Author: Dawid Gosławski (alkuzad) Date: 2020-05-11 08:50
Shutil's which implementation does not work correctly when someone set's empty item in `PATHEXT` environment variable. Example:


I'm not 100% sure how I got this in my PATHEXT config, I wasn't changing that so maybe some bugged uninstaller not removed it's extension correctly.

This makes things confusing as Windows will find correctly binary, but Python will return nothing, due to this part:

if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
            files = [cmd]

pathext is initialized as `pathext = os.environ.get("PATHEXT", "").split(os.pathsep)`, which ends producing '' as last element

Because any string ends with empty string (''), files list will have plain version added like `git`, which will then fail executable check.

Workaround is to use full name `git.exe`

Filtering out empty strings would fix that.
msg368745 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-05-12 22:29
Sounds like a good opportunity for someone to make their first contribution.

Post a message if you'd like to work on this (and a test), and we can help get through the PR process.
msg368838 - (view) Author: Christopher Marchfelder (peanut-lord) * Date: 2020-05-14 13:42
@steve.dower I would really love to work on this and make my first contribution. Never did one, so I would some help doing this one :)
Date User Action Args
2020-05-14 15:56:44peanut-lordsetkeywords: + patch
stage: patch review
pull_requests: + pull_request19392
2020-05-14 13:42:18peanut-lordsetnosy: + peanut-lord
messages: + msg368838
2020-05-12 22:29:22steve.dowersetkeywords: + easy, newcomer friendly

messages: + msg368745
2020-05-11 10:05:51serhiy.storchakasetnosy: + paul.moore, tim.golden, zach.ware, steve.dower
components: + Windows
2020-05-11 08:50:15alkuzadcreate