Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit c0d2802

Browse files
committed
Refactor configuration handling in aicodebot
In the pursuit of simplicity and clarity, the configuration handling functions have been moved from `aicodebot/helpers.py` to a new file `aicodebot/config.py`. This change enhances the modularity of the code and makes it easier to manage and understand. The `cli.py` file has been updated accordingly to import these functions from their new location.
1 parent eb4c981 commit c0d2802

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

aicodebot/cli.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
from aicodebot import version as aicodebot_version
2-
from aicodebot.helpers import (
3-
exec_and_get_output,
4-
get_config_file,
5-
get_llm_model,
6-
get_token_length,
7-
git_diff_context,
8-
logger,
9-
read_config,
10-
)
2+
from aicodebot.config import get_config_file, read_config
3+
from aicodebot.helpers import exec_and_get_output, get_llm_model, get_token_length, git_diff_context, logger
114
from aicodebot.prompts import DEFAULT_PERSONALITY, PERSONALITIES, generate_files_context, get_prompt
125
from langchain.callbacks.base import BaseCallbackHandler
136
from langchain.chains import LLMChain

aicodebot/config.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from aicodebot.helpers import logger
2+
from pathlib import Path
3+
import os, yaml
4+
5+
6+
def get_config_file():
7+
if "AICODEBOT_CONFIG_FILE" in os.environ:
8+
config_file = Path(os.getenv("AICODEBOT_CONFIG_FILE"))
9+
else:
10+
config_file = Path(Path.home() / ".aicodebot.yaml")
11+
logger.debug(f"Using config file {config_file}")
12+
return config_file
13+
14+
15+
def read_config():
16+
"""Read the config file and return its contents as a dictionary."""
17+
config_file = get_config_file()
18+
if config_file.exists():
19+
logger.debug(f"Config file {config_file} exists")
20+
with Path(config_file).open("r") as f:
21+
return yaml.safe_load(f)
22+
else:
23+
logger.debug(f"Config file {config_file} does not exist")
24+
return None

0 commit comments

Comments
 (0)