bpo-30618: add readlink to pathlib.Path by girtsf · Pull Request #8285 · python/cpython (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation21 Commits1 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

girtsf

@the-knights-who-say-ni

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

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 titlebpo-30618: add readlink to pathlib.Path bpo-30618: add readlink to pathlib.Path (GH-8285)

Jul 14, 2018

@Mariatta Mariatta changed the titlebpo-30618: add readlink to pathlib.Path (GH-8285) bpo-30618: add readlink to pathlib.Path

Jul 16, 2018

@ammaraskar

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

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

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

@girtsf

@girtsf

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

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

berkerpeksag

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

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

@girtsf

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

Thanks for making the requested changes!

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

@girtsf

This adds a "readlink" method to pathlib.Path objects that calls through to os.readlink, and wraps the result in a "Path" object.

@girtsf

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

gpshead

@gpshead

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

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

jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request

Dec 5, 2019

@girtsf

shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request

Jan 31, 2020

@girtsf @shihai1991