pfnet / pfio

IO library to access various filesystems with unified API
https://pfio.readthedocs.io/
MIT License
52 stars 20 forks source link

Remove v2.FS from v2.Path context #325

Closed kuenishi closed 4 months ago

kuenishi commented 11 months ago

pfio.v2.Path shall be independent from pfio.v2.FS implementations such as S3 and so on as it includes too much information to represent generic paths and its manipulations. In this PR, it deprecates giving pfio.v2.FS to the constructor of pfio.v2.Path, and add a new method .scope() to FS for calling file access methods from Path such as open and exists.

Before:

with from_url('s3://bucket/path/to/dir') as s3:
  p = Path('path/to/file', fs=s3)
  p.open().read()

After this PR, we can do this:

p = Path('path/to/file')
with from_url('s3://bucket/path/to/dir') as s3:
  with s3.scope():
    p.open().read()

Current style (above) remains supported for 2.7.x, but will be removed in 2.8.

kuenishi commented 4 months ago

Closing in favor of https://github.com/pfnet/pfio/pull/331 .