-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidators.py
36 lines (26 loc) · 1.09 KB
/
validators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from pathlib import Path
from typing import List
import typer
from core.classification_data import DataSelector
def build_extension_validator(
valid_extensions: List[str],
nullable: bool = False,
):
def validate_extension(value: Path) -> Path:
if nullable and value is None:
return value
extension = value.suffix.lower()
if extension not in valid_extensions:
raise typer.BadParameter(
f"Invalid file extension: '{extension}', valid extensions: '{', '.join(valid_extensions)}'.",
)
return value
return validate_extension
def validate_metrics_filters_key(value: str) -> str:
if value not in DataSelector.NOTEBOOK_METRICS_FILTERS.keys():
raise typer.BadParameter(f"valid options: {', '.join(DataSelector.NOTEBOOK_METRICS_FILTERS.keys())}")
return value
def validate_scores_filters_key(value: str) -> str:
if value not in DataSelector.NOTEBOOK_SCORES_FILTERS.keys():
raise typer.BadParameter(f"valid options: {', '.join(DataSelector.NOTEBOOK_SCORES_FILTERS.keys())}")
return value