Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 3 commits into from
Feb 26, 2017

Conversation

sayanchowdhury
Copy link
Contributor

No description provided.

@the-knights-who-say-ni
Copy link

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:

  1. If you don't have an account on b.p.o, please create one
  2. Make sure your GitHub username is listed in "Your Details" at b.p.o
  3. If you have not already done so, please sign the PSF contributor agreement
  4. If you just signed the CLA, please wait at least one US business day and then check "Your Details" on bugs.python.org to see if your account has been marked as having signed the CLA (the delay is due to a person having to manually check your signed CLA)
  5. Reply here saying you have completed the above steps

Thanks again to your contribution and we look forward to looking at it!

@serhiy-storchaka serhiy-storchaka added type-feature A feature request or enhancement tests Tests in the Lib/test dir and removed type-feature A feature request or enhancement labels Feb 18, 2017
*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.
Copy link
Member

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.

Copy link
Contributor

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)

Copy link
Contributor

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.

*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.
Copy link
Member

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."

Copy link
Member

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.

Copy link
Member

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`.

@@ -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
Copy link
Member

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.

temp_dir = tempfile.gettempdir()
temp_dir = self._normalize_cwd(temp_dir)

class _PathLikeObj:
Copy link
Member

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.

Copy link
Contributor

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.

@sayanchowdhury
Copy link
Contributor Author

Thanks for the review. I have updated the PR.

@ncoghlan
Copy link
Contributor

ncoghlan commented Feb 19, 2017

make patchcheck should clean up the trailing whitespace errors being picked up by Travis.

(Oops, after chatting to @sayanchowdhury, I realised this suggestion wasn't as useful as I thought - make patchcheck only checks uncommitted changes, so it will only help here if you first soft-reset the git state to an earlier commit)

@sayanchowdhury
Copy link
Contributor Author

sayanchowdhury commented Feb 20, 2017

I ran make patchcheck which removed the trailing spaces. Travis also seems to be happy now.

Copy link
Member

@berkerpeksag berkerpeksag left a 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.

*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
Copy link
Member

Choose a reason for hiding this comment

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

cmd -> cwd

Copy link
Contributor Author

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.

@sayanchowdhury
Copy link
Contributor Author

Should add to section What's New in Python 3.6.1 release candidate 1 under Library in Misc/NEWS?

*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
Copy link
Member

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?

Copy link
Contributor Author

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.

@berkerpeksag
Copy link
Member

Can we please keep this PR specific to os.PathLike support? Passing cwd=b"something" is out of scope for this issue and it should be discussed on bugs.python.org.

@sayanchowdhury
Copy link
Contributor Author

Okay, I'll then go ahead and keep the changes os.PathLike specific.

@sayanchowdhury
Copy link
Contributor Author

I have updated the code.

@berkerpeksag berkerpeksag merged commit d5c11f7 into python:master Feb 26, 2017
berkerpeksag pushed a commit to berkerpeksag/cpython that referenced this pull request Feb 26, 2017
@berkerpeksag
Copy link
Member

Thanks!

berkerpeksag added a commit that referenced this pull request Feb 26, 2017
…ts PathLike objects (#157) (#323)

(cherry picked from commit d5c11f7)
benjaminp added a commit that referenced this pull request Mar 2, 2017
#157 added the test, but it's currently (correctly) broken on windows.
benjaminp added a commit that referenced this pull request Mar 2, 2017
#157 added the test, but it's currently (correctly) broken on windows.
@ncoghlan
Copy link
Contributor

Added the sprint label, as this PR was submitted at the PyCon Pune 2017 core development sprint.

akruis pushed a commit to akruis/cpython that referenced this pull request Jun 20, 2018
Detected by gcc -Wmisleading-indentation.
jaraco pushed a commit that referenced this pull request Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sprint tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants