-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-28624: Add test for subprocess to check that cmd arg supports PathLike #157
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
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow these steps to help rectify the issue:
Thanks again to your contribution and we look forward to looking at it! |
Doc/library/subprocess.rst
Outdated
*cwd* before executing the child. In particular, the function looks for | ||
*executable* (or for the first item in *args*) relative to *cwd* if the | ||
executable path is a relative path. | ||
*cwd* before executing the child. *cwd* also accepts a `os.PathLike` object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make suspicious
fails here with "default role used". Not sure, but you may have to put double backticks around os.PathLike
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:ref:os.PathLike
would be a preferable fix here (turning this into a cross reference to the ABC's docs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, if you follow Berker's suggestion below (which seems like a good idea to me), that will also fix this.
Doc/library/subprocess.rst
Outdated
*cwd* before executing the child. In particular, the function looks for | ||
*executable* (or for the first item in *args*) relative to *cwd* if the | ||
executable path is a relative path. | ||
*cwd* before executing the child. *cwd* also accepts a `os.PathLike` object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add two spaces before "*cwd* also accepts a os.PathLike object."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to follow the style in the rest of stdlib:
[...] child. *cmd* can be a :class:`str` and :term:`path-like <path-like object>` object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please add a versionchanged directive to properly document os.PathLike
support:
.. versionchanged:: 3.6
*cwd* parameter accepts a :term:`path-like object`.
Lib/test/test_subprocess.py
Outdated
@@ -347,6 +347,18 @@ def test_cwd(self): | |||
temp_dir = self._normalize_cwd(temp_dir) | |||
self._assert_cwd(temp_dir, sys.executable, cwd=temp_dir) | |||
|
|||
def test_cwd_with_pathlike(self): | |||
# Check that cwd changes the cwd for the child process with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add a comment here.
Lib/test/test_subprocess.py
Outdated
temp_dir = tempfile.gettempdir() | ||
temp_dir = self._normalize_cwd(temp_dir) | ||
|
||
class _PathLikeObj: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create a pathlib.Path
instance from temp_dir
and pass it to cwd
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sayanchowdhury and I were discussing that at the PyCon Pune sprints and I suggested doing it this way to avoid adding a new dependency to the test cases.
271a1ad
to
1cb8660
Compare
Thanks for the review. I have updated the PR. |
1cb8660
to
da4f28a
Compare
(Oops, after chatting to @sayanchowdhury, I realised this suggestion wasn't as useful as I thought - |
da4f28a
to
e153659
Compare
I ran |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to merge this, but just noticed a small typo. I think this also deserves a Misc/NEWS
entry since we are aim to support path-like objects in the stdlib in Python 3.6.
Doc/library/subprocess.rst
Outdated
*cwd* before executing the child. In particular, the function looks for | ||
*executable* (or for the first item in *args*) relative to *cwd* if the | ||
executable path is a relative path. | ||
*cwd* before executing the child. *cmd* can be a :class:`str` and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmd -> cwd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the typo. Fixed it.
e153659
to
6c208d2
Compare
Should add to section |
*executable* (or for the first item in *args*) relative to *cwd* if the | ||
executable path is a relative path. | ||
*cwd* before executing the child. *cwd* can be a :class:`str` and | ||
:term:`path-like <path-like object>` object. In particular, the function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, you only mention string and PathLike, how about bytes? Is it acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test for bytes too and it's seems to be passing too. Also updated the docs.
6c208d2
to
c096044
Compare
Can we please keep this PR specific to |
Signed-off-by: Sayan Chowdhury <[email protected]>
Okay, I'll then go ahead and keep the changes |
c096044
to
3370e0b
Compare
I have updated the code. |
…ts PathLike objects (python#157) (cherry picked from commit d5c11f7)
Thanks! |
#157 added the test, but it's currently (correctly) broken on windows.
#157 added the test, but it's currently (correctly) broken on windows.
Added the sprint label, as this PR was submitted at the PyCon Pune 2017 core development sprint. |
Detected by gcc -Wmisleading-indentation.
No description provided.