Uh oh!
There was an error while loading. Please reload this page.
gh-64978: Add chown() to pathlib.Path - #31212
Conversation
the-knights-who-say-ni
commented
Feb 8, 2022
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
6d47346 to
55b70c0CompareUh oh!
There was an error while loading. Please reload this page.
196cf81 to
9032f1bCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
c72a2f3 to
f9a611bCompareJelleZijlstra
commented
May 2, 2022
@barneygale what do you think? |
barneygale
commented
May 2, 2022
I'm supportive of adding I don't love Couple more things to consider/discuss:
|
chown() and lchown() to pathlib.Pathchown() and lchown() to pathlib.Pathbrettcannon
commented
May 5, 2022
I'm fine with adding I also concur on not wanting No opinion on the name/ID question. I don't quite follow the |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
bedevere-bot
commented
May 5, 2022
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 |
y0urself
commented
May 6, 2022
I have already removed the |
chown() and lchown() to pathlib.Pathchown() to pathlib.Pathy0urself
commented
May 6, 2022
I am not sure with On the other hand I have removed |
bedevere-bot
commented
May 6, 2022
Thanks for making the requested changes! @brettcannon: please review the changes made to this pull request. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Having given it more thought, and considering the context where this is likely to be used (devops-y scripts), I think supporting owner and group names (in addition to IDs) is important. I think the new method should call through to |
Co-authored-by: Barney Gale <barney.gale@gmail.com>
y0urself
commented
May 9, 2022
We would need to drop the |
barneygale
commented
May 9, 2022
Or add |
| Change the file ownership, like :func:`os.chown`. | ||
| This method normally follows symlinks. Some Unix flavours support changing |
There was a problem hiding this comment.
| This method normally follows symlinks. Some Unix flavours support changing | |
| This method follows symlinks by default. Some Unix flavours support changing |
| """ | ||
| Change the owner and group id of path to the numeric uid and gid, like os.chown(). | ||
| """ |
There was a problem hiding this comment.
Please follow PEP 8.
| """ | |
| Changetheownerandgroupidofpathtothenumericuidandgid, likeos.chown(). | |
| """ | |
| """Change the owner and group id of path to the numeric uid and gid, like os.chown().""" |
| root_in_posix = False | ||
| if hasattr(os, 'geteuid'): | ||
| root_in_posix = (os.geteuid() == 0) |
There was a problem hiding this comment.
| root_in_posix=False | |
| ifhasattr(os, 'geteuid'): | |
| root_in_posix= (os.geteuid() ==0) | |
| try: | |
| root_in_posix=notos.geteuid() | |
| exceptAttributeError: | |
| root_in_posix=False |
This looks to be a copy-and-paste from test_os.py, correct? If so, can you move this to https://github.com/python/cpython/tree/main/Lib/test/support somewhere?
There was a problem hiding this comment.
Sure I can move it and use it from there as a helper module ...
| @unittest.skipUnless(root_in_posix and len(all_users) > 1, | ||
| "test needs root privilege and more than one user") | ||
| def test_chown_with_root(self): | ||
| # original uid and gid |
There was a problem hiding this comment.
Please follow PEP 8.
| # original uid and gid | |
| # The original uid and gid. |
| try: | ||
| import pwd | ||
| all_users = [u.pw_uid for u in pwd.getpwall()] | ||
| except (ImportError, AttributeError): | ||
| all_users = [] |
There was a problem hiding this comment.
This looks to be a copy-and-paste from test_os.py, correct? If so, can you move this to https://github.com/python/cpython/tree/main/Lib/test/support somewhere?
| uid = p.stat().st_uid | ||
| gid = p.stat().st_gid | ||
| # get users and groups for testing |
There was a problem hiding this comment.
| # get users and groups for testing | |
| # Get users and groups for testing. |
bedevere-bot
commented
May 12, 2022
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 |
brettcannon
commented
May 19, 2022
I left a comment on the issue, but after thinking about it, right now there isn't really enough here to warrant taking this PR as it's just wrapping a function call in a method. Without some added benefit to being attached to |
AlexWaygood
commented
Jan 8, 2023
Thanks for the PR, @y0urself. I'm afraid I'm going to close this as rejected, as I agree with Brett's comments, as well as @barneygale's and @CAM-Gerlach's remarks on the associated issue. However, I hope this doesn't discourage you from contributing to CPython in the future! We do appreciate the contribution :) |
A few words about one thing. pipinstall-U'xonsh[full]'xonshcd/tmp&&echoworld>hello.txtp'hello.txt'# Path('hello.txt')p'hello.txt'.read_text()
# 'world\n'forfinp'/tmp'.glob('hello*'):
print(f, f.exists())
# /tmp/hello.txt TrueIt will be cool to run I'm for reopening this issue and favor for enriching pathlib. |
CAM-Gerlach
commented
Mar 18, 2023
@barneygale , as you're now officially the pathlib maintainer, what is your take on considering re-opening this PR and/or a revised one? |
barneygale
commented
Mar 18, 2023
I've re-opened the issue, we could continue discussion there if that works? |
This PR adds
chown()andlchown()to thepathliblibrary.As for
chmodand other existing functions, this is achieved by usingos.chown()within the new functions.