From f0155aea8083e4104c1a9f86b3803229f385e22b Mon Sep 17 00:00:00 2001 From: rasbt Date: Sat, 25 Jan 2014 21:25:29 -0500 Subject: [PATCH] backwards import compat. for python 2 --- pyprind/__init__.py | 4 ++-- pyprind/{pyprind.py => progbar.py} | 38 ++---------------------------- pyprind/progpercent.py | 35 +++++++++++++++++++++++++++ setup.py | 1 - 4 files changed, 39 insertions(+), 39 deletions(-) rename pyprind/{pyprind.py => progbar.py} (52%) create mode 100644 pyprind/progpercent.py diff --git a/pyprind/__init__.py b/pyprind/__init__.py index 0d3333b..4513ecc 100644 --- a/pyprind/__init__.py +++ b/pyprind/__init__.py @@ -1,5 +1,5 @@ # Sebastian Raschka 01/25/2014 # PyPrind - Python Progress Indicator module -from pyprind.pyprind import ProgBar -from pyprind.pyprind import ProgPercent \ No newline at end of file +from .progbar import ProgBar +from .progpercent import ProgPercent \ No newline at end of file diff --git a/pyprind/pyprind.py b/pyprind/progbar.py similarity index 52% rename from pyprind/pyprind.py rename to pyprind/progbar.py index e6ec3d3..31833cd 100644 --- a/pyprind/pyprind.py +++ b/pyprind/progbar.py @@ -1,7 +1,7 @@ import sys import time -class ProgBar() +class ProgBar(): """ Prints a progress bar to the standard output.""" def __init__(self, iterations, width=50): @@ -34,38 +34,4 @@ def finish(self, cpu_time=True): self.time[2] = self.time[1] - self.time[0] sys.stdout.write('\n') if cpu_time: - print('Time elapsed: {0:.4f} sec'.format(self.time[2])) - - -class ProgPercent(): - """ Prints a progress of an computation as percentage to the standard output.""" - - def __init__(self, iterations): - self.cnt = 0 - self.max_iter = float(iterations) # accommodation for Python 2.x users - self.perc = 0 - self.time = [time.clock(), None, None] - self.__print_percent() - - def __calc_percent(self): - return round(self.cnt/self.max_iter * 100) - - def __print_percent(self): - sys.stdout.write('\r[%3d %%]' % (self.perc)) - - def update(self): - self.cnt += 1 - next_perc = self.__calc_percent() - if next_perc > self.perc: - self.perc = next_perc - self.__print_percent() - sys.stdout.flush() - - def finish(self, cpu_time=True): - self.time[1] = time.clock() - self.time[2] = self.time[1] - self.time[0] - sys.stdout.write('\n') - if cpu_time: - print('Time elapsed: {0:.4f} sec'.format(self.time[2])) - - + print('Time elapsed: {0:.4f} sec'.format(self.time[2])) \ No newline at end of file diff --git a/pyprind/progpercent.py b/pyprind/progpercent.py new file mode 100644 index 0000000..1f82bdd --- /dev/null +++ b/pyprind/progpercent.py @@ -0,0 +1,35 @@ +import sys +import time + +class ProgPercent(): + """ Prints a progress of an computation as percentage to the standard output.""" + + def __init__(self, iterations): + self.cnt = 0 + self.max_iter = float(iterations) # accommodation for Python 2.x users + self.perc = 0 + self.time = [time.clock(), None, None] + self.__print_percent() + + def __calc_percent(self): + return round(self.cnt/self.max_iter * 100) + + def __print_percent(self): + sys.stdout.write('\r[%3d %%]' % (self.perc)) + + def update(self): + self.cnt += 1 + next_perc = self.__calc_percent() + if next_perc > self.perc: + self.perc = next_perc + self.__print_percent() + sys.stdout.flush() + + def finish(self, cpu_time=True): + self.time[1] = time.clock() + self.time[2] = self.time[1] - self.time[0] + sys.stdout.write('\n') + if cpu_time: + print('Time elapsed: {0:.4f} sec'.format(self.time[2])) + + diff --git a/setup.py b/setup.py index d8f0157..930853e 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,5 @@ ], license='GPLv3', long_description = README_TEXT, - extras_require={'testing': ['pytest']}, platforms='any', )