diff --git a/.gitignore b/.gitignore index e69de29..bf39ebb 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/progress-*.tar.gz diff --git a/0001-fixup-moving-average-window.patch b/0001-fixup-moving-average-window.patch new file mode 100644 index 0000000..769c68f --- /dev/null +++ b/0001-fixup-moving-average-window.patch @@ -0,0 +1,159 @@ +Fix fast upload avg calculation + +Upstream verigak/progress is broken for very fast uploads; e.g. +with 'copr build' command, the next() call is called so often that +the avg() calculation probably suffers from some small +floating-point numbers problems: + + With 15MB/s => next() called for each 8096B => ~2000 calls/s + +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. + +This has been discussed very extensively with upstream (PR 24 and +friends) but I neither was not able to explain the problem, nor I +was able to convince upstream to accept my patches. + +This downstream patch - while it keeps the backward API +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 e434c25..1cbdce6 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.5' +@@ -30,19 +27,55 @@ HIDE_CURSOR = '\x1b[?25l' + SHOW_CURSOR = '\x1b[?25h' + + ++class _Window(object): ++ max_seconds = 2 ++ max_items = None ++ ++ def __init__(self, max_seconds=2, max_items=None): ++ self.max_seconds = max_seconds ++ self.max_items = max_items ++ ++ stamp = time() ++ self.last = stamp - 0.001 ++ self.counter = 0 ++ self.deque = deque() ++ self.next(0, stamp) ++ ++ def pop(self): ++ item = self.deque.popleft() ++ self.counter -= item[1] ++ ++ def clean(self): ++ if self.max_items: ++ while len(self.deque) > self.max_items: ++ self.pop() ++ while len(self.deque) > 2 and self.last - self.deque[0][0] > float(self.max_seconds): ++ self.pop() ++ ++ def next(self, n, t): ++ self.clean() ++ self.deque.append((self.last, n)) ++ self.last = t ++ self.counter += n ++ ++ @property ++ def avg(self): ++ return self.counter / (self.last - self.deque[0][0]) ++ ++ + class Infinite(object): + file = stderr +- sma_window = 10 # Simple Moving Average window ++ # Maximum number of next() calls to be held in Simple Moving Average ++ # window structure (in memory), default is unlimited. ++ sma_window_seconds = 2 ++ sma_window = None + check_tty = True + hide_cursor = True + + def __init__(self, message='', **kwargs): + self.index = 0 +- 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) + +@@ -62,23 +95,19 @@ class Infinite(object): + + @property + def elapsed(self): +- return int(monotonic() - self.start_ts) ++ return int(time() - self.start_ts) ++ ++ @property ++ def avg(self): ++ speed = self.window.avg ++ if speed: ++ return 1/speed ++ return 3600 # better constant? + + @property + def elapsed_td(self): + return timedelta(seconds=self.elapsed) + +- def update_avg(self, n, dt): +- if n > 0: +- xput_len = len(self._xput) +- self._xput.append(dt / n) +- now = monotonic() +- # update when we're still filling _xput, then after every second +- if (xput_len < self.sma_window or +- now - self._avg_update_ts > 1): +- self.avg = sum(self._xput) / len(self._xput) +- self._avg_update_ts = now +- + def update(self): + pass + +@@ -112,10 +141,7 @@ class Infinite(object): + return self.file.isatty() if self.check_tty else True + + 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.index = self.index + n + self.update() + diff --git a/python-progress.spec b/python-progress.spec new file mode 100644 index 0000000..0c6ce89 --- /dev/null +++ b/python-progress.spec @@ -0,0 +1,177 @@ +%if 0%{?fedora} + %bcond_without python3 + %if 0%{?fedora} > 29 + %bcond_with python2 + %else + %bcond_without python2 + %endif +%else + %if 0%{?rhel} > 7 + %bcond_with python2 + %bcond_without python3 + %else + %bcond_without python2 + %bcond_with python3 + %endif +%endif + +# Created by pyp2rpm-0.5.2 +%global pypi_name progress + +Name: python-%{pypi_name} +Version: 1.5 +Release: 3%{?dist} +Summary: Easy to use progress bars + +License: ISC +URL: http://github.com/verigak/progress/ +Source0: %pypi_source +BuildArch: noarch + +%if %{with python2} +BuildRequires: python2-devel +BuildRequires: python2-setuptools +%endif + +%if %{with python3} +BuildRequires: python3-devel +BuildRequires: python3-setuptools +%endif + +Patch1: 0001-fixup-moving-average-window.patch + +%global _description\ +Collection of easy to use progress bars and spinners.\ + + +%description %_description + + +%if 0%{with python2} +%package -n python2-%{pypi_name} +Summary: %summary +%{?python_provide:%python_provide python2-%{pypi_name}} + +%description -n python2-%{pypi_name} %_description +%endif # python2 + + +%if 0%{with python3} +%package -n python3-%{pypi_name} +Summary: Easy to use progress bars + +%description -n python3-%{pypi_name} +Collection of easy to use progress bars and spinners. +%endif # python3 + + +%prep +%autosetup -p1 -n %{pypi_name}-%{version} + +# Remove bundled egg-info +rm -rf %{pypi_name}.egg-info + + +%build +%{?with_python2: %py2_build} +%{?with_python3: %py3_build} + + +%install +%{?with_python2: %py2_install} +%{?with_python3: %py3_install} + + +%if 0%{with python2} +%files -n python2-%{pypi_name} +%doc README.rst LICENSE +%{python2_sitelib}/%{pypi_name} +%{python2_sitelib}/%{pypi_name}-%{version}-py?.?.egg-info +%endif + +%if 0%{with python3} +%files -n python3-%{pypi_name} +%doc README.rst LICENSE +%{python3_sitelib}/%{pypi_name} +%{python3_sitelib}/%{pypi_name}-%{version}-py?.?.egg-info +%endif + + +%changelog +* Mon Aug 19 2019 Miro Hrončok - 1.5-3 +- Rebuilt for Python 3.8 + +* Fri Jul 26 2019 Fedora Release Engineering - 1.5-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild + +* Mon Mar 18 2019 Pavel Raiskup - 1.5-1 +- the latest upstream release + +* Sat Feb 02 2019 Fedora Release Engineering - 1.4-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild + +* Tue Dec 11 2018 Pavel Raiskup - 1.4-2 +- followup for previous commit, PR#3 + +* Wed Dec 05 2018 Gwyn Ciesla - 1.4-1 +- 1.4 + +* Wed Oct 03 2018 Pavel Raiskup - 1.2-19 +- no python2 in f30+ (rhbz#1634951) +- fix el6 build (rhbz#1310704) + +* Sat Jul 14 2018 Fedora Release Engineering - 1.2-18 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild + +* Tue Jun 19 2018 Miro Hrončok - 1.2-17 +- Rebuilt for Python 3.7 + +* Fri Feb 09 2018 Fedora Release Engineering - 1.2-16 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild + +* Sat Jan 27 2018 Iryna Shcherbina - 1.2-15 +- Update Python 2 dependency declarations to new packaging standards + (See https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3) + +* Sat Aug 19 2017 Zbigniew Jędrzejewski-Szmek - 1.2-14 +- Python 2 binary package renamed to python2-progress + See https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3 + +* Thu Jul 27 2017 Fedora Release Engineering - 1.2-13 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild + +* Sat Feb 11 2017 Fedora Release Engineering - 1.2-12 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild + +* Mon Dec 19 2016 Miro Hrončok - 1.2-11 +- Rebuild for Python 3.6 + +* Thu Dec 08 2016 Pavel Raiskup - 1.2-10 +- keep enabled python3 subpackage only in fedora, and merge into epel7 + +* Tue Nov 01 2016 Pavel Raiskup - 1.2-9 +- fix avg counter for copr-cli (rhbz#1299634) + +* Tue Jul 19 2016 Fedora Release Engineering - 1.2-8 +- https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages + +* Thu Feb 04 2016 Fedora Release Engineering - 1.2-7 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild + +* Tue Nov 10 2015 Fedora Release Engineering - 1.2-6 +- Rebuilt for https://fedoraproject.org/wiki/Changes/python3.5 + +* Thu Jun 18 2015 Fedora Release Engineering - 1.2-5 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild + +* Sat Jun 07 2014 Fedora Release Engineering - 1.2-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild + +* Tue May 13 2014 Bohuslav Kabrda - 1.2-3 +- Rebuilt for https://fedoraproject.org/wiki/Changes/Python_3.4 + +* Tue Feb 18 2014 Bohuslav Kabrda - 1.2-2 +- Add missing BR: python{,3}-setuptools + +* Tue Feb 18 2014 Bohuslav Kabrda - 1.2-1 +- Initial package. diff --git a/sources b/sources index e69de29..c6b40a1 100644 --- a/sources +++ b/sources @@ -0,0 +1 @@ +SHA512 (progress-1.5.tar.gz) = a9bee3498746233f874da2d6509d052882d9592df69c223637279a1fae40174a4dc279b56a7558e95ed173b0d357ae07752501c577a3cb9c79e0f87095838896