logbar 0.0.1.dev0__tar.gz → 0.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {logbar-0.0.1.dev0/logbar.egg-info → logbar-0.0.3}/PKG-INFO +2 -2
- logbar-0.0.3/logbar/__init__.py +1 -0
- {logbar-0.0.1.dev0 → logbar-0.0.3}/logbar/logbar.py +10 -40
- {logbar-0.0.1.dev0 → logbar-0.0.3}/logbar/progress.py +9 -20
- {logbar-0.0.1.dev0 → logbar-0.0.3/logbar.egg-info}/PKG-INFO +2 -2
- {logbar-0.0.1.dev0 → logbar-0.0.3}/setup.py +2 -2
- logbar-0.0.1.dev0/logbar/__init__.py +0 -3
- {logbar-0.0.1.dev0 → logbar-0.0.3}/LICENSE +0 -0
- {logbar-0.0.1.dev0 → logbar-0.0.3}/MANIFEST.in +0 -0
- {logbar-0.0.1.dev0 → logbar-0.0.3}/README.md +0 -0
- {logbar-0.0.1.dev0 → logbar-0.0.3}/logbar/terminal.py +0 -0
- {logbar-0.0.1.dev0 → logbar-0.0.3}/logbar.egg-info/SOURCES.txt +0 -0
- {logbar-0.0.1.dev0 → logbar-0.0.3}/logbar.egg-info/dependency_links.txt +0 -0
- {logbar-0.0.1.dev0 → logbar-0.0.3}/logbar.egg-info/top_level.txt +0 -0
- {logbar-0.0.1.dev0 → logbar-0.0.3}/requirements.txt +0 -0
- {logbar-0.0.1.dev0 → logbar-0.0.3}/setup.cfg +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: logbar
|
|
3
|
-
Version: 0.0.
|
|
4
|
-
Summary: A unified Logger and ProgressBar util with zero dependencies.
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: A unified Logger and ProgressBar util with zero dependencies.
|
|
5
5
|
Home-page: https://github.com/ModelCloud/LogBar
|
|
6
6
|
Author: ModelCloud
|
|
7
7
|
Author-email: qubitium@modelcloud.ai
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .logbar import LogBar
|
|
@@ -18,7 +18,7 @@ import logging
|
|
|
18
18
|
from enum import Enum
|
|
19
19
|
from typing import Optional, Iterable
|
|
20
20
|
|
|
21
|
-
from
|
|
21
|
+
from .terminal import terminal_size
|
|
22
22
|
|
|
23
23
|
# global static/shared logger instance
|
|
24
24
|
logger = None
|
|
@@ -45,6 +45,8 @@ class LEVEL(str, Enum):
|
|
|
45
45
|
ERROR = "ERROR"
|
|
46
46
|
CRITICAL = "CRIT"
|
|
47
47
|
|
|
48
|
+
LEVEL_MAX_LENGTH = 5 # ERROR/DEBUG is longest at 5 chars
|
|
49
|
+
|
|
48
50
|
class LogBar(logging.Logger):
|
|
49
51
|
history = set()
|
|
50
52
|
history_limit = 1000
|
|
@@ -174,58 +176,26 @@ class LogBar(logging.Logger):
|
|
|
174
176
|
columns, _ = terminal_size()
|
|
175
177
|
str_msg = str(msg)
|
|
176
178
|
|
|
179
|
+
if columns > 0:
|
|
180
|
+
str_msg += " " * (columns - LEVEL_MAX_LENGTH - 2 - len(str_msg)) # -2 for cursor + space between LEVEL and msg
|
|
181
|
+
|
|
177
182
|
global last_pb_instance
|
|
178
183
|
if isinstance(last_pb_instance, ProgressBar) and not last_pb_instance.closed:
|
|
179
|
-
|
|
180
|
-
if columns > 0:
|
|
181
|
-
str_msg += " " * columns
|
|
182
|
-
|
|
183
|
-
print(buf,end='',flush=True)
|
|
184
|
+
print('\r',end='',flush=True)
|
|
184
185
|
|
|
185
186
|
# Get the color for the log level
|
|
186
187
|
|
|
187
188
|
reset = COLORS["RESET"]
|
|
188
189
|
color = COLORS.get(level.value, reset)
|
|
189
190
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
padding = " " * (5 - len(level.value)) # 5 is max enum string length
|
|
194
|
-
print(f"{color}{level.value}{reset}{padding} {str_msg}", end='\n', flush=True)
|
|
195
|
-
# if level == LEVEL.INFO:
|
|
196
|
-
# print(f"INFO: {str_msg}", end='',flush=True)
|
|
197
|
-
# elif level == LEVEL.WARN:
|
|
198
|
-
# print(f"WARN: {str_msg}", end='',flush=True)
|
|
199
|
-
# elif level == LEVEL.ERROR:
|
|
200
|
-
# print(f"ERROR: {str_msg}", end='',flush=True)
|
|
201
|
-
# elif level == LEVEL.DEBUG:
|
|
202
|
-
# print(f"DEBUG: {str_msg}", end='',flush=True)
|
|
203
|
-
# else:
|
|
204
|
-
# raise RuntimeError(f"Unknown logging level {level}")
|
|
205
|
-
|
|
206
|
-
# Print the message with the appropriate color
|
|
207
|
-
#print(f"{color}{level.value}{reset}{padding} {str_msg}")
|
|
208
|
-
|
|
209
|
-
# if level == LEVEL.INFO:
|
|
210
|
-
# self._info(str_msg, *args, **kwargs)
|
|
211
|
-
#
|
|
212
|
-
# elif level == LEVEL.WARN:
|
|
213
|
-
# self._warning(str_msg, *args, **kwargs)
|
|
214
|
-
# elif level == LEVEL.ERROR:
|
|
215
|
-
# self._error(str_msg, *args, **kwargs)
|
|
216
|
-
# elif level == LEVEL.DEBUG:
|
|
217
|
-
# self._debug(str_msg, *args, **kwargs)
|
|
218
|
-
# else:
|
|
219
|
-
# raise RuntimeError(f"Unknown logging level {level}")
|
|
191
|
+
level_padding = " " * (LEVEL_MAX_LENGTH - len(level.value)) # 5 is max enum string length
|
|
192
|
+
print(f"\r{color}{level.value}{reset}{level_padding} {str_msg}", end='\n', flush=True)
|
|
220
193
|
|
|
221
194
|
if isinstance(last_pb_instance, ProgressBar):
|
|
222
195
|
if not last_pb_instance.closed:
|
|
223
196
|
# only do this for our instance
|
|
224
197
|
if self == logger:
|
|
198
|
+
#print('\r', end='', flush=True)
|
|
225
199
|
last_pb_instance.draw()
|
|
226
200
|
else:
|
|
227
201
|
last_pb_instance = None
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
@@ -20,8 +20,9 @@ from enum import Enum
|
|
|
20
20
|
from typing import Iterable, Optional
|
|
21
21
|
from warnings import warn
|
|
22
22
|
|
|
23
|
-
from
|
|
24
|
-
from logbar
|
|
23
|
+
from . import LogBar
|
|
24
|
+
from .logbar import update_last_pb_instance
|
|
25
|
+
from .terminal import terminal_size
|
|
25
26
|
|
|
26
27
|
logger = LogBar.shared()
|
|
27
28
|
|
|
@@ -41,7 +42,6 @@ class RenderMode(str, Enum):
|
|
|
41
42
|
class ProgressBar:
|
|
42
43
|
def __init__(self, iterable: Iterable):
|
|
43
44
|
self._iterating = False # state: in init or active iteration
|
|
44
|
-
self._skip_next_draw = False
|
|
45
45
|
|
|
46
46
|
self._render_mode = RenderMode.AUTO
|
|
47
47
|
|
|
@@ -110,10 +110,6 @@ class ProgressBar:
|
|
|
110
110
|
self._render_mode = RenderMode.MANUAL
|
|
111
111
|
return self
|
|
112
112
|
|
|
113
|
-
def skip_next_draw(self):
|
|
114
|
-
if not self._skip_next_draw:
|
|
115
|
-
self._skip_next_draw = True
|
|
116
|
-
|
|
117
113
|
def draw(self):
|
|
118
114
|
columns, _ = terminal_size()
|
|
119
115
|
|
|
@@ -144,11 +140,11 @@ class ProgressBar:
|
|
|
144
140
|
if self._subtitle and len(self._subtitle) < self.max_subtitle_len:
|
|
145
141
|
padding += " " * (self.max_subtitle_len - len(self._subtitle))
|
|
146
142
|
|
|
147
|
-
bar_length = columns - pre_bar_size - len(log) -
|
|
143
|
+
bar_length = columns - pre_bar_size - len(log) - 3 # bar|_ == 2 chars + 1 char for cursor
|
|
148
144
|
|
|
149
145
|
filled_length = int(bar_length * self.step() // len(self))
|
|
150
146
|
bar = self._fill * filled_length + '-' * (bar_length - filled_length)
|
|
151
|
-
self.log(bar=bar, log=log,
|
|
147
|
+
self.log(bar=bar, log=log, pre_bar_padding=padding, end='') # '\n' if percent_num >= 1.0 else ''
|
|
152
148
|
|
|
153
149
|
def calc_time(self, iteration):
|
|
154
150
|
used_time = int(time.time() - self.time)
|
|
@@ -156,8 +152,7 @@ class ProgressBar:
|
|
|
156
152
|
remaining = str(datetime.timedelta(seconds=int((used_time / max(iteration, 1)) * len(self))))
|
|
157
153
|
return f"{formatted_time} / {remaining}"
|
|
158
154
|
|
|
159
|
-
def log(self, bar:str, log:str,
|
|
160
|
-
# print(f'\r{self.prefix} {self.info_text} |{bar}| {log}', end='', flush=True)
|
|
155
|
+
def log(self, bar:str, log:str, pre_bar_padding:str = "", end: str = ""):
|
|
161
156
|
out = ""
|
|
162
157
|
if self._title:
|
|
163
158
|
out += self._title + " "
|
|
@@ -165,7 +160,8 @@ class ProgressBar:
|
|
|
165
160
|
if self._subtitle:
|
|
166
161
|
out += self._subtitle + " "
|
|
167
162
|
|
|
168
|
-
|
|
163
|
+
if pre_bar_padding:
|
|
164
|
+
out += pre_bar_padding
|
|
169
165
|
|
|
170
166
|
if self.ui_show_left_steps:
|
|
171
167
|
out += self.ui_show_left_steps_text
|
|
@@ -241,7 +237,7 @@ class ProgressBar:
|
|
|
241
237
|
iterable = self.iterable
|
|
242
238
|
|
|
243
239
|
for obj in iterable:
|
|
244
|
-
#
|
|
240
|
+
# update running state
|
|
245
241
|
if not self._iterating:
|
|
246
242
|
self.iterating = True
|
|
247
243
|
|
|
@@ -250,17 +246,10 @@ class ProgressBar:
|
|
|
250
246
|
if self._render_mode == RenderMode.AUTO:
|
|
251
247
|
self.draw()
|
|
252
248
|
|
|
253
|
-
# if not self._skip_next_draw:
|
|
254
|
-
# if self._render_mode == RenderMode.AUTO:
|
|
255
|
-
# self.draw()
|
|
256
|
-
# else:
|
|
257
|
-
# self._skip_next_draw = False
|
|
258
249
|
yield obj
|
|
259
250
|
|
|
260
|
-
# self.progress()
|
|
261
251
|
self.close()
|
|
262
252
|
return
|
|
263
253
|
|
|
264
254
|
def close(self):
|
|
265
255
|
self.closed = True
|
|
266
|
-
#self.log(f"{self.fill * self.bar_length}", "100.0%", end="\n")
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: logbar
|
|
3
|
-
Version: 0.0.
|
|
4
|
-
Summary: A unified Logger and ProgressBar util with zero dependencies.
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: A unified Logger and ProgressBar util with zero dependencies.
|
|
5
5
|
Home-page: https://github.com/ModelCloud/LogBar
|
|
6
6
|
Author: ModelCloud
|
|
7
7
|
Author-email: qubitium@modelcloud.ai
|
|
@@ -18,7 +18,7 @@ from pathlib import Path
|
|
|
18
18
|
|
|
19
19
|
from setuptools import find_packages, setup
|
|
20
20
|
|
|
21
|
-
__version__ = "0.0.
|
|
21
|
+
__version__ = "0.0.3"
|
|
22
22
|
|
|
23
23
|
with open("requirements.txt") as f:
|
|
24
24
|
requirements = f.read().splitlines()
|
|
@@ -28,7 +28,7 @@ setup(
|
|
|
28
28
|
version=__version__,
|
|
29
29
|
author="ModelCloud",
|
|
30
30
|
author_email="qubitium@modelcloud.ai",
|
|
31
|
-
description="A unified Logger and ProgressBar util with zero dependencies.
|
|
31
|
+
description="A unified Logger and ProgressBar util with zero dependencies.",
|
|
32
32
|
long_description=(Path(__file__).parent / "README.md").read_text(encoding="UTF-8"),
|
|
33
33
|
long_description_content_type="text/markdown",
|
|
34
34
|
url="https://github.com/ModelCloud/LogBar",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|