Skip to content

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Apr 16, 2019

shutil.which() and distutils.spawn.find_executable() now use
os.confstr("CS_PATH") if available instead of os.defpath, if the PATH
environment variable is not set.

Don't use os.confstr("CS_PATH") nor os.defpath if the PATH
environment variable is set to an empty string to mimick Unix 'which'
command behavior.

https://bugs.python.org/issue35755

@vstinner
Copy link
Member Author

I'm not comfortable to backport this change to stable Python branches (2.7 and 3.7). I propose to only modify master (Python 3.8).

@vstinner
Copy link
Member Author

@asottile: Would you mind to review this change?

@asottile
Copy link
Contributor

@asottile: Would you mind to review this change?

yep, will review this when I get home from work 👍

Copy link
Contributor

@asottile asottile left a comment

Choose a reason for hiding this comment

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

shutil.which looks good, find_executable is still discovering from pwd though

@vstinner
Copy link
Member Author

@asottile: Would you mind to review the updated PR? find_executable() first looks if the program exists in the current directory. My PR doesn't change that. I have no opinion if it's a good thing or not, but I don't want to change that in this PR. If you want to change it, please open a separated issue on bugs.python.org since it will be backward incompatible change not directly related to https://bugs.python.org/issue35755

@vstinner
Copy link
Member Author

Hum, I propose to backport this change (use confstr("CS_PATH")) to Python 3.7. Or at least, backport additional tests.

Copy link
Contributor

@asottile asottile left a comment

Choose a reason for hiding this comment

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

looks great! thanks for the additional test

shutil.which() and distutils.spawn.find_executable() now use
os.confstr("CS_PATH") if available instead of os.defpath, if the PATH
environment variable is not set.

Don't use os.confstr("CS_PATH") nor os.defpath if the PATH
environment variable is set to an empty string to mimick Unix 'which'
command behavior.

Changes:

* find_executable() now starts by checking for the exeuctable in the
  current working directly case first. Add an explicit
  "if not path: return None".
* Add tests for PATH='', PATH=':' and for PATHEXT.
@vstinner
Copy link
Member Author

I rebased my PR, squashed commits and just fixed a comment.

@vstinner vstinner merged commit 228a3c9 into python:master Apr 17, 2019
@miss-islington
Copy link
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @vstinner, I could not cleanly backport this to 3.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 228a3c99bdb2d02771bead66a0beabafad3a90d3 3.7

vstinner added a commit that referenced this pull request Apr 17, 2019
* bpo-35755: shutil.which() uses os.confstr("CS_PATH") (GH-12858)

shutil.which() and distutils.spawn.find_executable() now use
os.confstr("CS_PATH") if available instead of os.defpath, if the PATH
environment variable is not set.

Don't use os.confstr("CS_PATH") nor os.defpath if the PATH
environment variable is set to an empty string.

Changes:

* find_executable() now starts by checking for the executable in the
  current working directly case. Add an explicit
  "if not path: return None".
* Add tests for PATH='' (empty string), PATH=':' and for PATHEXT.

(cherry picked from commit 228a3c9)

* bpo-35755: Remove current directory from posixpath.defpath (GH-11586)

Document the change in a NEWS entry of the Security category.

(cherry picked from commit 2c4c02f)
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.

5 participants