diff --git a/0001-fixup-moving-average-window.patch b/0001-fixup-moving-average-window.patch index 844a6eb..96ea569 100644 --- a/0001-fixup-moving-average-window.patch +++ b/0001-fixup-moving-average-window.patch @@ -11,7 +11,7 @@ Since the upstream default window size is only of size 10 items (by default), it calculates the average speed only for the last ~0.005s. We could enlarge the size of window (sma_window param), but the algorithm is so naive that it would decrease the -performance. +performance (O(N): sum(queue)/len(queue)). This has been discussed very extensively with upstream (PR 24 and friends) but I neither was not able to explain the problem, nor I @@ -22,36 +22,14 @@ compatibility - changes the algorithm so the average speed is calculation is fast enough, and much more stable (by default it calculates speed for window of 2 seconds). -We also don't seem to have the monotonic() mess, since we don't seem -to suffer from the same issues. - Fork with this patch backported is maintained in https://github.com/python-progress/python-progress -diff --git a/MANIFEST.in b/MANIFEST.in -index ef7c4cb..0c73842 100644 ---- a/MANIFEST.in -+++ b/MANIFEST.in -@@ -1,2 +1 @@ - include README.rst LICENSE --include test_*.py diff --git a/progress/__init__.py b/progress/__init__.py -index b434b30..71b2039 100644 +index b434b30..f26056d 100644 --- a/progress/__init__.py +++ b/progress/__init__.py -@@ -18,10 +18,7 @@ from collections import deque - from datetime import timedelta - from math import ceil - from sys import stderr --try: -- from time import monotonic --except ImportError: -- from time import time as monotonic -+from time import time - - - __version__ = '1.6' -@@ -30,19 +27,55 @@ HIDE_CURSOR = '\x1b[?25l' +@@ -30,19 +30,55 @@ HIDE_CURSOR = '\x1b[?25l' SHOW_CURSOR = '\x1b[?25h' @@ -63,7 +41,7 @@ index b434b30..71b2039 100644 + self.max_seconds = max_seconds + self.max_items = max_items + -+ stamp = time() ++ stamp = monotonic() + self.last = stamp - 0.001 + self.counter = 0 + self.deque = deque() @@ -103,30 +81,26 @@ index b434b30..71b2039 100644 def __init__(self, message='', **kwargs): self.index = 0 -- self.start_ts = monotonic() + self.start_ts = monotonic() - self.avg = 0 - self._avg_update_ts = self.start_ts - self._ts = self.start_ts - self._xput = deque(maxlen=self.sma_window) -+ self.start_ts = time() + self.window = _Window(self.sma_window_seconds, self.sma_window) for key, val in kwargs.items(): setattr(self, key, val) -@@ -67,23 +100,19 @@ class Infinite(object): - - @property +@@ -69,21 +105,17 @@ class Infinite(object): def elapsed(self): -- return int(monotonic() - self.start_ts) -+ return int(time() - self.start_ts) -+ + return int(monotonic() - self.start_ts) + + @property + def avg(self): + speed = self.window.avg + if speed: + return 1/speed -+ return 3600 # better constant? - ++ return float("inf") ++ @property def elapsed_td(self): return timedelta(seconds=self.elapsed) @@ -145,15 +119,20 @@ index b434b30..71b2039 100644 def update(self): pass -@@ -116,10 +145,7 @@ class Infinite(object): - raise AttributeError(msg) +@@ -112,14 +144,10 @@ class Infinite(object): + try: + return self.file.isatty() if self.check_tty else True + except AttributeError: +- msg = "%s has no attribute 'isatty'. Try setting check_tty=False." % self +- raise AttributeError(msg) ++ raise AttributeError('\'{}\' object has no attribute \'isatty\'. Try setting parameter check_tty=False.'.format(self)) def next(self, n=1): - now = monotonic() - dt = now - self._ts - self.update_avg(n, dt) - self._ts = now -+ self.window.next(n, time()) ++ self.window.next(n, monotonic()) self.index = self.index + n self.update() diff --git a/python-progress.spec b/python-progress.spec index 6515584..7b35399 100644 --- a/python-progress.spec +++ b/python-progress.spec @@ -20,7 +20,7 @@ Name: python-%{pypi_name} Version: 1.6 -Release: 5%{?dist} +Release: 6%{?dist} Summary: Easy to use progress bars License: ISC @@ -98,6 +98,9 @@ rm -rf %{pypi_name}.egg-info %changelog +* Fri Jul 15 2022 Pavel Raiskup - 1.6-6 +- use time.monotonic(), bar.avg is infinity for zero speed + * Fri Jul 22 2022 Fedora Release Engineering - 1.6-5 - Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild