You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I understand it, this package cannot be used with universal pathlib right away, but all the building block are already there. All that's missing is registering the AbstractFileSystem subclasses with fsspec and creating fsspec/universal_pathlib subclasses and registering them with their registry.
This seems simple enough and seems to work in my testing:
fromfsspecimportAbstractFileSystemfromupathimportUPathfromupath.registryimportregister_implementationfrommorefs.memoryimportMemFS# local instance for inspectability during testingmem_fs=MemFS()
classMorefsMemPath(UPath):
@classmethoddef_fs_factory(
cls, urlpath: str, protocol: str, storage_options: dict
) ->AbstractFileSystem:
returnmem_fs# this should be MemFS(...)fsname="customfs"register_implementation(fsname, MorefsMemPath)
deftest_upath():
testtext="Hello from MemFS!"testfile="/example.txt"p=UPath(f"{fsname}:///{testfile}")
p.write_text(testtext)
asserttesttext==p.read_text()
assertmem_fs.ls("/") == [testfile]
The text was updated successfully, but these errors were encountered:
I think universal-pathlib is supposed to work right out of the box without requiring explicit registration (which I am not against, PR welcome).
So, UPath("memfs://") should just work. Although, compared to fsspec's MemoryFileSystem, morefs's memfs and dictfs are not global. So I see that every child paths get created with different filesystem instances.
Thanks for the speedy reply. Yeah I am new to fsspec and totally missed that there was a mechanism for this upstream already.
For my usecase, memfs filesystems not being global works out well anyway.
I wouldn't mind creating a PR, but since it's already implemented as a flavour upstream, what benefit would explicitly registering bring? And registering would require adding a (optional) dependency to the universal_pathlib repo, for as I see it, hardly any benefit/noticeable change? Maybe it could introduce a global variant?
As far as I understand it, this package cannot be used with universal pathlib right away, but all the building block are already there. All that's missing is registering the
AbstractFileSystem
subclasses with fsspec and creating fsspec/universal_pathlib subclasses and registering them with their registry.This seems simple enough and seems to work in my testing:
The text was updated successfully, but these errors were encountered: