Skip to content

Commit

Permalink
feat(config): deprecate skip_empty_plots (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed Sep 1, 2022
1 parent e2b52f2 commit 372ef85
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions popmon/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"""
Expand Down Expand Up @@ -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)"""
Expand Down Expand Up @@ -287,7 +309,7 @@ class Monitoring(BaseModel):
"""


class Settings(BaseSettings):
class Settings(ValidatedSettings):
report: Report = Report()
"""Settings regarding the report"""

Expand Down Expand Up @@ -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

0 comments on commit 372ef85

Please sign in to comment.