diff options
| author | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-05-29 15:56:09 +0300 |
|---|---|---|
| committer | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-05-29 15:56:09 +0300 |
| commit | 81ec6d0e5d486a4b7087365a3398f69419738b21 (patch) | |
| tree | b1a92f151e170c5b73944dac98b4144781d0d89c /robusta_krr/utils | |
| parent | caef32f1c3a8e735493410419e8338a6beb69d46 (diff) | |
| parent | e92919ce1b402e024933528f99e4c13b065f19fa (diff) | |
Merge branch 'main' into multicluster-improvement
Diffstat (limited to 'robusta_krr/utils')
| -rw-r--r-- | robusta_krr/utils/configurable.py | 4 | ||||
| -rw-r--r-- | robusta_krr/utils/display_name.py | 23 | ||||
| -rw-r--r-- | robusta_krr/utils/progress_bar.py | 7 |
3 files changed, 27 insertions, 7 deletions
diff --git a/robusta_krr/utils/configurable.py b/robusta_krr/utils/configurable.py index a6cb92f..8954139 100644 --- a/robusta_krr/utils/configurable.py +++ b/robusta_krr/utils/configurable.py @@ -10,7 +10,9 @@ from robusta_krr.core.models.config import Config class Configurable(abc.ABC): """ A class that can be configured with a Config object. - Opens the possibility to use echo and debug methods + Opens the possibility to use custom logging methods, that can be configured with the Config object. + + Also makes a `console` attribute available, which is a rich console. """ def __init__(self, config: Config) -> None: diff --git a/robusta_krr/utils/display_name.py b/robusta_krr/utils/display_name.py index 9082fc0..69541ae 100644 --- a/robusta_krr/utils/display_name.py +++ b/robusta_krr/utils/display_name.py @@ -1,16 +1,27 @@ -from typing import Callable, TypeVar +from typing import Callable, TypeVar, Any _T = TypeVar("_T") -def add_display_name(*, postfix: str) -> Callable[[type[_T]], type[_T]]: - """Add a decorator factory to add __display_name__ property to the class.""" +def display_name_property(*, suffix: str) -> Callable[[type[_T]], type[_T]]: + """Add a decorator factory to add __display_name__ property to the class. + + It is a utility function for BaseStrategy. + It makes a __display_name__ property for the class, that uses the name of the class. + By default, it will remove the suffix from the name of the class. + For example, if the name of the class is 'MyStrategy', the __display_name__ property will be 'My'. + If the name of the class is 'Foo', the __display_name__ property will be 'Foo', because it does not end with 'Strategy'. + + If you then override the __display_name__ property, it will be used instead of the default one. + """ def decorator(cls: type[_T]) -> type[_T]: class DisplayNameProperty: - def __get__(self, instance, owner): - if owner.__name__.lower().endswith(postfix.lower()): - return owner.__name__[: -len(postfix)] + # This is a descriptor that returns the name of the class. + # It is used to generate the __display_name__ property. + def __get__(self, instance: Any, owner: type[_T]) -> str: + if owner.__name__.lower().endswith(suffix.lower()): + return owner.__name__[: -len(suffix)] return owner.__name__ diff --git a/robusta_krr/utils/progress_bar.py b/robusta_krr/utils/progress_bar.py index 808a380..32bf211 100644 --- a/robusta_krr/utils/progress_bar.py +++ b/robusta_krr/utils/progress_bar.py @@ -5,6 +5,13 @@ from robusta_krr.utils.configurable import Configurable class ProgressBar(Configurable): + """ + Progress bar for displaying progress of gathering recommendations. + + Use `ProgressBar` as a context manager to automatically handle the progress bar. + Use `progress` method to step the progress bar. + """ + def __init__(self, config: Config, **kwargs) -> None: super().__init__(config) self.show_bar = self.echo_active |
