GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-73991: Support preserving metadata in `pathlib.Path.copy()` by barneygale · Pull Request #120806 · python/cpython

Conversation

@barneygale

@barneygale barneygale commented Jun 20, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Add preserve_metadata keyword-only argument to pathlib.Path.copy(), defaulting to false. When set to true, we copy timestamps, permissions, extended attributes and flags where available, like shutil.copystat(). The argument has no effect on Windows, where metadata is always copied.

Internally (in the pathlib ABCs), path types gain _readable_metadata and _writable_metadata attributes. These sets of strings describe what kinds of metadata can be retrieved and stored. We take an intersection of source._readable_metadata and target._writable_metadata to minimise reads/writes. A new _read_metadata() method accepts a set of metadata keys and returns a dict with those keys, and a new _write_metadata() method accepts a dict of metadata. We might make these public in future, but it's hard to justify while the ABCs are still private.

  • Issue: Support moving across filesystems in pathlib.Path, as shutil.move() does #73991

📚 Documentation preview 📚: https://cpython-previews--120806.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@barneygale
pythonGH-73991: Support preserving metadata in pathlib.Path.copy()
ff025ff
Add *preserve_metadata* keyword-only argument to `pathlib.Path.copy()`,
defaulting to false. When set to true, we copy timestamps, permissions,
extended attributes and flags where available, like `shutil.copystat()`.
The argument has no effect on Windows, where metadata is always copied.

In the pathlib ABCs we copy the file permissions with `PathBase.chmod()`
where supported. In the future we might want to support a more generic
public interface for copying metadata between different types of `PathBase`
object, but it would be premature here.
@barneygale barneygale added skip news topic-pathlib labels Jun 20, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Jun 20, 2024
Support moving across filesystems in pathlib.Path, as shutil.move() does #73991
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Jun 20, 2024
barneygale added 14 commits June 20, 2024 19:20
@barneygale
Test timestamps
720a0e0
@barneygale
Typos
c14d16f
@barneygale
Use code from shutil.
f54925c
@barneygale
Tighten conditions.
b05256b
@barneygale
Merge branch 'main' into copy-metadata
ee2cd35
@barneygale
Merge branch 'main' into copy-metadata
da6cd5b
@barneygale
Undo shutil changes.
211b861
@barneygale
Remove some code that's now unused.
8129c46
@barneygale
docstrings, re-order methods.
15cc3db
@barneygale
Skip retrieving metadata if we're unable to set it on the target.
89dfad5
@barneygale
Merge branch 'main' into copy-metadata
d312469
@barneygale
Fix double lookup.
547a3c3
@barneygale
Rename methods.
f584643
@barneygale
Tweaks
3206a89
@barneygale
barneygale merged commit 88fc065 into python:main Jul 6, 2024
@bedevere-app bedevere-app Bot removed the awaiting core review label Jul 6, 2024
@bedevere-bot

bedevere-bot commented Jul 6, 2024

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot PPC64LE Fedora Stable Clang Installed 3.x has failed when building commit 88fc065.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/451/builds/4646) and take a look at the build logs.
  4. Check if the failure is related to this commit (88fc065) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/451/builds/4646

Failed tests:

  • test_pathlib

Failed subtests:

  • test_copy_file_preserve_metadata - test.test_pathlib.test_pathlib.PathSubclassTest.test_copy_file_preserve_metadata
  • test_copy_file_preserve_metadata - test.test_pathlib.test_pathlib.PathTest.test_copy_file_preserve_metadata
  • test_copy_file_preserve_metadata - test.test_pathlib.test_pathlib.PosixPathTest.test_copy_file_preserve_metadata

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-ppc64le.clang-installed/build/target/lib/python3.14/test/test_pathlib/test_pathlib.py", line 660, in test_copy_file_preserve_metadata
    os.setxattr(source, b'user.foo', b'42')
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 95] Operation not supported: '/tmp/test_python_pfjupu1y/test_python_2060648æ/@test_2060648_tmpæ/fileA'


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-ppc64le.clang-installed/build/target/lib/python3.14/test/test_pathlib/test_pathlib.py", line 660, in test_copy_file_preserve_metadata
    os.setxattr(source, b'user.foo', b'42')
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 95] Operation not supported: '/tmp/test_python__riczf75/test_python_2046711æ/@test_2046711_tmpæ/fileA'
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

barneygale added a commit to barneygale/cpython that referenced this pull request Jul 6, 2024
@barneygale
pythonGH-73991: Fix "Operation not supported" on Fedora buildbot.
ccd9928
Follow-up to python#120806. Use `os_helper.skip_unless_xattr` to skip testing
xattr preservation when unsupported.
@barneygale barneygale mentioned this pull request Jul 6, 2024
GH-73991: Fix "Operation not supported" on Fedora buildbot. #121444
Merged
barneygale added a commit that referenced this pull request Jul 7, 2024
@barneygale
GH-73991: Fix "Operation not supported" on Fedora buildbot. (#121444)
b765e4a
Follow-up to #120806. Use `os_helper.skip_unless_xattr` to skip testing
xattr preservation when unsupported.
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
@barneygale @estyxx
pythonGH-73991: Support preserving metadata in pathlib.Path.copy() (p…
577c9ca
…ython#120806)

Add *preserve_metadata* keyword-only argument to `pathlib.Path.copy()`, defaulting to false. When set to true, we copy timestamps, permissions, extended attributes and flags where available, like `shutil.copystat()`. The argument has no effect on Windows, where metadata is always copied.

Internally (in the pathlib ABCs), path types gain `_readable_metadata` and `_writable_metadata` attributes. These sets of strings describe what kinds of metadata can be retrieved and stored. We take an intersection of `source._readable_metadata` and `target._writable_metadata` to minimise reads/writes. A new `_read_metadata()` method accepts a set of metadata keys and returns a dict with those keys, and a new `_write_metadata()` method accepts a dict of metadata. We *might* make these public in future, but it's hard to justify while the ABCs are still private.
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
@barneygale @estyxx
pythonGH-73991: Fix "Operation not supported" on Fedora buildbot. (py…
5aa4c45
…thon#121444)

Follow-up to python#120806. Use `os_helper.skip_unless_xattr` to skip testing
xattr preservation when unsupported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news topic-pathlib

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@barneygale @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.