[Python-ideas] New PEP proposal -- Pathlib Module ShouldContain All File Operations -- version 2

Chris Barker chris.barker at noaa.gov
Fri Mar 23 21:46:35 EDT 2018


On Fri, Mar 23, 2018 at 3:38 PM, Wes Turner <wes.turner at gmail.com> wrote:

> Here's a comparison table of os, os.path, shutil, pathlib, and path.py.
>

Darn, that's a big list -- exactly what we want to avoid :-(

Though there are bunch of string methods in there that we can dump right
off the bat.

> ... trio wraps pathlib methods with async; which also might as well be
done in pathlib?

hmm --that's s touch one -- a full set of async file operations would be
great. But where to put them????

and most of what we are talking about doesn't need asnyc, does it?
deleting/renaming a single, file, etc.

So my thought is that an asnyc lib should mirror / overwrite this
file-operations-api. Which makes it a problem for the async lib(s) later on
down the road.

BTW -- this is a nice argument for making this API in the first place --
then we have a single API to make an async version of!

- Does it make sense to copy the docstrings at import time every time?

copy from where? is this for the async version? or are you thinking that
the new methods will simply be wrappers for the olds ones -- in which case,
I think no -- this should be a new API with its own docs, whether or not a
particular call is any different that the "old" one.

The big challenge is to identity what is "basic" or "normal" ratehr than
advanced.

here's a quick take on trimming down that whole table -- jsut my quick HO:

attr table
==========

================== == ======= ====== ======= =======
attr               os os.path shutil pathlib path.py
================== == ======= ====== ======= =======
`absolute`_                          X
`abspath`_            X                       X
`access`_          X                          X
`atime`_                                      X
`basename`_           X                       X

`cd`_                                         X

`commonpath`_         X
`commonprefix`_       X
`copy`_                       X               X
`copytree`_                   X               X

`curdir`_          X  X
`dirname`_            X                       X

`drive`_                             X        X

`exists`_             X              X        X

`expanduser`_         X              X        X
`expandvars`_         X                       X
`ext`_                                        X

`fnmatch`_                    X               X

`get_owner`_                                  X
`getatime`_           X                       X
`getctime`_           X                       X

`getcwd`_          X                          X
`getmtime`_           X                       X

`getsize`_            X                       X

`glob`_                              X        X
`home`_                              X
`is_absolute`_                       X
`is_dir`_                            X

`is_symlink`_                        X
`isabs`_              X                       X

`isdir`_              X                       X
`isfile`_             X                       X
`islink`_             X                       X

`iterdir`_                           X

`lchmod`_                            X

`link`_            X                          X
`listdir`_         X                          X

`lstat`_           X                 X        X

`mkdir`_           X                 X        X
`makedirs`_        X                          X

`match`_                             X
`merge_tree`_                                 X

`move`_                       X               X
`mtime`_                                      X

`normcase`_           X                       X
`normpath`_           X                       X

`open`_            X                 X        X

`owner`_                             X        X

`parent`_                            X        X
`parents`_                           X

`relative_to`_                       X
`relpath`_            X                       X
`relpathto`_                                  X

`remove`_          X                          X

`removedirs`_      X                          X
`rename`_          X                 X        X
`replace`_         X                 X        X
`resolve`_                           X
`rglob`_                             X
`root`_                              X

`samefile`_           X              X        X

`size`_                                       X
`suffix`_                            X
`suffixes`_                          X
`symlink`_         X                          X
`symlink_to`_                        X
`touch`_                             X        X
`utime`_           X                          X
`walk`_            X                          X
`with_name`_                         X
`with_suffix`_                       X        X
`write_bytes`_                       X        X
`write_text`_                        X        X


These are about permissions -- challenging how to do that in a X-platform
way...
And it would be good to group this sort of thing together.

`chmod`_           X                 X        X
`chown`_           X          X               X

================== == ======= ====== ======= =======

Now that I've done that, I think it would be better to be systematic:

1) keep every method that pathlib.Path has
2) dump every method this is only a string method (and maybe everything
that path has that nothign else has -- most of those are string methods
3) match the ones that are the same thing, but different names
4) match the ones that are almost the same thing:remove and removedir and
removedirs
  - then we can hash out whether to join with flags, or keep separate
5) group by "class of functionality:
   - file nameing, etc
   - seraching (glob)
   - permission handling
   - etc.

That'll get it structured to capture the discussion.

-CHB

> Tinkered around at lunchtime with a module to bring them under one roof.
Named it "f2" because "fs" was taken on PyPI and thought the name should be
very short since it could potentially be used in every script, like os and
sys are.

>
>     https://github.com/mixmastamyk/f2
>

This is a great idea to have a prototype of sorts, but I do'nt think we
should take the approach of: make it, put it on pypi, and see if it gains
traction -- this isn't adding anythign new, very few folks are going to
want to crate a dependency to get a more discoverable api, and no one going
to point newbies at it.

Just poking around these questions came up about what to include:
>
>     - Include file descriptors apis?
>
no -- unless in an "advanced" api somewhere

    - chroot?
>
no

>     - l- functions to not follow links?
>
maybe adanced, or optional flags


>     - Unix dev files?  obscure
>

don't even know what this is, so no :-)

    - pathconf?
>

again, what is this? probabaly no.


>     - supports_* api?
>

no.


>     - Only scandirs or walk too?
>

walk is really useful and not trivial to write, so yes.



>     - Should unpack os.path functions into the root?  Handy but many of
> them.
>

no way.


>     - Unpack file-related shutil functions?  Or leave as submodule?
>

make them methods on Path.

-CHB




-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180323/6fa1cfbc/attachment-0001.html>


More information about the Python-ideas mailing list