diff --git a/ols/constants.py b/ols/constants.py index ecf7e902..6d8dd5a8 100644 --- a/ols/constants.py +++ b/ols/constants.py @@ -218,3 +218,7 @@ class GenericLLMParameters: # Default configuration file name DEFAULT_CONFIGURATION_FILE = "rcsconfig.yaml" + +# Environment variable containing configuration file name to override default +# configuration file +CONFIGURATION_FILE_NAME_ENV_VARIABLE = "RCS_CONFIG_FILE" diff --git a/ols/user_data_collection/data_collector.py b/ols/user_data_collection/data_collector.py index 1c362467..581e4a47 100644 --- a/ols/user_data_collection/data_collector.py +++ b/ols/user_data_collection/data_collector.py @@ -27,9 +27,14 @@ # initialize config from ols import config # pylint: disable=C0413 -from ols.constants import DEFAULT_CONFIGURATION_FILE # pylint: disable=C0413 +from ols.constants import ( # pylint: disable=C0413 + CONFIGURATION_FILE_NAME_ENV_VARIABLE, + DEFAULT_CONFIGURATION_FILE, +) -cfg_file = os.environ.get("RCS_CONFIG_FILE", DEFAULT_CONFIGURATION_FILE) +cfg_file = os.environ.get( + CONFIGURATION_FILE_NAME_ENV_VARIABLE, DEFAULT_CONFIGURATION_FILE +) config.reload_from_yaml_file( cfg_file, ignore_llm_secrets=True, ignore_missing_certs=True ) diff --git a/runner.py b/runner.py index 5f650a4a..43c167c2 100644 --- a/runner.py +++ b/runner.py @@ -6,7 +6,10 @@ import threading from pathlib import Path -from ols.constants import DEFAULT_CONFIGURATION_FILE +from ols.constants import ( + CONFIGURATION_FILE_NAME_ENV_VARIABLE, + DEFAULT_CONFIGURATION_FILE, +) from ols.runners.uvicorn import start_uvicorn from ols.src.auth.auth import use_k8s_auth from ols.utils.certificates import generate_certificates_file @@ -35,7 +38,9 @@ def load_index(): # else via our code before other envs are set (mainly the gradio). from ols import config - cfg_file = os.environ.get("RCS_CONFIG_FILE", DEFAULT_CONFIGURATION_FILE) + cfg_file = os.environ.get( + CONFIGURATION_FILE_NAME_ENV_VARIABLE, DEFAULT_CONFIGURATION_FILE + ) config.reload_from_yaml_file(cfg_file) configure_logging(config.ols_config.logging_config) diff --git a/scripts/generate_openapi_schema.py b/scripts/generate_openapi_schema.py index 9f60e0e6..c1afb5f2 100644 --- a/scripts/generate_openapi_schema.py +++ b/scripts/generate_openapi_schema.py @@ -13,10 +13,15 @@ ) from ols import config # pylint: disable=C0413 -from ols.constants import DEFAULT_CONFIGURATION_FILE +from ols.constants import ( + CONFIGURATION_FILE_NAME_ENV_VARIABLE, + DEFAULT_CONFIGURATION_FILE, +) # it is needed to read proper configuration in order to start the app to generate schema -cfg_file = os.environ.get("RCS_CONFIG_FILE", "scripts/" + DEFAULT_CONFIGURATION_FILE) +cfg_file = os.environ.get( + CONFIGURATION_FILE_NAME_ENV_VARIABLE, "scripts/" + DEFAULT_CONFIGURATION_FILE +) config.reload_from_yaml_file(cfg_file) from ols.app.main import app # noqa: E402 pylint: disable=C0413 diff --git a/tests/integration/test_liveness_readiness.py b/tests/integration/test_liveness_readiness.py index f0e7ad03..4fbb6761 100644 --- a/tests/integration/test_liveness_readiness.py +++ b/tests/integration/test_liveness_readiness.py @@ -8,6 +8,7 @@ from fastapi.testclient import TestClient from ols import config +from ols.constants import CONFIGURATION_FILE_NAME_ENV_VARIABLE client: TestClient @@ -16,7 +17,10 @@ # config file before we import anything from main.py @pytest.fixture(scope="function", autouse=True) @patch.dict( - os.environ, {"RCS_CONFIG_FILE": "tests/config/config_for_integration_tests.yaml"} + os.environ, + { + CONFIGURATION_FILE_NAME_ENV_VARIABLE: "tests/config/config_for_integration_tests.yaml" + }, ) def _setup(): """Setups the test client.""" diff --git a/tests/integration/test_metrics.py b/tests/integration/test_metrics.py index 75154aa2..527eaf18 100644 --- a/tests/integration/test_metrics.py +++ b/tests/integration/test_metrics.py @@ -11,6 +11,7 @@ from ols import config from ols.app.models.config import LoggingConfig +from ols.constants import CONFIGURATION_FILE_NAME_ENV_VARIABLE from ols.utils.logging_configurator import configure_logging client: TestClient @@ -31,7 +32,10 @@ # config file before we import anything from main.py @pytest.fixture(scope="function", autouse=True) @patch.dict( - os.environ, {"RCS_CONFIG_FILE": "tests/config/config_for_integration_tests.yaml"} + os.environ, + { + CONFIGURATION_FILE_NAME_ENV_VARIABLE: "tests/config/config_for_integration_tests.yaml" + }, ) def _setup(): """Setups the test client.""" diff --git a/tests/integration/test_openapi.py b/tests/integration/test_openapi.py index 330dfb0b..5504fc57 100644 --- a/tests/integration/test_openapi.py +++ b/tests/integration/test_openapi.py @@ -9,6 +9,7 @@ from fastapi.testclient import TestClient from ols import config +from ols.constants import CONFIGURATION_FILE_NAME_ENV_VARIABLE client: TestClient @@ -17,7 +18,10 @@ # config file before we import anything from main.py @pytest.fixture(scope="function", autouse=True) @patch.dict( - os.environ, {"RCS_CONFIG_FILE": "tests/config/config_for_integration_tests.yaml"} + os.environ, + { + CONFIGURATION_FILE_NAME_ENV_VARIABLE: "tests/config/config_for_integration_tests.yaml" + }, ) def _setup(): """Setups the test client."""