diff --git a/hera_librarian/settings.py b/hera_librarian/settings.py index 030c5c5..cb40145 100644 --- a/hera_librarian/settings.py +++ b/hera_librarian/settings.py @@ -8,6 +8,11 @@ from pydantic import BaseModel from pydantic_settings import BaseSettings +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + client_settings: "ClientSettings" + class ClientInfo(BaseModel): """ @@ -39,12 +44,17 @@ def load_settings() -> ClientSettings: global _settings try_paths = [ - Path(os.environ["HL_CLIENT_CONFIG"]), + os.environ.get("HL_CLIENT_CONFIG", None), Path.home() / ".hl_client.cfg", Path.home() / ".hl_client.json", ] for path in try_paths: + if path is not None: + path = Path(path) + else: + continue + if path.exists(): _settings = ClientSettings.from_file(path) return _settings diff --git a/librarian_server/settings.py b/librarian_server/settings.py index 0a0211b..8ece347 100644 --- a/librarian_server/settings.py +++ b/librarian_server/settings.py @@ -11,6 +11,11 @@ from .stores import StoreNames +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + server_settings: "ServerSettings" + class StoreSettings(BaseModel): """ @@ -87,10 +92,15 @@ def load_settings() -> ServerSettings: global _settings try_paths = [ - Path(os.environ["LIBRARIAN_CONFIG_PATH"]), + os.environ.get("LIBRARIAN_CONFIG_PATH", None), ] for path in try_paths: + if path is not None: + path = Path(path) + else: + continue + if path.exists(): _settings = ServerSettings.from_file(path) return _settings