Skip to content

Commit

Permalink
feat(config): deprecate skip_empty_plots
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed Aug 30, 2022
1 parent 1d5e26d commit d42b967
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions popmon/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
# 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 import BaseModel
from pydantic.class_validators import validator
from pydantic.env_settings import BaseSettings
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 +33,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 +172,20 @@ 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 +308,7 @@ class Monitoring(BaseModel):
"""


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

Expand Down Expand Up @@ -385,7 +406,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 d42b967

Please sign in to comment.