[Python-Dev] Improvements for Pathlib

Ionel Cristian Mărieș contact at ionelmc.ro
Sat Nov 8 16:46:08 CET 2014


Hello,

In the current incarnation Pathlib is missing some key features I need in
my usecases. I want to contribute them but i'd like a bit of feedback on
the new api before jumping to implementation.

The four things I need are:

#1. A context manager for temporary files and dirs (that cleans everything
up on exit). Eg:

with pathlib.TmpDir(suffix='', prefix='') as tmp:
  assert isinstance(tmp, pathlib.Path)

with pathlib.TmpFile(suffix='', prefix='') as tmp:
  assert isinstance(tmp, pathlib.Path)

#2. A context manager for changing working directory (that switches to the
old cwd on exit). Eg:

with path.cd():
 assert os.getcwd() == path

#
​3​
. Shutil-like features:

- copy_file
- copy_dir (or copy_tree?)
- copy (does copy_dir or copy_file depending on what the source is. How to
handle symlinks?)
- rm_dir (or rm_tree? Also, this would be required for the TmpDir path).

#4. Zip files support. A specialised Path subclass that works inside a zip
file. I'm ok having this as an external package but some discussion would
be useful as I'd have to rely on pathlib internals.

After some brief looking in the pathlib code it would appear the wise thing
would be to have the zip path as the "drive" for the ZipPaths that refer to
files inside the zip.

I'm not sure where the best place is to store the internal zipfile object.
Perhaps the accessor?

Ideally the ZipFiles would work with the shtuil-like api just fine (or at
least the readonly operations).

Thanks,
-- Ionel M.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20141108/61000b7d/attachment.html>


More information about the Python-Dev mailing list