-
Notifications
You must be signed in to change notification settings - Fork 430
/
pbar.py
55 lines (39 loc) · 1.26 KB
/
pbar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
import logging
__all__ = ["get_progress_bar"]
try:
import tqdm
except ImportError:
tqdm = None
class _NoOpPBar(object):
"""This class implements the progress bar interface but does nothing"""
def __init__(self):
pass
def __enter__(self, *args, **kwargs):
return self
def __exit__(self, *args, **kwargs):
pass
def update(self, count):
pass
def get_progress_bar(display, total):
"""Get a progress bar interface with given properties
If the tqdm library is not installed, this will always return a "progress
bar" that does nothing.
Args:
display (bool or str): Should the bar actually show the progress? Or a
string to indicate which tqdm bar to use.
total (int): The total size of the progress bar.
"""
if display:
if tqdm is None:
logging.warning(
"You must install the tqdm library to use progress "
"indicators with emcee"
)
return _NoOpPBar()
else:
if display is True:
return tqdm.tqdm(total=total)
else:
return getattr(tqdm, "tqdm_" + display)(total=total)
return _NoOpPBar()