Skip to content

bpo-30618: add readlink to pathlib.Path #8285

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 1 commit into from
Oct 23, 2019

Conversation

girtsf
Copy link
Contributor

@girtsf girtsf commented Jul 14, 2018

This adds a "readlink" method to pathlib.Path objects that calls through
to os.readlink.

https://bugs.python.org/issue30618

Automerge-Triggered-By: @gpshead

@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 our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

When your account is ready, please add a comment in this pull request
and a Python core developer will remove the CLA not signed label
to make the bot check again.

Thanks again for your contribution, we look forward to reviewing it!

@girtsf
Copy link
Contributor Author

girtsf commented Jul 14, 2018

I submitted the CLA form, so it will probably take a few days to clear.

Also, I wasn't entirely sure if a) this needs any special handling for non-POSIX platforms, and b) if I'm supposed to be modifying the documentation in this pull request too, so any advice would be welcome!

@girtsf girtsf changed the title bpo-30618: add readlink to pathlib.Path bpo-30618: add readlink to pathlib.Path (GH-8285) Jul 14, 2018
@Mariatta Mariatta changed the title bpo-30618: add readlink to pathlib.Path (GH-8285) bpo-30618: add readlink to pathlib.Path Jul 16, 2018
@ammaraskar
Copy link
Member

ammaraskar commented Jul 16, 2018

a) this needs any special handling for non-POSIX platforms

Take a look at is_mount for some prior art on this, it throws a NotImplementedError on Windows and the documentation notes that its not available on Windows.

b) if I'm supposed to be modifying the documentation in this pull request too, so any advice would be welcome!

Documentation should definitely be added since this is a public facing API.

Edit: it looks like windows actually does support os.readlink in Py3 so it should be made available there.

@girtsf girtsf force-pushed the fix-issue-30618 branch from a29d031 to 0e29a0d Compare July 30, 2018 06:27
@girtsf
Copy link
Contributor Author

girtsf commented Jul 30, 2018

Updated the pull request to include documentation. Also, switched to wrapping the readlink value in Path, to have similar behavior to existing functions (e.g., 'resolve').

(Also, I submitted the CLA couple weeks ago, not sure if somebody needs to kick the CLA bot or if it will automagically happen?)

@girtsf
Copy link
Contributor Author

girtsf commented Jul 30, 2018

Hmm. So looks like this is failing on windows with:

======================================================================
ERROR: test_readlink (test.test_pathlib.PathTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\1\s\lib\test\test_pathlib.py", line 1671, in test_readlink
    self.assertEqual((P / 'linkA').readlink(), self.cls('fileA'))
  File "D:\a\1\s\lib\pathlib.py", line 1204, in readlink
    path = self._accessor.readlink(self)
  File "D:\a\1\s\lib\pathlib.py", line 424, in readlink
    return os.readlink(path)
TypeError: readlink() argument 1 must be str, not WindowsPath

Is this a bug? The documentation for os.readlink says that it accepts a path-like object. os.readlink(pathlib.Path('foo')) works for me on macOS. Looks like it does not work on windows?

@girtsf
Copy link
Contributor Author

girtsf commented Jul 31, 2018

(Something was wacky with my bpo user, perhaps because I registered with google's oauth. I changed my username, it then cleared out my github username. I reset that back, and now https://bugs.python.org/user?@template=clacheck&github_names=girtsf shows true. Dear Ni bot tamers, can we try again with that label please?)

@girtsf
Copy link
Contributor Author

girtsf commented Aug 12, 2018

FYI: filed https://bugs.python.org/issue34384 for the readlink on Windows issue.

@girtsf
Copy link
Contributor Author

girtsf commented Aug 17, 2018

Hooray, looks like due to @berkerpeksag 's fixes in #8740, the tests now pass on Windows too!

I think this is ready for another looksie.

@berkerpeksag berkerpeksag self-requested a review August 17, 2018 09:37
@berkerpeksag
Copy link
Member

@girtsf thanks for the ping! I just added this to my TODO list.

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.

Please add a note to Doc/whatsnew/3.8.rst and use the following format:

Your note.

(Contributed by Girts Folkmanis in :issue:`30618`.)

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@csabella
Copy link
Contributor

@girtsf, please address the code review from @berkerpeksag. Thanks!

@girtsf girtsf force-pushed the fix-issue-30618 branch from bcd71c9 to 09734ac Compare July 20, 2019 04:17
@girtsf
Copy link
Contributor Author

girtsf commented Jul 20, 2019

Better later than never? 😬

I'm assuming 3.8 train has sailed, so I added the news to 3.9.

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@berkerpeksag: please review the changes made to this pull request.

@girtsf girtsf requested a review from berkerpeksag September 17, 2019 14:56
This adds a "readlink" method to pathlib.Path objects that calls through
to os.readlink, and wraps the result in a "Path" object.
@girtsf
Copy link
Contributor Author

girtsf commented Oct 23, 2019

@gpshead, um, hi! Abusing old connections to see if I can get this reviewed. :)

@gpshead gpshead self-assigned this Oct 23, 2019
@gpshead
Copy link
Member

gpshead commented Oct 23, 2019

the azure pipelines should've completed within half an hour after yesterday's push but appear to have not even run it? odd. i'm closing and reopening to kick the CI systems to rerun.

@miss-islington
Copy link
Contributor

@girtsf: Status check is done, and it's a success ✅ .

@miss-islington miss-islington merged commit a01ba33 into python:master Oct 23, 2019
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
This adds a "readlink" method to pathlib.Path objects that calls through
to os.readlink.


https://bugs.python.org/issue30618



Automerge-Triggered-By: @gpshead
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
This adds a "readlink" method to pathlib.Path objects that calls through
to os.readlink.


https://bugs.python.org/issue30618



Automerge-Triggered-By: @gpshead
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.

9 participants