MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / LocalState

Class LocalState

misc/python/materialize/build_config.py:18–53  ·  view source on GitHub ↗

Local state persisted by a tool. Users should not expect this state to be durable, it can be blown away at at point. Stored at: ~/.cache/materialize/build_state.toml

Source from the content-addressed store, hash-verified

16
17
18class LocalState:
19 """Local state persisted by a tool.
20
21 Users should not expect this state to be durable, it can be blown away at
22 at point.
23
24 Stored at: ~/.cache/materialize/build_state.toml
25 """
26
27 def __init__(self, path: Path):
28 self.path = path
29 if path.is_file():
30 with open(path) as f:
31 self.data = toml.load(f)
32 else:
33 self.data = {}
34
35 @staticmethod
36 def default_path() -> Path:
37 home = Path.home()
38 path = home / ".cache" / "materialize" / "build_state.toml"
39 return path
40
41 @classmethod
42 def read(cls, namespace: str) -> Any | None:
43 cache = LocalState(LocalState.default_path())
44 return cache.data.get(namespace, None)
45
46 @classmethod
47 def write(cls, namespace: str, val: Any):
48 cache = LocalState(LocalState.default_path())
49 cache.data[namespace] = val
50
51 Path(os.path.dirname(cache.path)).mkdir(parents=True, exist_ok=True)
52 with open(cache.path, "w+") as f:
53 toml.dump(cache.data, f)
54
55
56class TeleportLocalState:

Callers 2

readMethod · 0.85
writeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected