Skip to content

Commit fcc8f3b

Browse files
committed
fixed env variables
1 parent 96a6370 commit fcc8f3b

4 files changed

Lines changed: 22 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ jobs:
1010
build:
1111
runs-on: ubuntu-latest
1212

13+
env:
14+
HF_API_KEY: ${{ secrets.HF_API_KEY }}
15+
DB_URL: ${{ secrets.DB_URL }}
16+
1317
steps:
1418
- uses: actions/checkout@v3
1519
- name: Set Up Python
@@ -21,7 +25,6 @@ jobs:
2125
run: |
2226
pip install poetry
2327
poetry install
24-
2528
- name: Run tests
2629
run: |
2730
poetry run pytest

src/rowgen/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
from huggingface_hub import InferenceClient
55
import sqlalchemy
66
from dotenv import load_dotenv
7-
from utils import ENV_PATH
7+
from utils import API_KEY
88

9-
load_dotenv(dotenv_path=ENV_PATH)
10-
API_KEY = os.getenv("HF_API_KEY")
119
print()
1210

1311

src/rowgen/utils.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from pathlib import Path
22

3+
from dotenv import load_dotenv
4+
import os
5+
36

47
def find_project_root(start_path: Path = None, marker_files=None) -> Path:
58
"""
@@ -33,13 +36,20 @@ def find_project_root(start_path: Path = None, marker_files=None) -> Path:
3336
current = current.parent
3437

3538

36-
def get_env_file_path() -> Path:
39+
def get_api_key() -> str:
3740
"""
38-
Finds and returns the path of .env file.
39-
:return: Path object.
41+
Returns the API key from environment, loading .env if running locally.
4042
"""
41-
root = find_project_root()
42-
return f"{root}/.env"
43+
# Load .env only if not already set (e.g., local dev)
44+
if "HF_API_KEY" not in os.environ:
45+
env_path = find_project_root() / ".env"
46+
if env_path.exists():
47+
load_dotenv(dotenv_path=env_path)
48+
49+
api_key = os.getenv("HF_API_KEY")
50+
if not api_key:
51+
raise RuntimeError("HF_API_KEY is not set in the environment.")
52+
return api_key
4353

4454

45-
ENV_PATH = get_env_file_path()
55+
API_KEY = get_api_key()

tests/test_ai_api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
from dotenv import load_dotenv
55
from huggingface_hub.errors import BadRequestError
66

7-
from rowgen.utils import ENV_PATH
7+
from rowgen.utils import API_KEY
88
from huggingface_hub import InferenceClient, HfApi
99

10-
load_dotenv(dotenv_path=ENV_PATH)
11-
API_KEY = os.getenv("HF_API_KEY")
1210

1311
DEEP_SEEK_MODEL = "deepseek-ai/DeepSeek-V3"
1412

0 commit comments

Comments
 (0)