Skip to content

Commit

Permalink
Remove progressbar dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpreiner committed Apr 22, 2024
1 parent f69fc73 commit 8ea5677
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Requirements
------------

* `Python <https://www.python.org/>`_ version 3.6 or later
* `progressbar <https://pypi.org/project/progressbar>`_

Bibtex
------
Expand Down
46 changes: 30 additions & 16 deletions ddsmt/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -39,20 +48,25 @@ 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():
"""Stop the current progress bar.
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')
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ea5677

Please sign in to comment.