diff options
| author | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-05-27 00:05:01 +0300 |
|---|---|---|
| committer | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-05-27 00:05:01 +0300 |
| commit | 38716e99b15a43274db1a8c512cb82ced1708990 (patch) | |
| tree | 1b4bb81c2e8a7e200aeb493ec4bf90438abf84dc /robusta_krr/utils | |
| parent | 6abd673bfdb11e81cf857fd2e0d7721d4e0cc93f (diff) | |
Add more documentation
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 4777a9c..c2b2465 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 |
