-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relative paths don't work when _protocol_dispatch = False
.
#211
Comments
Hello @keunhong, When protocol dispatch is turned off, the default implementation of Could you kindly elaborate on your specific use case? Perhaps together we can explore alternative solutions that are easier to manage. Best regards, |
I wanted to subclass
Is there a way to achieve this without turning off protocol dispatch? |
A few more questions:
In the "single protocol" case, let's say for from upath.implementations.cloud import S3Path
from upath.registry import register_implementation
class MyS3Path(S3Path):
def open(...):
...
register_implementation("s3", MyS3Path, clobber=True)
assert isinstance(UPath('s3://bucket/file'), MyS3Path) The "all (or many) protocols" case is currently not well supported due to the class inheritance structure replicated from stdlib pathlib. You would have to override the open method for every My recommended workaround for now would be to use a context manager that provides files from the cache. When #28 is implemented, you can then switch to using The context manager could look like this: from contextlib import contextmanager
@contextmanager
def open_cached(pth: UPath, mode, *args, **fsspec_kwargs):
storage_options = {**pth.storage_options, **fsspec_kwargs}
cache_storage = storage_options.get("cache_storage")
cache_timeout = storage_options.get("cache_timeout")
# If caching is configured and this is a file read, use a cached read.
if "r" in mode and cache_storage is not None:
fs = fsspec.filesystem(
"filecache",
fs=pth.fs,
cache_storage=str(cache_storage)
cache_timeout=cache_timeout,
)
yield fs.open(pth.path, mode, *args, **storage_options)
else:
yield pth.open(mode, *args, **fsspec_kwargs) |
Ah I see the issue now. I wanted the second behavior you mentioned which is having Thank you for the help, and for the excellent library! |
The base
pathlib.Path
andupath.PosixUPath
correctly handle relative paths, but when subclassed relative paths stop working. A prefix/
is always prepended:The text was updated successfully, but these errors were encountered: