diff --git a/pyproject.toml b/pyproject.toml index 2e4df62..be344f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "co_op_translator" -version = "0.6.1" +version = "0.6.2" description = "Easily automate multilingual translations for your projects with co-op-translator, powered by advanced LLM technology." authors = ["Minseok Song ", "timothychungd "] maintainers = [] diff --git a/src/co_op_translator/__main__.py b/src/co_op_translator/__main__.py index 3ddd58c..d248e93 100644 --- a/src/co_op_translator/__main__.py +++ b/src/co_op_translator/__main__.py @@ -3,17 +3,10 @@ import click import importlib.resources import yaml -from pathlib import Path -from dotenv import load_dotenv from co_op_translator.core.project.project_translator import ProjectTranslator from co_op_translator.config.base_config import Config from co_op_translator.config.vision_config.config import VisionConfig -# Load .env from the root directory -root_dir = Path(__file__).resolve().parent.parent.parent -env_path = root_dir / '.env' -load_dotenv(dotenv_path=env_path) - logger = logging.getLogger(__name__) @click.command() diff --git a/src/co_op_translator/config/base_config.py b/src/co_op_translator/config/base_config.py index 6f9437a..4bce599 100644 --- a/src/co_op_translator/config/base_config.py +++ b/src/co_op_translator/config/base_config.py @@ -1,6 +1,7 @@ import os import logging from pathlib import Path +from dotenv import load_dotenv from co_op_translator.config.llm_config.config import LLMConfig from co_op_translator.config.vision_config.config import VisionConfig @@ -12,13 +13,34 @@ class Config: """ @classmethod - def check_configuration(cls): + def load_environment(cls, root_dir='.'): """ - Checks if all required environment variables are set across all services. + Load environment variables from the target project's root directory. + + Args: + root_dir: Root directory of the target project (default is current directory). + """ + env_path = Path(root_dir) / '.env' + if env_path.exists(): + load_dotenv(dotenv_path=env_path) + else: + logger.debug(f"No .env file found in {env_path}") + + @classmethod + def check_configuration(cls, root_dir='.'): + """ + Load environment variables and check if all required variables are set across all services. Raises an OSError if any required environment variables are missing. + + Args: + root_dir: Root directory of the target project (default is current directory). """ + # Load environment variables first + cls.load_environment(root_dir) + # Check LLM configurations LLMConfig.check_configuration() # Check Vision configurations + VisionConfig.check_configuration() VisionConfig.check_configuration() \ No newline at end of file