Skip to content

Commit 744c34a

Browse files
authored
Support for HAYHOOKS env var prefix (#65)
* Add support to 'hayhooks_*' to env variables (to avoid conflicts with other similar ones) * Add test for 'hayhooks_*' env var ; remove unneeded test
1 parent 8aa18ca commit 744c34a

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

.env.example

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Host for the FastAPI app
2-
HOST="localhost"
2+
HAYHOOKS_HOST="localhost"
33

44
# Port for the FastAPI app
5-
PORT=1416
5+
HAYHOOKS_PORT=1416
66

77
# Root path for the FastAPI app
8-
ROOT_PATH=""
8+
HAYHOOKS_ROOT_PATH=""
99

1010
# Path to the directory containing the pipelines
11-
PIPELINES_DIR="pipelines"
11+
HAYHOOKS_PIPELINES_DIR="pipelines"
1212

1313
# Additional Python path to be added to the Python path
14-
ADDITIONAL_PYTHON_PATH=""
14+
HAYHOOKS_ADDITIONAL_PYTHON_PATH=""

src/hayhooks/settings.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from pydantic import field_validator
2-
from pydantic_settings import BaseSettings
1+
from pydantic_settings import BaseSettings, SettingsConfigDict
32
from dotenv import load_dotenv
43
from pathlib import Path
54

@@ -29,5 +28,9 @@ class AppSettings(BaseSettings):
2928
# Files to ignore when reading pipeline files from a directory
3029
files_to_ignore_patterns: list[str] = ["*.pyc", "*.pyo", "*.pyd", "__pycache__", "*.so", "*.egg", "*.egg-info"]
3130

31+
# Prefix for the environment variables to avoid conflicts
32+
# with other similar environment variables
33+
model_config = SettingsConfigDict(env_prefix='hayhooks_')
34+
3235

3336
settings = AppSettings()

tests/test_settings.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ def temp_dir(tmp_path):
1212
shutil.rmtree(tmp_path)
1313

1414

15-
def test_default_pipelines_dir():
16-
settings = AppSettings()
17-
assert settings.pipelines_dir == str(Path(__file__).parent.parent / "pipelines")
18-
19-
2015
def test_custom_pipelines_dir(temp_dir):
2116
custom_dir = temp_dir / "custom_pipelines"
2217
settings = AppSettings(pipelines_dir=str(custom_dir))
@@ -36,3 +31,9 @@ def test_host():
3631
def test_port():
3732
settings = AppSettings(port=1234)
3833
assert settings.port == 1234
34+
35+
36+
def test_env_var_prefix(monkeypatch):
37+
monkeypatch.setenv("HAYHOOKS_PORT", "5678")
38+
settings = AppSettings()
39+
assert settings.port == 5678

0 commit comments

Comments
 (0)