-
Notifications
You must be signed in to change notification settings - Fork 409
localmemory: init #1905
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
localmemory: init #1905
Conversation
024a418
to
169cb50
Compare
169cb50
to
5953c86
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't expecting a new implementation - I thought you were thinking to change the existing one. This, of course, never has a chance to affect the existing tests and fixtures.
I wouldn't even bother putting this in a new module, since it's so similar to rmemoryFS.
point to different memory filesystems. | ||
""" | ||
|
||
pseudo_dirs = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why set the class variable even if none of the instances see it?
cachable = False # same as: skip_instance_cache = True | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.logger = logger # global |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why bother having this on this instance? We only even have one logger anyway.
def __init__(self, *args, **kwargs): | ||
self.logger = logger | ||
super().__init__(*args, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def __init__(self, *args, **kwargs): | |
self.logger = logger | |
super().__init__(*args, **kwargs) |
yes... that was a quickfix i tried to implement this via the # fsspec/implementations/memory.py
class MemoryFileSystem(AbstractFileSystem):
store: ClassVar[dict[str, Any]] = {} # global, do not overwrite!
pseudo_dirs = [""] # global, do not overwrite!
protocol = "memory"
root_marker = "/"
_intrans = False
def __init__(self, *args, **kwargs):
self.logger = logger
print("init kwargs", kwargs) # FIXME this always prints {}
skip_instance_cache = kwargs.get("skip_instance_cache", False)
if skip_instance_cache:
self.store = {}
self.pseudo_dirs = [""]
super().__init__(*args, **kwargs) # fsspec/implementations/tests/test_memory.py
import os
from pathlib import PurePosixPath, PureWindowsPath
import pytest
from fsspec.implementations.local import LocalFileSystem, make_path_posix
from fsspec.implementations.memory import MemoryFileSystem
def test_identical_instances():
fs1 = MemoryFileSystem()
fs2 = MemoryFileSystem()
assert id(fs1) == id(fs2)
assert id(fs1.store) == id(fs2.store)
fs1.touch("/fs1.txt")
fs2.touch("/fs2.txt")
assert fs1.ls("/", detail=False) == ["/fs1.txt", "/fs2.txt"]
assert fs2.ls("/", detail=False) == ["/fs1.txt", "/fs2.txt"]
def test_separate_instances():
fs1 = MemoryFileSystem(skip_instance_cache=True)
fs2 = MemoryFileSystem(skip_instance_cache=True)
assert id(fs1) != id(fs2)
assert id(fs1.store) != id(fs2.store) # FIXME this fails
fs1.touch("/fs1.txt")
fs2.touch("/fs2.txt")
assert fs1.ls("/", detail=False) == ["/fs1.txt"]
assert fs2.ls("/", detail=False) == ["/fs2.txt"] |
Correct, this happens in |
success. merged with - skip = kwargs.pop("skip_instance_cache", False)
+ skip = kwargs.get("skip_instance_cache", False) to pass i wanted to avoid adding a new parameter like |
Note the failure in s3fs:
This is expected - now you pass on an extra argument that implementations don't know about. Of course, this kwarg isn't much used in the tests, but the same could happen for other implementations that don't explicitly discard unneeded kwargs. |
How about either
|
sorry, abandoned (i would prefer "a flag in init" to not pollute the classes namespace) |
fix #1904
also fix the
memory
filesystem:all tests are passing: