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

memoryFS can't use Pathlike object to ls #1292

Closed
wgqimut opened this issue Jun 16, 2023 · 2 comments
Closed

memoryFS can't use Pathlike object to ls #1292

wgqimut opened this issue Jun 16, 2023 · 2 comments

Comments

@wgqimut
Copy link

wgqimut commented Jun 16, 2023

>>> from fsspec import filesystem
>>> m = filesystem("memory")
>>> m.mkdir("/a/b")
>>> m.ls("/a")
[{'name': '/a/b', 'size': 0, 'type': 'directory'}]
>>> from pathlib import Path
>>> a = Path("/a")
>>> m.ls(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/eleven/.local/lib/python3.11/site-packages/fsspec/implementations/memory.py", line 37, in ls
    path = self._strip_protocol(path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/eleven/.local/lib/python3.11/site-packages/fsspec/implementations/memory.py", line 29, in _strip_protocol
    if path.startswith("memory://"):
       ^^^^^^^^^^^^^^^
AttributeError: 'PosixPath' object has no attribute 'startswith'

I think the memoryFS shouldn't implement it's own _strip_protocol, which is merged by #654 .

@martindurant
Copy link
Member

As you can see in that PR, there are some peculiarities of memoryFS that require particular coding in _strip_protocol. It should maybe call super()._strip_protocol as part of its call, which may solve this.

However, it's not exactly obvious that Path objects ought to work with non-standard filesystems like memory. I am not strongly against, but I don't see the motivation. Have you tried https://github.com/fsspec/universal_pathlib ?

@wgqimut
Copy link
Author

wgqimut commented Jun 17, 2023

Have you tried https://github.com/fsspec/universal_pathlib ?

No I'm not, this repo is great! that's exactly what i'm looking for, thank you so much!

@wgqimut wgqimut closed this as not planned Won't fix, can't repro, duplicate, stale Jun 17, 2023
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