Skip to content
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

Shutil.which incosistent with windows's where #84772

Closed
alkuzad mannequin opened this issue May 11, 2020 · 9 comments
Closed

Shutil.which incosistent with windows's where #84772

alkuzad mannequin opened this issue May 11, 2020 · 9 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes easy OS-windows stdlib Python modules in the Lib dir

Comments

@alkuzad
Copy link
Mannequin

alkuzad mannequin commented May 11, 2020

BPO 40592
Nosy @pfmoore, @tjguk, @zware, @zooba, @alkuzad, @miss-islington, @peanutlord
PRs
  • bpo-40592: shutil.which will not return None anymore if ; is the last char in PATHEXT #20088
  • [3.9] bpo-40592: shutil.which will not return None anymore if ; is the last char in PATHEXT (GH-20088) #22912
  • [3.8] bpo-40592: shutil.which will not return None anymore if ; is the last char in PATHEXT (GH-20088) #22913
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-10-23.10:09:45.922>
    created_at = <Date 2020-05-11.08:50:15.691>
    labels = ['easy', '3.8', '3.9', '3.10', 'library', 'OS-windows']
    title = "`Shutil.which` incosistent with windows's `where`"
    updated_at = <Date 2020-10-23.21:38:08.966>
    user = 'https://github.com/alkuzad'

    bugs.python.org fields:

    activity = <Date 2020-10-23.21:38:08.966>
    actor = 'miss-islington'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-10-23.10:09:45.922>
    closer = 'steve.dower'
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2020-05-11.08:50:15.691>
    creator = 'alkuzad'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40592
    keywords = ['patch', 'easy', 'newcomer friendly']
    message_count = 9.0
    messages = ['368620', '368745', '368838', '379218', '379347', '379426', '379427', '379477', '379478']
    nosy_count = 7.0
    nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'steve.dower', 'alkuzad', 'miss-islington', 'peanutlord']
    pr_nums = ['20088', '22912', '22913']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue40592'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @alkuzad
    Copy link
    Mannequin Author

    alkuzad mannequin commented May 11, 2020

    Shutil's which implementation does not work correctly when someone set's empty item in PATHEXT environment variable. Example:

    set PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.RB;.RBW;

    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.

    @alkuzad alkuzad mannequin added stdlib Python modules in the Lib dir labels May 11, 2020
    @zooba
    Copy link
    Member

    zooba commented May 12, 2020

    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.

    @peanutlord
    Copy link
    Mannequin

    peanutlord mannequin commented May 14, 2020

    @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 :)

    @peanutlord
    Copy link
    Mannequin

    peanutlord mannequin commented Oct 21, 2020

    @steve.dower Added the changes in the PR - could you please re-check? Thank you!

    @peanutlord
    Copy link
    Mannequin

    peanutlord mannequin commented Oct 22, 2020

    @steve.dower Your advice did it, is fixed and green! :) Thank you again

    @zooba
    Copy link
    Member

    zooba commented Oct 23, 2020

    New changeset da6f098 by Christopher Marchfelder in branch 'master':
    bpo-40592: shutil.which will not return None anymore if ; is the last char in PATHEXT (GH-20088)
    da6f098

    @zooba
    Copy link
    Member

    zooba commented Oct 23, 2020

    Thanks for the contribution! Looking forward to your next one :)

    @zooba zooba added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Oct 23, 2020
    @zooba zooba closed this as completed Oct 23, 2020
    @zooba zooba added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Oct 23, 2020
    @zooba zooba closed this as completed Oct 23, 2020
    @miss-islington
    Copy link
    Contributor

    New changeset 8b4842b by Miss Skeleton (bot) in branch '3.8':
    [3.8] bpo-40592: shutil.which will not return None anymore if ; is the last char in PATHEXT (GH-20088) (GH-22913)
    8b4842b

    @miss-islington
    Copy link
    Contributor

    New changeset c437fe3 by Miss Skeleton (bot) in branch '3.9':
    [3.9] bpo-40592: shutil.which will not return None anymore if ; is the last char in PATHEXT (GH-20088) (GH-22912)
    c437fe3

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes 3.10 only security fixes easy OS-windows stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants