diff --git a/popmon/config.py b/popmon/config.py index 29355b46..7375e89d 100644 --- a/popmon/config.py +++ b/popmon/config.py @@ -16,12 +16,14 @@ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +import warnings from pathlib import Path from typing import Any, Dict, List, Optional, Union import pandas as pd from histogrammar.dfinterface.make_histograms import get_time_axes from pydantic import BaseModel, BaseSettings +from pydantic.class_validators import validator from typing_extensions import Literal # Global configuration for the joblib parallelization. Could be used to change the number of jobs, and/or change @@ -30,6 +32,18 @@ parallel_args = {"n_jobs": 1} +class ValidatedBaseModel(BaseModel): + class Config: + validate_all = True + validate_assignment = True + + +class ValidatedSettings(BaseSettings): + class Config: + validate_all = True + validate_assignment = True + + class SectionModel(BaseModel): name: str """Name of the section in the report""" @@ -157,14 +171,22 @@ class Section(BaseModel): """Configuration related to the traffic lights section""" -class Report(BaseModel): +class Report(ValidatedBaseModel): """Report-specific configuration""" title: str = "POPMON Report" """Report title in browser and navbar. May contain HTML.""" - skip_empty_plots: bool = True - """if false, also show empty plots in report with only nans or zeroes (optional)""" + skip_empty_plots: bool = False + """(deprecated) if false, also show empty plots in report with only nans or zeroes (optional)""" + + @validator("skip_empty_plots") + def skip_empty_plots_deprecated(cls, v): + if v: + warnings.warn( + "The 'skip_empty_plots' parameter is deprecated and will be removed in the next release." + ) + return v last_n: int = 0 """plot statistic data for last 'n' periods (optional)""" @@ -287,7 +309,7 @@ class Monitoring(BaseModel): """ -class Settings(BaseSettings): +class Settings(ValidatedSettings): report: Report = Report() """Settings regarding the report""" @@ -385,7 +407,3 @@ def _set_bin_specs_by_time_width_and_offset( "bin_width": float(pd.Timedelta(time_width).value), "bin_offset": float(pd.Timestamp(time_offset).value), } - - class Config: - validate_all = True - validate_assignment = True