nnlogging 0.1.2__py3-none-any.whl
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.
- nnlogging/__init__.py +16 -0
- nnlogging/shell.py +450 -0
- nnlogging/shell_protocol.py +86 -0
- nnlogging/typings/__init__.py +41 -0
- nnlogging/typings/aliases.py +66 -0
- nnlogging/typings/exceptions.py +10 -0
- nnlogging/typings/generics.py +23 -0
- nnlogging/typings/protocols.py +14 -0
- nnlogging/utils/__init__.py +83 -0
- nnlogging/utils/exception/__init__.py +11 -0
- nnlogging/utils/exception/branch_exists.py +49 -0
- nnlogging/utils/exception/branch_not_found.py +49 -0
- nnlogging/utils/exception/task_exists.py +54 -0
- nnlogging/utils/exception/task_not_found.py +49 -0
- nnlogging/utils/factory_funcs/rich_.py +154 -0
- nnlogging/utils/factory_funcs/shell_.py +192 -0
- nnlogging/utils/helpers.py +39 -0
- nnlogging/utils/shell_funcs/branch_.py +164 -0
- nnlogging/utils/shell_funcs/logger_.py +199 -0
- nnlogging/utils/shell_funcs/run_.py +97 -0
- nnlogging/utils/shell_funcs/task_.py +111 -0
- nnlogging-0.1.2.dist-info/METADATA +146 -0
- nnlogging-0.1.2.dist-info/RECORD +24 -0
- nnlogging-0.1.2.dist-info/WHEEL +4 -0
nnlogging/__init__.py
ADDED
nnlogging/shell.py
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from collections.abc import Collection
|
|
3
|
+
from logging import Formatter as LoggingFormatter, Logger as LoggingLogger
|
|
4
|
+
from typing import Literal, cast
|
|
5
|
+
|
|
6
|
+
from aim import Repo as AimRepo, Run as AimRun
|
|
7
|
+
from aim.sdk.types import AimObject
|
|
8
|
+
from rich.highlighter import Highlighter as RichHighlighter
|
|
9
|
+
from rich.progress import ProgressColumn as RichProgressColumn
|
|
10
|
+
from rich.theme import Theme as RichTheme
|
|
11
|
+
|
|
12
|
+
from nnlogging.typings import (
|
|
13
|
+
Branch,
|
|
14
|
+
ConsolePrintOptions,
|
|
15
|
+
FormatTimeCallable,
|
|
16
|
+
LogOptions,
|
|
17
|
+
Omitable,
|
|
18
|
+
Sink,
|
|
19
|
+
)
|
|
20
|
+
from nnlogging.utils import (
|
|
21
|
+
BranchConfig,
|
|
22
|
+
LoggerConfig,
|
|
23
|
+
RunConfig,
|
|
24
|
+
add_tag as _add_tag,
|
|
25
|
+
advance as _advance,
|
|
26
|
+
branch_add as _branch_add,
|
|
27
|
+
branch_configure as _branch_configure,
|
|
28
|
+
branch_remove as _branch_remove,
|
|
29
|
+
critical as _critical,
|
|
30
|
+
debug as _debug,
|
|
31
|
+
error as _error,
|
|
32
|
+
exception as _exception,
|
|
33
|
+
info as _info,
|
|
34
|
+
log as _log,
|
|
35
|
+
logger_configure as _logger_configure,
|
|
36
|
+
remove_tag as _remove_tag,
|
|
37
|
+
run_configure as _run_configure,
|
|
38
|
+
task_add as _task_add,
|
|
39
|
+
task_remove as _task_remove,
|
|
40
|
+
track as _track,
|
|
41
|
+
update_metadata as _update_metadata,
|
|
42
|
+
warn as _warn,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
global_shell = None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Shell:
|
|
49
|
+
def __init__(
|
|
50
|
+
self,
|
|
51
|
+
shell_name: str = "nnlogging",
|
|
52
|
+
/,
|
|
53
|
+
*,
|
|
54
|
+
logger_config: LoggerConfig | None = None,
|
|
55
|
+
run_config: RunConfig | None = None,
|
|
56
|
+
branch_config: BranchConfig | None = None,
|
|
57
|
+
):
|
|
58
|
+
self.logger: LoggingLogger | None = None
|
|
59
|
+
self.run: AimRun | None = None
|
|
60
|
+
self.branches: dict[str, Branch] = dict()
|
|
61
|
+
|
|
62
|
+
self.name: str = shell_name
|
|
63
|
+
self.logger_config: LoggerConfig = logger_config or LoggerConfig()
|
|
64
|
+
self.run_config: RunConfig = run_config or RunConfig()
|
|
65
|
+
self.branch_config: BranchConfig = branch_config or BranchConfig()
|
|
66
|
+
|
|
67
|
+
def logger_configure(
|
|
68
|
+
self,
|
|
69
|
+
config: LoggerConfig | None = None,
|
|
70
|
+
/,
|
|
71
|
+
*,
|
|
72
|
+
name: Omitable[str] = ...,
|
|
73
|
+
level: Omitable[int | str] = ...,
|
|
74
|
+
propagate: Omitable[bool] = ...,
|
|
75
|
+
):
|
|
76
|
+
_logger_configure(
|
|
77
|
+
self,
|
|
78
|
+
config,
|
|
79
|
+
name=name,
|
|
80
|
+
level=level,
|
|
81
|
+
propagate=propagate,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
def run_configure(
|
|
85
|
+
self,
|
|
86
|
+
config: RunConfig | None = None,
|
|
87
|
+
/,
|
|
88
|
+
*,
|
|
89
|
+
experiment: Omitable[str | None] = ...,
|
|
90
|
+
repo: Omitable[str | AimRepo | None] = ...,
|
|
91
|
+
system_tracking_interval: Omitable[float | None] = ...,
|
|
92
|
+
capture_terminal_logs: Omitable[bool] = ...,
|
|
93
|
+
log_system_params: Omitable[bool] = ...,
|
|
94
|
+
run_hash: Omitable[str | None] = ...,
|
|
95
|
+
read_only: Omitable[bool] = ...,
|
|
96
|
+
force_resume: Omitable[bool] = ...,
|
|
97
|
+
):
|
|
98
|
+
_run_configure(
|
|
99
|
+
self,
|
|
100
|
+
config,
|
|
101
|
+
experiment=experiment,
|
|
102
|
+
repo=repo,
|
|
103
|
+
system_tracking_interval=system_tracking_interval,
|
|
104
|
+
capture_terminal_logs=capture_terminal_logs,
|
|
105
|
+
log_system_params=log_system_params,
|
|
106
|
+
run_hash=run_hash,
|
|
107
|
+
read_only=read_only,
|
|
108
|
+
force_resume=force_resume,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
def branch_configure(
|
|
112
|
+
self,
|
|
113
|
+
config: BranchConfig | None = None,
|
|
114
|
+
/,
|
|
115
|
+
*,
|
|
116
|
+
markup: Omitable[bool] = ...,
|
|
117
|
+
highlighter: Omitable[RichHighlighter] = ...,
|
|
118
|
+
width: Omitable[int | None] = ...,
|
|
119
|
+
height: Omitable[int | None] = ...,
|
|
120
|
+
emoji: Omitable[bool] = ...,
|
|
121
|
+
color_system: Omitable[Literal["auto", "standard", "truecolor"] | None] = ...,
|
|
122
|
+
theme: Omitable[RichTheme] = ...,
|
|
123
|
+
soft_wrap: Omitable[bool] = ...,
|
|
124
|
+
force_terminal: Omitable[bool | None] = ...,
|
|
125
|
+
force_jupyter: Omitable[bool | None] = ...,
|
|
126
|
+
force_interactive: Omitable[bool | None] = ...,
|
|
127
|
+
level: Omitable[str | int] = ...,
|
|
128
|
+
show_level: Omitable[bool] = ...,
|
|
129
|
+
show_time: Omitable[bool] = ...,
|
|
130
|
+
show_path: Omitable[bool] = ...,
|
|
131
|
+
log_time_format: Omitable[str | FormatTimeCallable] = ...,
|
|
132
|
+
omit_repeated_times: Omitable[bool] = ...,
|
|
133
|
+
rich_tracebacks: Omitable[bool] = ...,
|
|
134
|
+
tracebacks_show_locals: Omitable[bool] = ...,
|
|
135
|
+
log_message_format: Omitable[str | LoggingFormatter] = ...,
|
|
136
|
+
columns: Omitable[Collection[str | RichProgressColumn]] = ...,
|
|
137
|
+
transient: Omitable[bool] = ...,
|
|
138
|
+
refresh_per_second: Omitable[float] = ...,
|
|
139
|
+
speed_estimate_period: Omitable[float] = ...,
|
|
140
|
+
default_column_markup: Omitable[bool] = ...,
|
|
141
|
+
):
|
|
142
|
+
_branch_configure(
|
|
143
|
+
self,
|
|
144
|
+
config,
|
|
145
|
+
markup=markup,
|
|
146
|
+
highlighter=highlighter,
|
|
147
|
+
width=width,
|
|
148
|
+
height=height,
|
|
149
|
+
emoji=emoji,
|
|
150
|
+
color_system=color_system,
|
|
151
|
+
theme=theme,
|
|
152
|
+
soft_wrap=soft_wrap,
|
|
153
|
+
force_terminal=force_terminal,
|
|
154
|
+
force_jupyter=force_jupyter,
|
|
155
|
+
force_interactive=force_interactive,
|
|
156
|
+
level=level,
|
|
157
|
+
show_level=show_level,
|
|
158
|
+
show_time=show_time,
|
|
159
|
+
show_path=show_path,
|
|
160
|
+
log_time_format=log_time_format,
|
|
161
|
+
omit_repeated_times=omit_repeated_times,
|
|
162
|
+
rich_tracebacks=rich_tracebacks,
|
|
163
|
+
tracebacks_show_locals=tracebacks_show_locals,
|
|
164
|
+
log_message_format=log_message_format,
|
|
165
|
+
columns=columns,
|
|
166
|
+
transient=transient,
|
|
167
|
+
refresh_per_second=refresh_per_second,
|
|
168
|
+
speed_estimate_period=speed_estimate_period,
|
|
169
|
+
default_column_markup=default_column_markup,
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
def branch_add(
|
|
173
|
+
self,
|
|
174
|
+
name: str,
|
|
175
|
+
/,
|
|
176
|
+
sink: Sink | None = None,
|
|
177
|
+
*,
|
|
178
|
+
markup: Omitable[bool] = ...,
|
|
179
|
+
highlighter: Omitable[RichHighlighter] = ...,
|
|
180
|
+
width: Omitable[int | None] = ...,
|
|
181
|
+
height: Omitable[int | None] = ...,
|
|
182
|
+
emoji: Omitable[bool] = ...,
|
|
183
|
+
color_system: Omitable[Literal["auto", "standard", "truecolor"] | None] = ...,
|
|
184
|
+
theme: Omitable[RichTheme] = ...,
|
|
185
|
+
soft_wrap: Omitable[bool] = ...,
|
|
186
|
+
force_terminal: Omitable[bool | None] = ...,
|
|
187
|
+
force_jupyter: Omitable[bool | None] = ...,
|
|
188
|
+
force_interactive: Omitable[bool | None] = ...,
|
|
189
|
+
level: Omitable[str | int] = ...,
|
|
190
|
+
show_level: Omitable[bool] = ...,
|
|
191
|
+
show_time: Omitable[bool] = ...,
|
|
192
|
+
show_path: Omitable[bool] = ...,
|
|
193
|
+
log_time_format: Omitable[str | FormatTimeCallable] = ...,
|
|
194
|
+
omit_repeated_times: Omitable[bool] = ...,
|
|
195
|
+
rich_tracebacks: Omitable[bool] = ...,
|
|
196
|
+
tracebacks_show_locals: Omitable[bool] = ...,
|
|
197
|
+
log_message_format: Omitable[str | LoggingFormatter] = ...,
|
|
198
|
+
):
|
|
199
|
+
_branch_add(
|
|
200
|
+
self,
|
|
201
|
+
name,
|
|
202
|
+
sink=sink,
|
|
203
|
+
markup=markup,
|
|
204
|
+
highlighter=highlighter,
|
|
205
|
+
width=width,
|
|
206
|
+
height=height,
|
|
207
|
+
emoji=emoji,
|
|
208
|
+
color_system=color_system,
|
|
209
|
+
theme=theme,
|
|
210
|
+
soft_wrap=soft_wrap,
|
|
211
|
+
force_terminal=force_terminal,
|
|
212
|
+
force_jupyter=force_jupyter,
|
|
213
|
+
force_interactive=force_interactive,
|
|
214
|
+
level=level,
|
|
215
|
+
show_level=show_level,
|
|
216
|
+
show_time=show_time,
|
|
217
|
+
show_path=show_path,
|
|
218
|
+
log_time_format=log_time_format,
|
|
219
|
+
omit_repeated_times=omit_repeated_times,
|
|
220
|
+
rich_tracebacks=rich_tracebacks,
|
|
221
|
+
tracebacks_show_locals=tracebacks_show_locals,
|
|
222
|
+
log_message_format=log_message_format,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
def branch_remove(
|
|
226
|
+
self,
|
|
227
|
+
name: str,
|
|
228
|
+
/,
|
|
229
|
+
):
|
|
230
|
+
_branch_remove(
|
|
231
|
+
self,
|
|
232
|
+
name,
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
def task_add(
|
|
236
|
+
self,
|
|
237
|
+
name: str,
|
|
238
|
+
/,
|
|
239
|
+
*,
|
|
240
|
+
desc: str,
|
|
241
|
+
total: float | None,
|
|
242
|
+
done: float = 0,
|
|
243
|
+
):
|
|
244
|
+
_task_add(
|
|
245
|
+
self,
|
|
246
|
+
name,
|
|
247
|
+
desc=desc,
|
|
248
|
+
total=total,
|
|
249
|
+
done=done,
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
def task_remove(
|
|
253
|
+
self,
|
|
254
|
+
name: str,
|
|
255
|
+
/,
|
|
256
|
+
):
|
|
257
|
+
_task_remove(
|
|
258
|
+
self,
|
|
259
|
+
name,
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
def log(
|
|
263
|
+
self,
|
|
264
|
+
level: int,
|
|
265
|
+
msg: object,
|
|
266
|
+
*args: object,
|
|
267
|
+
log_options: LogOptions | None = None,
|
|
268
|
+
console_options: ConsolePrintOptions | None = None,
|
|
269
|
+
):
|
|
270
|
+
_log(
|
|
271
|
+
self,
|
|
272
|
+
level,
|
|
273
|
+
msg,
|
|
274
|
+
*args,
|
|
275
|
+
log_options=log_options,
|
|
276
|
+
console_options=console_options,
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
def debug(
|
|
280
|
+
self,
|
|
281
|
+
msg: object,
|
|
282
|
+
*args: object,
|
|
283
|
+
log_options: LogOptions | None = None,
|
|
284
|
+
console_options: ConsolePrintOptions | None = None,
|
|
285
|
+
):
|
|
286
|
+
_debug(
|
|
287
|
+
self,
|
|
288
|
+
msg,
|
|
289
|
+
*args,
|
|
290
|
+
log_options=log_options,
|
|
291
|
+
console_options=console_options,
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
def info(
|
|
295
|
+
self,
|
|
296
|
+
msg: object,
|
|
297
|
+
*args: object,
|
|
298
|
+
log_options: LogOptions | None = None,
|
|
299
|
+
console_options: ConsolePrintOptions | None = None,
|
|
300
|
+
):
|
|
301
|
+
_info(
|
|
302
|
+
self,
|
|
303
|
+
msg,
|
|
304
|
+
*args,
|
|
305
|
+
log_options=log_options,
|
|
306
|
+
console_options=console_options,
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
def warn(
|
|
310
|
+
self,
|
|
311
|
+
msg: object,
|
|
312
|
+
*args: object,
|
|
313
|
+
log_options: LogOptions | None = None,
|
|
314
|
+
console_options: ConsolePrintOptions | None = None,
|
|
315
|
+
):
|
|
316
|
+
_warn(
|
|
317
|
+
self,
|
|
318
|
+
msg,
|
|
319
|
+
*args,
|
|
320
|
+
log_options=log_options,
|
|
321
|
+
console_options=console_options,
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
def error(
|
|
325
|
+
self,
|
|
326
|
+
msg: object,
|
|
327
|
+
*args: object,
|
|
328
|
+
log_options: LogOptions | None = None,
|
|
329
|
+
console_options: ConsolePrintOptions | None = None,
|
|
330
|
+
):
|
|
331
|
+
_error(
|
|
332
|
+
self,
|
|
333
|
+
msg,
|
|
334
|
+
*args,
|
|
335
|
+
log_options=log_options,
|
|
336
|
+
console_options=console_options,
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
def critical(
|
|
340
|
+
self,
|
|
341
|
+
msg: object,
|
|
342
|
+
*args: object,
|
|
343
|
+
log_options: LogOptions | None = None,
|
|
344
|
+
console_options: ConsolePrintOptions | None = None,
|
|
345
|
+
):
|
|
346
|
+
_critical(
|
|
347
|
+
self,
|
|
348
|
+
msg,
|
|
349
|
+
*args,
|
|
350
|
+
log_options=log_options,
|
|
351
|
+
console_options=console_options,
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
def exception(
|
|
355
|
+
self,
|
|
356
|
+
msg: object,
|
|
357
|
+
*args: object,
|
|
358
|
+
log_options: LogOptions | None = None,
|
|
359
|
+
console_options: ConsolePrintOptions | None = None,
|
|
360
|
+
):
|
|
361
|
+
_exception(
|
|
362
|
+
self,
|
|
363
|
+
msg,
|
|
364
|
+
*args,
|
|
365
|
+
log_options=log_options,
|
|
366
|
+
console_options=console_options,
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
def advance(
|
|
370
|
+
self,
|
|
371
|
+
name: str,
|
|
372
|
+
/,
|
|
373
|
+
value: float,
|
|
374
|
+
):
|
|
375
|
+
_advance(
|
|
376
|
+
self,
|
|
377
|
+
name,
|
|
378
|
+
advance=value,
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
def track(
|
|
382
|
+
self,
|
|
383
|
+
value: object,
|
|
384
|
+
/,
|
|
385
|
+
name: str | None,
|
|
386
|
+
*,
|
|
387
|
+
step: int | None,
|
|
388
|
+
epoch: int | None,
|
|
389
|
+
context: AimObject,
|
|
390
|
+
):
|
|
391
|
+
_track(
|
|
392
|
+
self,
|
|
393
|
+
value,
|
|
394
|
+
name=name,
|
|
395
|
+
step=step,
|
|
396
|
+
epoch=epoch,
|
|
397
|
+
context=context,
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
def add_tag(
|
|
401
|
+
self,
|
|
402
|
+
name: str,
|
|
403
|
+
/,
|
|
404
|
+
):
|
|
405
|
+
_add_tag(
|
|
406
|
+
self,
|
|
407
|
+
name,
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
def remove_tag(
|
|
411
|
+
self,
|
|
412
|
+
name: str,
|
|
413
|
+
/,
|
|
414
|
+
):
|
|
415
|
+
_remove_tag(
|
|
416
|
+
self,
|
|
417
|
+
name,
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
def update_metadata(
|
|
421
|
+
self,
|
|
422
|
+
name: str,
|
|
423
|
+
/,
|
|
424
|
+
metadata: AimObject,
|
|
425
|
+
):
|
|
426
|
+
_update_metadata(
|
|
427
|
+
self,
|
|
428
|
+
name,
|
|
429
|
+
metadata,
|
|
430
|
+
)
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
def get_global_shell(sink: Sink | Literal["stderr", "stdout"] = "stderr"):
|
|
434
|
+
global global_shell
|
|
435
|
+
if global_shell is None:
|
|
436
|
+
global_shell = Shell()
|
|
437
|
+
if isinstance(sink, str) and sink in ("stderr", "stdout"):
|
|
438
|
+
sink = cast(Sink, getattr(sys, sink))
|
|
439
|
+
global_shell.branch_add("default", sink)
|
|
440
|
+
global_shell.debug(f'"global_shell" is now initialized as {repr(global_shell)}')
|
|
441
|
+
return global_shell
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
def replace_global_shell(shell: Shell):
|
|
445
|
+
global global_shell
|
|
446
|
+
msg = f'"global_shell" has been replaced from {repr(global_shell)} to {repr(shell)}'
|
|
447
|
+
if global_shell is not None:
|
|
448
|
+
global_shell.info(msg)
|
|
449
|
+
global_shell = shell
|
|
450
|
+
global_shell.debug(msg)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
from logging import Logger as LoggingLogger
|
|
2
|
+
from typing import Protocol, runtime_checkable
|
|
3
|
+
|
|
4
|
+
from aim import Run as AimRun
|
|
5
|
+
from aim.sdk.types import AimObject
|
|
6
|
+
|
|
7
|
+
from nnlogging.typings import Branch, LogOptions
|
|
8
|
+
from nnlogging.utils.factory_funcs.shell_ import BranchConfig, LoggerConfig, RunConfig
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@runtime_checkable
|
|
12
|
+
class ShellProtocol(Protocol):
|
|
13
|
+
logger_config: LoggerConfig
|
|
14
|
+
run_config: RunConfig
|
|
15
|
+
branch_config: BranchConfig
|
|
16
|
+
logger: LoggingLogger | None
|
|
17
|
+
run: AimRun | None
|
|
18
|
+
branches: dict[str, Branch]
|
|
19
|
+
|
|
20
|
+
def logger_configure(
|
|
21
|
+
self,
|
|
22
|
+
config: LoggerConfig | None,
|
|
23
|
+
/,
|
|
24
|
+
): ...
|
|
25
|
+
def run_configure(
|
|
26
|
+
self,
|
|
27
|
+
conf: RunConfig | None,
|
|
28
|
+
/,
|
|
29
|
+
): ...
|
|
30
|
+
def branch_configure(
|
|
31
|
+
self,
|
|
32
|
+
conf: BranchConfig | None,
|
|
33
|
+
/,
|
|
34
|
+
): ...
|
|
35
|
+
def branch_add(
|
|
36
|
+
self,
|
|
37
|
+
name: str,
|
|
38
|
+
/,
|
|
39
|
+
): ...
|
|
40
|
+
def branch_remove(
|
|
41
|
+
self,
|
|
42
|
+
name: str,
|
|
43
|
+
/,
|
|
44
|
+
): ...
|
|
45
|
+
def task_add(
|
|
46
|
+
self,
|
|
47
|
+
name: str,
|
|
48
|
+
/,
|
|
49
|
+
*,
|
|
50
|
+
desc: str,
|
|
51
|
+
total: float | None,
|
|
52
|
+
): ...
|
|
53
|
+
def task_remove(
|
|
54
|
+
self,
|
|
55
|
+
name: str,
|
|
56
|
+
/,
|
|
57
|
+
): ...
|
|
58
|
+
def log(
|
|
59
|
+
self,
|
|
60
|
+
level: int,
|
|
61
|
+
msg: object,
|
|
62
|
+
/,
|
|
63
|
+
): ...
|
|
64
|
+
def exception(
|
|
65
|
+
self,
|
|
66
|
+
msg: object,
|
|
67
|
+
/,
|
|
68
|
+
*,
|
|
69
|
+
log_options: LogOptions | None = None,
|
|
70
|
+
): ...
|
|
71
|
+
def advance(
|
|
72
|
+
self,
|
|
73
|
+
name: str,
|
|
74
|
+
/,
|
|
75
|
+
value: float,
|
|
76
|
+
): ...
|
|
77
|
+
def track(
|
|
78
|
+
self,
|
|
79
|
+
value: object,
|
|
80
|
+
/,
|
|
81
|
+
name: str | None,
|
|
82
|
+
*,
|
|
83
|
+
step: int | None,
|
|
84
|
+
epoch: int | None,
|
|
85
|
+
context: AimObject,
|
|
86
|
+
): ...
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from .aliases import (
|
|
2
|
+
Branch,
|
|
3
|
+
ConsolePrintOptions,
|
|
4
|
+
ExcInfo,
|
|
5
|
+
FormatTimeCallable,
|
|
6
|
+
GenericPath,
|
|
7
|
+
LogOptions,
|
|
8
|
+
Sink,
|
|
9
|
+
)
|
|
10
|
+
from .exceptions import (
|
|
11
|
+
BranchExistsError,
|
|
12
|
+
BranchNotFoundError,
|
|
13
|
+
TaskExistsError,
|
|
14
|
+
TaskNotFoundError,
|
|
15
|
+
)
|
|
16
|
+
from .generics import DataclassT, Omitable, Pathlike, T
|
|
17
|
+
from .protocols import TerminalWritable, Writable
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
# aliases
|
|
21
|
+
"Branch",
|
|
22
|
+
"Sink",
|
|
23
|
+
"GenericPath",
|
|
24
|
+
"FormatTimeCallable",
|
|
25
|
+
"ExcInfo",
|
|
26
|
+
"ConsolePrintOptions",
|
|
27
|
+
"LogOptions",
|
|
28
|
+
# generics
|
|
29
|
+
"T",
|
|
30
|
+
"DataclassT",
|
|
31
|
+
"Omitable",
|
|
32
|
+
"Pathlike",
|
|
33
|
+
# protocols
|
|
34
|
+
"Writable",
|
|
35
|
+
"TerminalWritable",
|
|
36
|
+
# exception
|
|
37
|
+
"BranchNotFoundError",
|
|
38
|
+
"BranchExistsError",
|
|
39
|
+
"TaskExistsError",
|
|
40
|
+
"TaskNotFoundError",
|
|
41
|
+
]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from collections.abc import Mapping
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from types import TracebackType
|
|
5
|
+
from typing import Callable, Literal, TypeAlias, TypedDict
|
|
6
|
+
|
|
7
|
+
from rich.console import Console as RichConsole
|
|
8
|
+
from rich.logging import RichHandler
|
|
9
|
+
from rich.progress import Progress as RichProgress, TaskID as RichTaskID
|
|
10
|
+
from rich.style import Style as RichStyle
|
|
11
|
+
from rich.text import Text as RichText
|
|
12
|
+
|
|
13
|
+
from nnlogging.typings.generics import Pathlike
|
|
14
|
+
from nnlogging.typings.protocols import TerminalWritable, Writable
|
|
15
|
+
|
|
16
|
+
if sys.version_info >= (3, 11):
|
|
17
|
+
from typing import NotRequired, Required
|
|
18
|
+
else:
|
|
19
|
+
from typing_extensions import NotRequired, Required
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
Sink: TypeAlias = Writable | TerminalWritable
|
|
23
|
+
GenericPath = Pathlike[str] | Pathlike[bytes]
|
|
24
|
+
FormatTimeCallable: TypeAlias = Callable[[datetime], RichText]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Branch(TypedDict):
|
|
28
|
+
console: Required[RichConsole]
|
|
29
|
+
handler: Required[RichHandler]
|
|
30
|
+
tasks: Required[dict[str, RichTaskID]]
|
|
31
|
+
progress: Required[RichProgress | None]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
JustifyMethod = Literal["default", "left", "center", "right", "full"]
|
|
35
|
+
OverflowMethod = Literal["fold", "crop", "ellipsis", "ignore"]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ConsolePrintOptions(TypedDict):
|
|
39
|
+
sep: NotRequired[str]
|
|
40
|
+
end: NotRequired[str]
|
|
41
|
+
style: NotRequired[str | RichStyle | None]
|
|
42
|
+
justify: NotRequired[JustifyMethod | None]
|
|
43
|
+
overflow: NotRequired[OverflowMethod | None]
|
|
44
|
+
no_wrap: NotRequired[bool | None]
|
|
45
|
+
emoji: NotRequired[bool | None]
|
|
46
|
+
markup: NotRequired[bool | None]
|
|
47
|
+
highlight: NotRequired[bool | None]
|
|
48
|
+
width: NotRequired[int | None]
|
|
49
|
+
height: NotRequired[int | None]
|
|
50
|
+
crop: NotRequired[bool]
|
|
51
|
+
soft_wrap: NotRequired[bool | None]
|
|
52
|
+
new_line_start: NotRequired[bool]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
_SysExcInfo: TypeAlias = (
|
|
56
|
+
tuple[type[BaseException], BaseException, TracebackType | None]
|
|
57
|
+
| tuple[None, None, None]
|
|
58
|
+
)
|
|
59
|
+
ExcInfo: TypeAlias = None | bool | _SysExcInfo | BaseException
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class LogOptions(TypedDict):
|
|
63
|
+
exc_info: NotRequired[ExcInfo]
|
|
64
|
+
stack_info: NotRequired[bool]
|
|
65
|
+
stacklevel: NotRequired[int]
|
|
66
|
+
extra: NotRequired[Mapping[str, object] | None]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from dataclasses import Field
|
|
3
|
+
from os import PathLike
|
|
4
|
+
from types import EllipsisType
|
|
5
|
+
from typing import Any, ClassVar, Protocol, TypeVar
|
|
6
|
+
|
|
7
|
+
if sys.version_info >= (3, 12):
|
|
8
|
+
from typing import TypeAliasType
|
|
9
|
+
else:
|
|
10
|
+
from typing_extensions import TypeAliasType
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DataclassInstance(Protocol):
|
|
14
|
+
__dataclass_fields__: ClassVar[dict[str, Field[Any]]] # pyright: ignore[reportExplicitAny]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
T = TypeVar("T")
|
|
18
|
+
PathT = TypeVar("PathT", str, bytes)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
Omitable = TypeAliasType("Omitable", T | EllipsisType, type_params=(T,))
|
|
22
|
+
DataclassT = TypeVar("DataclassT", bound=DataclassInstance)
|
|
23
|
+
Pathlike = TypeAliasType("Pathlike", PathT | PathLike[PathT], type_params=(PathT,))
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import Protocol, runtime_checkable
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@runtime_checkable
|
|
5
|
+
class Writable(Protocol):
|
|
6
|
+
def write(self, text: str, /) -> int: ...
|
|
7
|
+
def flush(self) -> None: ...
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@runtime_checkable
|
|
11
|
+
class TerminalWritable(Protocol):
|
|
12
|
+
def write(self, text: str, /) -> int: ...
|
|
13
|
+
def flush(self) -> None: ...
|
|
14
|
+
def isatty(self) -> bool: ...
|