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

gh-109590 - Update shutil.which on win32 to only give back PATHEXT matches by default #109995

Merged
merged 4 commits into from
Oct 2, 2023

Conversation

csm10495
Copy link
Contributor

@csm10495 csm10495 commented Sep 28, 2023

Based off the conversation in gh-109590, if os.X_OK, only give back things that match PATHEXT. Add some corresponding tests.

@zooba said this should probably be in a 3.12.1, so I've marked it that way, though I'm not sure what else I need to change to aim for that. Please advise. Thanks.

Also updated the which tests to work a bit cleaner in terms of str vs bytes. Previously a decent amount of testing wasn't actually running as bytes.


📚 Documentation preview 📚: https://cpython-previews--109995.org.readthedocs.build/

Copy link
Member

@zooba zooba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of minor code changes, but overall it looks good to me

Lib/shutil.py Outdated Show resolved Hide resolved
Lib/shutil.py Outdated Show resolved Hide resolved
@csm10495
Copy link
Contributor Author

Updated with suggestions. I think we're ready for a merge. Thanks!

@csm10495
Copy link
Contributor Author

grr.. accidental pull.. sorry to the folks who got added by mistake. Fixed it but it still added y'all.

@zooba i went back to .upper() since casefold() doesn't work on bytes

csm10495 and others added 3 commits September 28, 2023 17:23
@csm10495 csm10495 force-pushed the shutil_which_no_extv3 branch from fd3a830 to d93e51f Compare September 29, 2023 00:27
@csm10495 csm10495 requested a review from zooba September 29, 2023 00:28
@gvanrossum gvanrossum removed request for a team and gvanrossum September 29, 2023 01:20
@zooba
Copy link
Member

zooba commented Sep 29, 2023

I wonder if we ought to keep the extensionless file at the end? That should help preserve people who really do want the extensionless file returned, and are currently succeeding (even in older versions I believe) if there's no executable there.

So our language becomes "shutil.which prefers files with a PATHEXT extension when an executable path is requested" (I'll rewrite the commit message on merge, don't worry about trying to do it, but wanted to let you know what it'll be)

@csm10495
Copy link
Contributor Author

csm10495 commented Sep 30, 2023

@zooba I gave it a try. Let me know what ya think. Thanks again.

Feel free to squash, rewrite the message, etc.

@zooba zooba merged commit 29b875b into python:main Oct 2, 2023
@zooba
Copy link
Member

zooba commented Oct 2, 2023

Looks great! More updates than I thought, I'm glad I clarified the language for you 😄

@zooba zooba added the needs backport to 3.12 bug and security fixes label Oct 2, 2023
@miss-islington
Copy link
Contributor

Thanks @csm10495 for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 2, 2023
…xtension on executable files (pythonGH-109995)

The default arguments for shutil.which() request an executable file, but extensionless files are not executable on Windows and should be ignored.
(cherry picked from commit 29b875b)

Co-authored-by: Charles Machalow <csm10495@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Oct 2, 2023

GH-110202 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Oct 2, 2023
Yhg1s pushed a commit that referenced this pull request Oct 2, 2023
…extension on executable files (GH-109995) (#110202)

gh-109590: Update shutil.which on Windows to prefer a PATHEXT extension on executable files (GH-109995)

The default arguments for shutil.which() request an executable file, but extensionless files are not executable on Windows and should be ignored.
(cherry picked from commit 29b875b)

Co-authored-by: Charles Machalow <csm10495@gmail.com>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…xtension on executable files (pythonGH-109995)

The default arguments for shutil.which() request an executable file, but extensionless files are not executable on Windows and should be ignored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants