-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): make it possible to enable/disable various features of the…
… app
- Loading branch information
1 parent
e098020
commit a579912
Showing
15 changed files
with
834 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from typing import TypedDict | ||
|
||
|
||
class EnabledFeatures(TypedDict): | ||
datasets: bool | ||
inference: bool | ||
images: bool | ||
embeddings: bool | ||
transforms: bool | ||
export: bool | ||
filtering: bool | ||
|
||
|
||
ALL_FEATURES: EnabledFeatures = { | ||
"datasets": True, | ||
"inference": True, | ||
"images": True, | ||
"embeddings": True, | ||
"transforms": True, | ||
"export": True, | ||
"filtering": True, | ||
} | ||
|
||
NO_FEATURES: EnabledFeatures = { | ||
"datasets": False, | ||
"inference": False, | ||
"images": False, | ||
"embeddings": False, | ||
"transforms": False, | ||
"export": False, | ||
"filtering": False, | ||
} | ||
|
||
DEFAULT_FEATURES = ALL_FEATURES | ||
|
||
VIEWER_PRESET: EnabledFeatures = { | ||
"datasets": True, | ||
"inference": False, | ||
"images": True, | ||
"embeddings": False, | ||
"transforms": False, | ||
"export": False, | ||
"filtering": True, | ||
} | ||
|
||
FEATURE_PRESETS = { | ||
"all": ALL_FEATURES, | ||
"none": NO_FEATURES, | ||
"viewer": VIEWER_PRESET, | ||
} | ||
|
||
|
||
def validate_feature_name(feature: str) -> str: | ||
known_features = set(DEFAULT_FEATURES.keys()) | ||
|
||
if feature not in known_features: | ||
raise ValueError(f"Unknown feature '{feature}'. Known features are {known_features}") | ||
|
||
return feature | ||
|
||
|
||
def validate_preset_name(preset: str) -> str: | ||
known_presets = set(FEATURE_PRESETS.keys()) | ||
|
||
if preset not in known_presets: | ||
raise ValueError(f"Unknown preset '{preset}'. Known presets are {known_presets}") | ||
|
||
return preset | ||
|
||
def config_features_to_enabled_features(features: list[str] | None) -> EnabledFeatures: | ||
if features is None: | ||
return DEFAULT_FEATURES | ||
|
||
enabled_features = NO_FEATURES.copy() | ||
|
||
for feature in features: | ||
enabled_features[feature] = True | ||
|
||
return enabled_features | ||
|
||
def config_preset_to_enabled_features(preset: str | None) -> EnabledFeatures: | ||
if preset is None: | ||
return DEFAULT_FEATURES | ||
|
||
return FEATURE_PRESETS[preset] |
Oops, something went wrong.