Skip to content

Commit d117154

Browse files
committed
feat(config): switched from os module usage to pathlib
1 parent a03d0d3 commit d117154

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/docbinder_oss/helpers/config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
2-
import os
2+
from pathlib import Path
33
from typing import List
4-
54
import typer
65
import yaml
76
from pydantic import BaseModel, ValidationError
@@ -10,23 +9,23 @@
109

1110
logger = logging.getLogger(__name__)
1211

13-
CONFIG_PATH = os.path.expanduser("~/.config/docbinder/config.yaml")
14-
12+
CONFIG_PATH = Path("~/.config/docbinder/config.yaml").expanduser()
1513

1614
class Config(BaseModel):
1715
"""Main configuration model that holds a list of all provider configs."""
18-
1916
providers: List[ServiceUnion]
2017

2118

2219
def load_config() -> Config:
23-
if not os.path.exists(CONFIG_PATH):
20+
if not CONFIG_PATH.exists():
2421
typer.echo(
2522
f"Config file not found at {CONFIG_PATH}. Please run 'docbinder setup' first."
2623
)
2724
raise typer.Exit(code=1)
25+
2826
with open(CONFIG_PATH, "r") as f:
2927
config_data = yaml.safe_load(f)
28+
3029
provider_registry = get_provider_registry()
3130
config_to_add = []
3231
for config in config_data.get("providers", []):
@@ -45,7 +44,8 @@ def load_config() -> Config:
4544

4645

4746
def save_config(config: Config):
48-
os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True)
47+
CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
48+
4949
with open(CONFIG_PATH, "w") as f:
5050
yaml.dump(config.model_dump(), f, default_flow_style=False)
5151
typer.echo(f"Config saved to {CONFIG_PATH}")

0 commit comments

Comments
 (0)