Skip to content

Commit 18a81d7

Browse files
committed
fix config in the future but it kinda does the thing it is supposed to right now
1 parent 676c694 commit 18a81d7

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

shelloracle/config/config.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from collections.abc import MutableMapping
22
from pathlib import Path
3+
from typing import Any
34

45
import tomlkit
56

6-
data_home = Path.home() / "Library/Application Support" / "shelloracle"
7+
data_home = Path.home() / ".shelloracle"
78

89

910
def _default_config() -> tomlkit.TOMLDocument:
@@ -20,27 +21,35 @@ class Configuration(MutableMapping):
2021
def __init__(self) -> None:
2122
self._ensure_config_exists()
2223

23-
def __getitem__(self, item):
24+
def __getitem__(self, item: str) -> dict:
2425
with self.filepath.open("r") as file:
2526
config = tomlkit.load(file)
2627
return config[item]
2728

28-
def __setitem__(self, key, value):
29+
def __setitem__(self, key: str, value: Any) -> None:
2930
with self.filepath.open("r") as file:
3031
config = tomlkit.load(file)
3132
config[key] = value
3233
config.multiline = True
3334
with self.filepath.open("w") as file:
3435
tomlkit.dump(config, file)
3536

36-
def __delitem__(self, key):
37-
raise NotImplementedError()
37+
def __delitem__(self, key: str) -> None:
38+
with self.filepath.open("r") as file:
39+
config = tomlkit.load(file)
40+
del config[key]
41+
with self.filepath.open("w") as file:
42+
tomlkit.dump(config, file)
3843

39-
def __iter__(self):
40-
raise NotImplementedError()
44+
def __iter__(self) -> None:
45+
with self.filepath.open("r") as file:
46+
config = tomlkit.load(file)
47+
return iter(config)
4148

4249
def __len__(self) -> int:
43-
raise NotImplementedError()
50+
with self.filepath.open("r") as file:
51+
config = tomlkit.load(file)
52+
return len(config)
4453

4554
def _ensure_config_exists(self) -> None:
4655
if self.filepath.exists():

shelloracle/config/setting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, *, default: T | None = None) -> None:
1616

1717
def __set_name__(self, owner: type[Provider], name: str) -> None:
1818
self.name = name
19-
# Set the default value in the config dictionary
19+
# Set the default value in the config dictionary if it doesn't exist
2020
provider_table = config.global_config.get("provider", {})
2121
provider_table.setdefault(owner.name, {}).setdefault(name, self.default)
2222
config.global_config["provider"] = provider_table

0 commit comments

Comments
 (0)