Repository navigation
v0.1.0
Published as pathlib-next up to 0.10.0; from 0.1.0 as pathapi. The released
sections below keep the name they were published under.
Added
supports()andcapabilities(): which protocols a path class implements.
pathapi.protocols.supports(obj_or_class, *protocols)is true when every
primitive of every protocol named is something other than its default stub, and
capabilities(obj_or_class)lists the protocols that hold. Ask once instead of
calling and catchingNotImplementedError. The answer is advisory: a primitive may
still refuse an argument. A class whose answer depends on its connection defines
_supports(protocol) -> bool | None.- The operations of
Pathare protocols you can mix in.Create(mkdir,
touch),Listing(iterdir,glob,rglob,walk),Remove(unlink,rmdir,
rm),Readlink(readlink),Symlink(symlink_to),Identity(samefile),Copy,Move
and the pure-path descriptionNamedare inpathapi.protocols, and
Pathis built from them. A read-only backend can be a class built fromPathname,
Listing,StatandBinaryOpenwith noPath:glob,checksum.md5
andPathSyncertake it as a source. Chmodis split, and so is every pair of a reader and a writer.Chown
(chown()),Owned(owner(),group()),Utime(_utime()),Readlinkand
Symlinkare protocols of their own, sosupports(path, Chmod)asks forchmod()
alone and an archive supportsReadlinkand notSymlink.Chmodstill inherits
ChownandUtime, sochown,_chownand_utimestay reachable from it.owner(),group(),readlink(),hardlink_to(),absolute()andresolve()
on everyPath. A backend supplies_user_name()and_group_name(),
readlink(),_hardlink_to()and_cwd();resolve()follows links through
readlink(), at most 40, and is lexical where a class has none.LocalPathkeeps
pathlib's own.- The contract suites' switches
supports_listing,supports_mkdir,
supports_delete,supports_utimeandsupports_renamedefault toNone, which
askssupports()aboutListing,Create,Remove,UtimeandMove, so a class
without a protocol skips those tests with no switch set and the skip names the
protocol. Set one toTrueorFalseon the test class to override the answer. providers.primitivemarks a default of a primitive whose body raises an error of its
own, sosupports()reads it as absent.providers.derived_from(*primitives)marks a method that only wraps other
primitives, so a base class can defineiterdir()over_listdir()and
supports()still says a subclass without_listdir()cannot list.providers.notimplementedtakes a reason:@notimplemented("why")marks a stub
thatsupports()reads as absent and whoseNotImplementedErrorcarries the
reason; the bare form is unchanged.
Changed
-
The distribution, the import package and the repository are
pathapi. Version
numbering restarts at 0.1.0.pathlib-next0.10.1 is a final release that depends on
pathapiand re-exports it under the old import name with aDeprecationWarning.
What to do: installpathapiand change the names in this table.Before After pip install pathlib-nextpip install pathapiimport pathlib_next,pathlib_next.<module>import pathapi,pathapi.<module>entry-point group pathlib_next.http_transportspathapi.http_transportspathlib-next-requests(pathlib_next_requests)pathapi-requests(pathapi_requests)PATHLIB_NEXT_HTTP_TRANSPORTPATHAPI_HTTP_TRANSPORTthe pathlib-next/<version>user agent, the.pathlib-next-tmpsuffix of aPathSyncertemporary siblingpathapi/<version>,.pathapi-tmpthe pathlib_next.syncandpathlib_next.httploggerspathapi.sync,pathapi.httpbenchmark result schema pathlib_next.bench/1pathapi.bench/1 -
copy()over an existing file does not callunlink()on a target whose class has no
Remove(it replaces the content throughopen()), andmove()raises
NotImplementedErrorbefore copying when the source cannot be removed and has no
rename()to use. Before, the first raised from theunlink()and the second left
the file in two places. What to do: nothing, unless you relied on either. -
Every
Pathnow has areadlink(), which raisesNotImplementedErrorwhere the class
cannot read links, sohasattr(path, "readlink")no longer tells the two apart. What
to do: asksupports(path, Readlink). -
A write stream that commits on close (
CommitOnClose, and any stream built on
DiscardOnError), or the text file over one, that is garbage collected without being
closed is now discarded with aResourceWarninginstead of committed, as awith
block that raised already was. Before, the collector closed it and so uploaded or
rewrote what the program never finished. What to do: close the file (usewith);
a stream of your own onDiscardOnErrorcan override_holds_uncommitted()to stay
silent when it has nothing to commit. -
_supports(protocol)may make at most one request per backend, cached for the
backend's lifetime, and never raises (it answersNonewhen the request fails).
Full Changelog: v0.10.0...v0.1.0