Skip to content

Commit

Permalink
Fix: ensure .env loading from project root directory (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
skytin1004 authored Dec 20, 2024
1 parent 4392369 commit 255a7b5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>", "timothychungd <[email protected]>"]
maintainers = []
Expand Down
7 changes: 0 additions & 7 deletions src/co_op_translator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
26 changes: 24 additions & 2 deletions src/co_op_translator/config/base_config.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()

0 comments on commit 255a7b5

Please sign in to comment.