diff --git a/README.rst b/README.rst index 4569da0..be49889 100644 --- a/README.rst +++ b/README.rst @@ -41,7 +41,6 @@ Requirements ------------ * `Python `_ version 3.6 or later -* `progressbar `_ Bibtex ------ diff --git a/ddsmt/progress.py b/ddsmt/progress.py index 38ed22b..e6a7b40 100644 --- a/ddsmt/progress.py +++ b/ddsmt/progress.py @@ -10,10 +10,20 @@ # information at https://github.com/ddsmt/ddSMT/blob/master/LICENSE. import logging -import progressbar import sys +import itertools -__BAR = None +__MAX_VAL = None +__CUR_VAL = 0 +__SPINNER = itertools.cycle(['-', '/', '|', '\\']) + + +def __print(): + global __CUR_VAL, __MAX_VAL + print('{} {} / {}'.format(next(__SPINNER), __CUR_VAL, __MAX_VAL), + end='\r', + flush=True, + file=sys.stderr) def start(max): @@ -22,15 +32,14 @@ def start(max): Only initialize if the current log level is at least ``logging.INFO``. """ - global __BAR + global __CUR_VAL, __MAX_VAL if not sys.stdout.isatty(): return if logging.getLogger().level > logging.INFO: return - widgets = [progressbar.Bar(), ' ', progressbar.Counter(), ' / ', str(max)] - __BAR = progressbar.ProgressBar(maxval=max, widgets=widgets) - __BAR.start() - __BAR.update_interval = 1 + __MAX_VAL = max + __CUR_VAL = 0 + __print() def update(newval=None): @@ -39,12 +48,17 @@ def update(newval=None): The value is incremented by one, or set to newval if newval is not ``None``. """ - global __BAR - if __BAR: - if newval is not None: - __BAR.update(min(newval, __BAR.maxval)) - else: - __BAR.update(__BAR.currval + 1) + global __CUR_VAL, __MAX_VAL + if __MAX_VAL is not None: + if __CUR_VAL < __MAX_VAL: + if newval is not None: + if __CUR_VAL + newval >= __MAX_VAL: + __CUR_VAL = __MAX_VAL + else: + __CUR_VAL += newval + else: + __CUR_VAL += 1 + __print() def finish(): @@ -52,7 +66,7 @@ def finish(): Delete the object and write a newline. """ - global __BAR - if __BAR: - __BAR = None + global __MAX_VAL + if __MAX_VAL is not None: + __MAX_VAL = None sys.stdout.write('\n') diff --git a/requirements.txt b/requirements.txt index 2288abb..2a88961 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ # for regular operation gprof2dot>=2019.11 importlib-metadata>=1.7 ; python_version<"3.8" -progressbar>=2.5 # for CI coverage>=4.5 docformatter>=1.4 diff --git a/setup.cfg b/setup.cfg index 50d4000..e742ded 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,7 +27,6 @@ packages = find: install_requires = gprof2dot>=2019.11 importlib-metadata>=1.7 ; python_version<"3.8" - progressbar>=2.5 python_requires = >=3.6 scripts = bin/smt2info