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
| 16 | |
| 17 | |
| 18 | class 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 | |
| 56 | class TeleportLocalState: |