nnlogging 0.1.0__py3-none-any.whl → 0.1.1__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.

Potentially problematic release.


This version of nnlogging might be problematic. Click here for more details.

nnlogging/__init__.py CHANGED
@@ -1,7 +1,16 @@
1
- """nnlog"""
1
+ """
2
+ Package: `nnlogging`
3
+ Version: ``0.1.1``
4
+ """
2
5
 
3
- from . import shell
4
- from . import utils
6
+ from .shell import Shell
7
+ from .utils import LoggerConfig
5
8
 
9
+ __all__ = ["Shell"]
6
10
 
7
- __all__ = ["shell", "utils"]
11
+ shell = Shell(
12
+ "__nnlogging__",
13
+ logger_config=LoggerConfig(
14
+ name="__nnlogging__",
15
+ ),
16
+ )
@@ -0,0 +1,8 @@
1
+ """
2
+ ``nnlogging.shell``
3
+ """
4
+
5
+ from .protocol import ShellProtocol
6
+ from .shell import Shell
7
+
8
+ __all__ = ["Shell", "ShellProtocol"]
@@ -0,0 +1,11 @@
1
+ from .branch_exists import raise_branch_exists_error
2
+ from .branch_not_found import raise_branch_not_found_error
3
+ from .task_exists import raise_task_exists_error
4
+ from .task_not_found import raise_task_not_found_error
5
+
6
+ __all__ = [
7
+ "raise_branch_exists_error",
8
+ "raise_branch_not_found_error",
9
+ "raise_task_exists_error",
10
+ "raise_task_not_found_error",
11
+ ]
@@ -0,0 +1,49 @@
1
+ import sys
2
+
3
+ if sys.version_info >= (3, 11):
4
+ from typing import Never
5
+ else:
6
+ from typing_extensions import Never
7
+
8
+ from nnlogging.shell.protocol import ShellProtocol
9
+ from nnlogging.typings import BranchExistsError, LogOptions
10
+ from nnlogging.utils import get__debugging, get_name
11
+
12
+
13
+ def _branch_exists_msg(
14
+ inst: ShellProtocol,
15
+ name: str,
16
+ /,
17
+ ):
18
+ return f'branch "{name}" already exists in {get_name(inst)}.branches'
19
+
20
+
21
+ def _branch_exists_error(
22
+ inst: ShellProtocol,
23
+ name: str,
24
+ /,
25
+ ):
26
+ return BranchExistsError(
27
+ f'branch "{name}" already exists in {get_name(inst)}.branches: {inst.branches}'
28
+ )
29
+
30
+
31
+ def raise_branch_exists_error(
32
+ inst: ShellProtocol,
33
+ name: str,
34
+ /,
35
+ *,
36
+ stacklevel: int = 1,
37
+ ) -> Never:
38
+ try:
39
+ raise _branch_exists_error(inst, name)
40
+ except BranchExistsError as e:
41
+ inst.exception(
42
+ _branch_exists_msg(inst, name),
43
+ log_options=LogOptions(
44
+ exc_info=e,
45
+ stack_info=get__debugging(inst),
46
+ stacklevel=stacklevel + 1,
47
+ ),
48
+ )
49
+ raise
@@ -0,0 +1,50 @@
1
+ import sys
2
+
3
+ if sys.version_info >= (3, 11):
4
+ from typing import Never
5
+ else:
6
+ from typing_extensions import Never
7
+
8
+
9
+ from nnlogging.shell.protocol import ShellProtocol
10
+ from nnlogging.typings import BranchNotFoundError, LogOptions
11
+ from nnlogging.utils import get__debugging, get_name
12
+
13
+
14
+ def _branch_not_found_msg(
15
+ inst: ShellProtocol,
16
+ name: str,
17
+ /,
18
+ ):
19
+ return f'branch "{name}" not found in {get_name(inst)}.branches'
20
+
21
+
22
+ def _branch_not_found_error(
23
+ inst: ShellProtocol,
24
+ name: str,
25
+ /,
26
+ ):
27
+ return BranchNotFoundError(
28
+ f'branch "{name}" not found in {get_name(inst)}.branches: {inst.branches}'
29
+ )
30
+
31
+
32
+ def raise_branch_not_found_error(
33
+ inst: ShellProtocol,
34
+ name: str,
35
+ /,
36
+ *,
37
+ stacklevel: int = 1,
38
+ ) -> Never:
39
+ try:
40
+ raise _branch_not_found_error(inst, name)
41
+ except BranchNotFoundError as e:
42
+ inst.exception(
43
+ _branch_not_found_msg(inst, name),
44
+ log_options=LogOptions(
45
+ exc_info=e,
46
+ stack_info=get__debugging(inst),
47
+ stacklevel=stacklevel + 1,
48
+ ),
49
+ )
50
+ raise
@@ -0,0 +1,54 @@
1
+ import sys
2
+
3
+ if sys.version_info >= (3, 11):
4
+ from typing import Never
5
+ else:
6
+ from typing_extensions import Never
7
+
8
+ from nnlogging.shell.protocol import ShellProtocol
9
+ from nnlogging.typings import LogOptions, TaskExistsError
10
+ from nnlogging.utils import get__debugging, get_name
11
+
12
+
13
+ def _task_exists_msg(
14
+ inst: ShellProtocol,
15
+ branch: str,
16
+ name: str,
17
+ /,
18
+ ):
19
+ return (
20
+ f'task "{name}" already exists in {get_name(inst)}.branches."{branch}"."tasks"'
21
+ )
22
+
23
+
24
+ def _task_exists_error(
25
+ inst: ShellProtocol,
26
+ branch: str,
27
+ name: str,
28
+ /,
29
+ ):
30
+ return TaskExistsError(
31
+ f'task "{name}" already exists in {get_name(inst)}.branches."{branch}"."tasks": {inst.branches[branch]["tasks"]}'
32
+ )
33
+
34
+
35
+ def raise_task_exists_error(
36
+ inst: ShellProtocol,
37
+ branch: str,
38
+ name: str,
39
+ /,
40
+ *,
41
+ stacklevel: int = 1,
42
+ ) -> Never:
43
+ try:
44
+ raise _task_exists_error(inst, branch, name)
45
+ except TaskExistsError as e:
46
+ inst.exception(
47
+ _task_exists_msg(inst, branch, name),
48
+ log_options=LogOptions(
49
+ exc_info=e,
50
+ stack_info=get__debugging(inst),
51
+ stacklevel=stacklevel + 1,
52
+ ),
53
+ )
54
+ raise
@@ -0,0 +1,50 @@
1
+ import sys
2
+
3
+ if sys.version_info >= (3, 11):
4
+ from typing import Never
5
+ else:
6
+ from typing_extensions import Never
7
+
8
+
9
+ from nnlogging.shell.protocol import ShellProtocol
10
+ from nnlogging.typings import LogOptions, TaskNotFoundError
11
+ from nnlogging.utils import get__debugging, get_name
12
+
13
+
14
+ def _task_not_found_msg(
15
+ inst: ShellProtocol,
16
+ name: str,
17
+ /,
18
+ ):
19
+ return f'task "{name}" not found in {get_name(inst)}.branches'
20
+
21
+
22
+ def _task_not_found_error(
23
+ inst: ShellProtocol,
24
+ name: str,
25
+ /,
26
+ ):
27
+ return TaskNotFoundError(
28
+ f'task "{name}" not found in {get_name(inst)}.branches: {inst.branches}'
29
+ )
30
+
31
+
32
+ def raise_task_not_found_error(
33
+ inst: ShellProtocol,
34
+ name: str,
35
+ /,
36
+ *,
37
+ stacklevel: int = 1,
38
+ ) -> Never:
39
+ try:
40
+ raise _task_not_found_error(inst, name)
41
+ except TaskNotFoundError as e:
42
+ inst.exception(
43
+ _task_not_found_msg(inst, name),
44
+ log_options=LogOptions(
45
+ exc_info=e,
46
+ stack_info=get__debugging(inst),
47
+ stacklevel=stacklevel + 1,
48
+ ),
49
+ )
50
+ raise
@@ -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 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
+ ): ...