configuration is now a TypedDict in its own module

This commit is contained in:
2023-08-16 08:14:41 +02:00
parent 4303fb414f
commit dc13213c4d
5 changed files with 43 additions and 26 deletions
+8 -7
View File
@@ -1,7 +1,8 @@
import yaml
import io
import pathlib
from .utils import terminal_width, append_message, message_to_chat, ConfigType, ChatType
from .utils import terminal_width, append_message, message_to_chat, ChatType
from .configuration import Config
from typing import Any, Optional
@@ -22,13 +23,13 @@ def read_file(fname: pathlib.Path, tags_only: bool = False) -> dict[str, Any]:
"file": fname.name}
def read_config(path: str) -> ConfigType:
def read_config(path: str) -> Config:
with open(path, 'r') as f:
config = yaml.load(f, Loader=yaml.FullLoader)
return config
def write_config(path: str, config: ConfigType) -> None:
def write_config(path: str, config: Config) -> None:
with open(path, 'w') as f:
yaml.dump(config, f)
@@ -52,7 +53,7 @@ def save_answers(question: str,
answers: list[str],
tags: list[str],
otags: Optional[list[str]],
config: ConfigType
config: Config
) -> None:
wtags = otags or tags
num, inum = 0, 0
@@ -77,7 +78,7 @@ def save_answers(question: str,
def create_chat_hist(question: Optional[str],
tags: Optional[list[str]],
extags: Optional[list[str]],
config: ConfigType,
config: Config,
match_all_tags: bool = False,
with_tags: bool = False,
with_file: bool = False
@@ -108,7 +109,7 @@ def create_chat_hist(question: Optional[str],
return chat
def get_tags(config: ConfigType, prefix: Optional[str]) -> list[str]:
def get_tags(config: Config, prefix: Optional[str]) -> list[str]:
result = []
for file in sorted(pathlib.Path(str(config['db'])).iterdir()):
if file.suffix == '.yaml':
@@ -127,5 +128,5 @@ def get_tags(config: ConfigType, prefix: Optional[str]) -> list[str]:
return result
def get_tags_unique(config: ConfigType, prefix: Optional[str]) -> list[str]:
def get_tags_unique(config: Config, prefix: Optional[str]) -> list[str]:
return list(set(get_tags(config, prefix)))