feat: allow overriding of some absolute paths using environment variables (#3102)

* Allow overriding of alembic config file path using environment variable

Signed-off-by: Litchi Pi <litchi.pi@proton.me>

* Allow overriding of MODEL_PATH using environment variable

Signed-off-by: Litchi Pi <litchi.pi@proton.me>

---------

Signed-off-by: Litchi Pi <litchi.pi@proton.me>
This commit is contained in:
Litchi Pi 2024-02-13 20:30:07 +01:00 committed by GitHub
parent fb9be66f97
commit 3d73e7498f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import os
from collections.abc import Callable
from pathlib import Path
from time import sleep
@ -87,7 +88,12 @@ def main():
if max_retry == 0:
raise ConnectionError("Database connection failed - exiting application.")
alembic_cfg = Config(str(PROJECT_DIR / "alembic.ini"))
alembic_cfg_path = os.getenv("ALEMBIC_CONFIG_FILE", default=str(PROJECT_DIR / "alembic.ini"))
if not os.path.isfile(alembic_cfg_path):
raise Exception("Provided alembic config path doesn't exist")
alembic_cfg = Config(alembic_cfg_path)
if db_is_at_head(alembic_cfg):
logger.debug("Migration not needed.")
else:

View File

@ -1,3 +1,4 @@
import os
import subprocess
import tempfile
from fractions import Fraction
@ -13,7 +14,7 @@ from . import utils
from .pre_processor import pre_process_string
CWD = Path(__file__).parent
MODEL_PATH = CWD / "model.crfmodel"
MODEL_PATH = os.getenv("CRF_MODEL_PATH", default=CWD / "model.crfmodel")
class CRFConfidence(BaseModel):