-
Notifications
You must be signed in to change notification settings - Fork 0
OSvariables_stories
US IO : Provide environment variables and system-level configurations for portability across various environments.
- US IO : Provide environment variables and system-level configurations for portability across various environments.
classDiagram
class Singleton {
- _instances: dict
+ __new__(cls, *args, **kwargs) Singleton
}
class BaseSettings {
<<external>>
}
class Env {
+ mlflow_tracking_uri: str = "./mlruns"
+ mlflow_registry_uri: str = "./mlruns"
+ mlflow_experiment_name: str = "regression_model_template"
+ mlflow_registered_model_name: str = "regression_model_template"
}
class Config {
+ case_sensitive: bool = False
+ env_file: str = ".env"
+ env_file_encoding: str = "utf-8"
+ extra: str = "ignore"
}
Env --|> Singleton : inherits
Env --|> BaseSettings : inherits
Env *-- Config : inner class
Title:
As a developer, I want a centralized and reusable way to manage environment variables and configuration settings so that I can ensure consistent behavior across the application.
Description:
The Env class combines the Singleton pattern and Pydantic's BaseSettings to create a single shared instance for managing environment-specific configurations. It ensures that environment variables are accessible, validated, and loaded from a .env file if available.
Acceptance Criteria:
- The
Envclass:- Inherits from both
Singletonand Pydantic'sBaseSettings. - Ensures only one instance of the class exists throughout the application (Singleton behavior).
- Provides default values for MLflow-related environment variables.
- Supports loading configurations from a
.envfile.
- Inherits from both
- Environment variables are:
- Case-insensitive (optional feature).
- Readable from both the system environment and a
.envfile. - Validated using Pydantic's type system.
- The
Configclass:- Enables
.envfile reading with UTF-8 encoding. - Handles case-insensitive environment variable lookups if enabled.
- Enables
Title:
As a machine learning engineer, I want to configure MLflow settings (tracking URI, registry URI, experiment name, etc.) in a single place so that I can easily manage and update them without code duplication.
Description:
The Env class provides default and customizable values for MLflow-related configurations. It ensures that all MLflow components use the same settings consistently, reducing potential misconfigurations.
Acceptance Criteria:
- The following MLflow configuration keys are available:
-
mlflow_tracking_uri: Default is"./mlruns". -
mlflow_registry_uri: Default is"./mlruns". -
mlflow_experiment_name: Default is"regression_model_template". -
mlflow_registered_model_name: Default is"regression_model_template".
-
- Values can be overridden by environment variables or a
.envfile. - The Singleton pattern ensures no accidental re-creation of the
Envinstance.
-
Implementation Requirements:
- The
Singletonpattern ensures a single shared instance of theEnvclass. - Default values are provided for MLflow configuration keys.
- The
-
Environment Variable Management:
- Values are first read from the environment variables.
- If not set, values are read from the
.envfile. - Defaults are used if neither source provides a value.
-
Error Handling:
- The
Envclass validates all settings using Pydantic's type system. - Errors are raised if a setting does not meet its type requirements.
- The
-
Testing:
- Unit tests verify:
- Singleton behavior of the
Envclass. - Correct loading of environment variables and
.envfile values. - Validation of MLflow-related settings.
- Singleton behavior of the
- Mocking is used to simulate environment variables and
.envfile contents.
- Unit tests verify:
-
Documentation:
- Class-level docstrings explain the purpose and usage of
EnvandSingleton. - Examples demonstrate:
- Accessing MLflow settings via the
Envclass. - Overriding values with environment variables or a
.envfile.
- Accessing MLflow settings via the
- Class-level docstrings explain the purpose and usage of
-
Accessing MLflow Settings:
env = Env() print(env.mlflow_tracking_uri) # Output: "./mlruns" (default or overridden)
-
Using the Singleton Pattern:
env1 = Env() env2 = Env() assert env1 is env2 # True, as both point to the same instance.
-
Overriding via Environment Variables or
.env:- Set
MLFLOW_TRACKING_URI="http://localhost:5000"in.envfile or environment. - Access with:
env = Env() print(env.mlflow_tracking_uri) # Output: "http://localhost:5000"
- Set
- The
Envclass implements environment configuration management with validation. - The Singleton behavior is verified, ensuring a single instance is used.
- The
.envfile and environment variables are correctly loaded and take precedence over defaults. - All functionality is tested, with error scenarios validated.
- Documentation provides clear usage instructions and examples.
Powered by MLOps Factory