mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-02-13 17:50:30 +00:00
feat: add ProgressLike protocol
This commit is contained in:
@@ -15,7 +15,11 @@ from freqtrade.util.formatters import decimals_per_coin, fmt_coin, fmt_coin2, ro
|
||||
from freqtrade.util.ft_precise import FtPrecise
|
||||
from freqtrade.util.measure_time import MeasureTime
|
||||
from freqtrade.util.periodic_cache import PeriodicCache
|
||||
from freqtrade.util.progress_tracker import get_progress_tracker # noqa F401
|
||||
from freqtrade.util.progress_tracker import ( # noqa F401
|
||||
ProgressLike,
|
||||
get_progress_tracker,
|
||||
retrieve_progress_tracker,
|
||||
)
|
||||
from freqtrade.util.rich_progress import CustomProgress
|
||||
from freqtrade.util.rich_tables import print_df_rich_table, print_rich_table
|
||||
from freqtrade.util.template_renderer import render_template, render_template_with_fallback # noqa
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
from contextlib import AbstractContextManager
|
||||
from typing import Optional, Protocol
|
||||
|
||||
from rich.progress import (
|
||||
BarColumn,
|
||||
MofNCompleteColumn,
|
||||
TaskID,
|
||||
TaskProgressColumn,
|
||||
TextColumn,
|
||||
TimeElapsedColumn,
|
||||
@@ -10,7 +14,19 @@ from rich.progress import (
|
||||
from freqtrade.util.rich_progress import CustomProgress
|
||||
|
||||
|
||||
def get_progress_tracker(**kwargs):
|
||||
class ProgressLike(Protocol, AbstractContextManager["ProgressLike"]):
|
||||
def add_task(self, description: str, *args, **kwargs) -> TaskID: ...
|
||||
|
||||
def update(self, task_id: TaskID, *, advance: float | None = None, **kwargs): ...
|
||||
|
||||
|
||||
def retrieve_progress_tracker(pt: Optional[ProgressLike]) -> ProgressLike:
|
||||
if pt is None:
|
||||
return get_progress_tracker()
|
||||
return pt
|
||||
|
||||
|
||||
def get_progress_tracker(**kwargs) -> ProgressLike:
|
||||
"""
|
||||
Get progress Bar with custom columns.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user