Skip to content
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

[Feature Request] fsspec/universal_pathlib integration #60

Open
Mithrandir2k18 opened this issue Mar 11, 2025 · 3 comments
Open

[Feature Request] fsspec/universal_pathlib integration #60

Mithrandir2k18 opened this issue Mar 11, 2025 · 3 comments

Comments

@Mithrandir2k18
Copy link

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:

from fsspec import AbstractFileSystem
from upath import UPath
from upath.registry import register_implementation

from morefs.memory import MemFS

# local instance for inspectability during testing
mem_fs = MemFS()


class MorefsMemPath(UPath):
    @classmethod
    def _fs_factory(
        cls, urlpath: str, protocol: str, storage_options: dict
    ) -> AbstractFileSystem:
        return mem_fs  # this should be MemFS(...)


fsname = "customfs"
register_implementation(fsname, MorefsMemPath)


def test_upath():
    testtext = "Hello from MemFS!"
    testfile = "/example.txt"
    p = UPath(f"{fsname}:///{testfile}")
    p.write_text(testtext)
    assert testtext == p.read_text()
    assert mem_fs.ls("/") == [testfile]
@skshetry
Copy link
Member

skshetry commented Mar 11, 2025

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.

@Mithrandir2k18
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants