socx-cli 0.13.3__tar.gz → 0.13.5__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.
- {socx_cli-0.13.3 → socx_cli-0.13.5}/PKG-INFO +2 -1
- {socx_cli-0.13.3 → socx_cli-0.13.5}/pyproject.toml +2 -1
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/__init__.py +0 -8
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/cli/callbacks.py +8 -6
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/_paths.py +8 -2
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/paths.py +6 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/io/__init__.py +0 -8
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/io/log.py +163 -64
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/regression/__init__.py +0 -2
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/regression/progress.py +68 -66
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/regression/regression.py +145 -148
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/regression/test.py +38 -19
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/static/settings/cli.yaml +1 -1
- socx_cli-0.13.5/socx/static/settings/logging.yaml +23 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/static/settings/regression.yaml +4 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/static/settings/settings.yaml +2 -1
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/regression/callbacks.py +10 -2
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/regression/run.py +5 -2
- socx_cli-0.13.5/socx_plugins/regression/tui.py +30 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/app.py +7 -2
- socx_cli-0.13.5/socx_tui/regression/details.py +158 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/widget.py +62 -92
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/static/tcss/regression/app.tcss +3 -1
- socx_cli-0.13.3/socx_plugins/regression/tui.py +0 -11
- socx_cli-0.13.3/socx_tui/regression/details.py +0 -165
- {socx_cli-0.13.3 → socx_cli-0.13.5}/.gitignore +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/LICENSE +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/README.md +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/__main__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/cli/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/cli/_cli.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/cli/_jinja.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/cli/cfg.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/cli/cli.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/cli/params.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/cli/types.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/config/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/config/_config.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/config/_settings.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/config/converters.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/config/encoders.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/config/formatters.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/config/serializers.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/config/validators.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/encoder.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/enums.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/funcs.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/metadata.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/schema/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/schema/git/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/schema/git/git.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/schema/git/manifest.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/schema/plugin.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/schema/types.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/core/serializer.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/git/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/git/_git.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/git/_manifest.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/git/_ssh.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/io/console.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/io/decorators.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/patterns/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/patterns/mixins/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/patterns/mixins/proxy.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/patterns/mixins/uid.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/patterns/singleton/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/patterns/singleton/singleton.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/patterns/visitor/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/patterns/visitor/protocol.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/patterns/visitor/traversal.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/regression/status.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/regression/validator.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/regression/visitor.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/static/settings/console.yaml +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/static/settings/git.yaml +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/static/settings/plugins.yaml +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/static/settings/rich_click.yaml +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/static/sql/socx.sql +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/utils/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx/utils/decorators.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/config/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/config/_config.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/config/edit.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/git/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/git/arguments.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/git/callbacks.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/git/cli.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/git/manifest.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/git/renderables.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/git/summary.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/git/utils.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/plugin/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/plugin/example.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/plugin/schema.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/regression/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/regression/_run.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/regression/cli.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/version/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_plugins/version/__main__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/__main__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/bindings/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/bindings/vim/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/bindings/vim/mode.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/bindings/vim/vim.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/containers.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/dialog.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/mixins/__init__.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/mixins/composable.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/preview.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/table.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/regression/tree.py +0 -0
- {socx_cli-0.13.3 → socx_cli-0.13.5}/socx_tui/static/tcss/regression/preview.tcss +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: socx-cli
|
|
3
|
-
Version: 0.13.
|
|
3
|
+
Version: 0.13.5
|
|
4
4
|
Summary: System on chip verification and tooling infrastructure.
|
|
5
5
|
Project-URL: Issues, https://github.com/sagikimhi/socx-cli/issues
|
|
6
6
|
Project-URL: Homepage, https://sagikimhi.dev/socx-cli
|
|
@@ -31,6 +31,7 @@ Requires-Python: >=3.12
|
|
|
31
31
|
Requires-Dist: anyio>=4.12.1
|
|
32
32
|
Requires-Dist: click
|
|
33
33
|
Requires-Dist: copier~=9.11
|
|
34
|
+
Requires-Dist: declare
|
|
34
35
|
Requires-Dist: dynaconf<3.2.12
|
|
35
36
|
Requires-Dist: gitpython
|
|
36
37
|
Requires-Dist: hoptex
|
|
@@ -29,7 +29,7 @@ socx = 'socx.__main__:main'
|
|
|
29
29
|
[project]
|
|
30
30
|
name = "socx-cli"
|
|
31
31
|
readme = "README.md"
|
|
32
|
-
version = "0.13.
|
|
32
|
+
version = "0.13.5"
|
|
33
33
|
license = "Apache-2.0"
|
|
34
34
|
authors = [{ name = "Sagi Kimhi", email = "sagi.kim5@gmail.com" }]
|
|
35
35
|
maintainers = [{ name = "Sagi Kimhi", email = "sagi.kim5@gmail.com" }]
|
|
@@ -59,6 +59,7 @@ dependencies = [
|
|
|
59
59
|
"pip",
|
|
60
60
|
"rich",
|
|
61
61
|
"click",
|
|
62
|
+
"declare",
|
|
62
63
|
"typer~=0.19",
|
|
63
64
|
"jinja2",
|
|
64
65
|
"psutil",
|
|
@@ -47,7 +47,6 @@ __all__ = (
|
|
|
47
47
|
"DEFAULT_HANDLERS",
|
|
48
48
|
"DEFAULT_TIME_FORMAT",
|
|
49
49
|
"Level",
|
|
50
|
-
"log",
|
|
51
50
|
"log_it",
|
|
52
51
|
"logger",
|
|
53
52
|
"console",
|
|
@@ -135,7 +134,6 @@ __all__ = (
|
|
|
135
134
|
"Regression",
|
|
136
135
|
"TestStatus",
|
|
137
136
|
"TestResult",
|
|
138
|
-
"RegressionTree",
|
|
139
137
|
"RegressionProgress",
|
|
140
138
|
)
|
|
141
139
|
|
|
@@ -180,11 +178,6 @@ from socx.core import deduplicate as deduplicate
|
|
|
180
178
|
|
|
181
179
|
from socx.utils import join_decorators as join_decorators
|
|
182
180
|
|
|
183
|
-
from socx.io import log as log
|
|
184
|
-
from socx.io import DEFAULT_LEVEL as DEFAULT_LEVEL
|
|
185
|
-
from socx.io import DEFAULT_FORMAT as DEFAULT_FORMAT
|
|
186
|
-
from socx.io import DEFAULT_HANDLERS as DEFAULT_HANDLERS
|
|
187
|
-
from socx.io import DEFAULT_TIME_FORMAT as DEFAULT_TIME_FORMAT
|
|
188
181
|
from socx.io import Level as Level
|
|
189
182
|
from socx.io import log_it as log_it
|
|
190
183
|
from socx.io import logger as logger
|
|
@@ -264,7 +257,6 @@ from socx.regression import TestBase as TestBase
|
|
|
264
257
|
from socx.regression import Regression as Regression
|
|
265
258
|
from socx.regression import TestStatus as TestStatus
|
|
266
259
|
from socx.regression import TestResult as TestResult
|
|
267
|
-
from socx.regression import RegressionTree as RegressionTree
|
|
268
260
|
from socx.regression import RegressionProgress as RegressionProgress
|
|
269
261
|
|
|
270
262
|
from socx.cli import FuncType as FuncType
|
|
@@ -12,7 +12,7 @@ from rich_click import Context
|
|
|
12
12
|
from rich_click import Parameter
|
|
13
13
|
from rich_click import RichContext
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
from socx.io.log import Level, set_level, get_level, _get_logger
|
|
16
16
|
from socx.io.console import console
|
|
17
17
|
from socx.io.decorators import log_it
|
|
18
18
|
from socx.config._config import settings
|
|
@@ -45,10 +45,11 @@ def cwd_cb(ctx: Context, param: Parameter, value: Path) -> Path:
|
|
|
45
45
|
@log_it(logger=logger)
|
|
46
46
|
def debug_cb(_: Context, param: Parameter, value: bool) -> bool:
|
|
47
47
|
"""Enable debug logging and persist the CLI switch to settings."""
|
|
48
|
+
socx_logger = _get_logger()
|
|
48
49
|
settings.cli.params[param.name] = value
|
|
49
50
|
if value:
|
|
50
|
-
|
|
51
|
-
settings.cli.params["verbosity"] =
|
|
51
|
+
set_level(Level.DEBUG, socx_logger)
|
|
52
|
+
settings.cli.params["verbosity"] = get_level().name
|
|
52
53
|
return value
|
|
53
54
|
|
|
54
55
|
|
|
@@ -88,10 +89,11 @@ def configure_cb(ctx: Context, param: Parameter, value: str) -> str:
|
|
|
88
89
|
@log_it(logger=logger)
|
|
89
90
|
def verbosity_cb(_: Context, param: Parameter, value: str) -> str:
|
|
90
91
|
"""Update the global log level while respecting existing overrides."""
|
|
91
|
-
|
|
92
|
+
socx_logger = _get_logger()
|
|
93
|
+
level = Level[value.upper()]
|
|
92
94
|
if not settings.cli.params.debug:
|
|
93
|
-
|
|
94
|
-
settings.cli.params[param.name] =
|
|
95
|
+
set_level(level, socx_logger)
|
|
96
|
+
settings.cli.params[param.name] = get_level().name
|
|
95
97
|
return settings.cli.params[param.name]
|
|
96
98
|
|
|
97
99
|
|
|
@@ -109,8 +109,11 @@ USER_LOG_DIR: Path = user_log_path(
|
|
|
109
109
|
).resolve()
|
|
110
110
|
"""Absolute path to platform's native application logs directory."""
|
|
111
111
|
|
|
112
|
-
USER_LOG_FILENAME: str = f"{__appname__}.log"
|
|
113
|
-
"""File name of application's
|
|
112
|
+
USER_LOG_FILENAME: str = f"{__appname__}_log.log"
|
|
113
|
+
"""File name of application's log file."""
|
|
114
|
+
|
|
115
|
+
USER_ROTATING_LOG_FILENAME: str = f"rotating_{__appname__}_log.log"
|
|
116
|
+
"""File name of application's rotating log file."""
|
|
114
117
|
|
|
115
118
|
USER_CONFIG_FILENAME: str = f"{__appname__}.yaml"
|
|
116
119
|
"""File name searched in user's config directory to load user configs."""
|
|
@@ -118,6 +121,9 @@ USER_CONFIG_FILENAME: str = f"{__appname__}.yaml"
|
|
|
118
121
|
USER_LOG_FILE: Path = USER_LOG_DIR / USER_LOG_FILENAME
|
|
119
122
|
"""Absolute path to application's main log for the current local user."""
|
|
120
123
|
|
|
124
|
+
USER_ROTATING_LOG_FILE: Path = USER_LOG_DIR / USER_ROTATING_LOG_FILENAME
|
|
125
|
+
"""Absolute path to application's rotating log for the current local user."""
|
|
126
|
+
|
|
121
127
|
USER_CONFIG_FILE: Path = USER_CONFIG_DIR / USER_CONFIG_FILENAME
|
|
122
128
|
"""Absolute path to application's user config file."""
|
|
123
129
|
|
|
@@ -19,8 +19,10 @@ __all__ = (
|
|
|
19
19
|
"USER_RUNTIME_DIR",
|
|
20
20
|
"USER_LOG_FILENAME",
|
|
21
21
|
"USER_CONFIG_FILENAME",
|
|
22
|
+
"USER_ROTATING_LOG_FILENAME",
|
|
22
23
|
"USER_LOG_FILE",
|
|
23
24
|
"USER_CONFIG_FILE",
|
|
25
|
+
"USER_ROTATING_LOG_FILE",
|
|
24
26
|
# Local Paths
|
|
25
27
|
"LOCAL_CONFIG_FILENAME",
|
|
26
28
|
"LOCAL_CONFIG_FILE",
|
|
@@ -46,8 +48,12 @@ from socx.core._paths import USER_CONFIG_DIR as USER_CONFIG_DIR
|
|
|
46
48
|
from socx.core._paths import USER_RUNTIME_DIR as USER_RUNTIME_DIR
|
|
47
49
|
from socx.core._paths import USER_LOG_FILENAME as USER_LOG_FILENAME
|
|
48
50
|
from socx.core._paths import USER_CONFIG_FILENAME as USER_CONFIG_FILENAME
|
|
51
|
+
from socx.core._paths import (
|
|
52
|
+
USER_ROTATING_LOG_FILENAME as USER_ROTATING_LOG_FILENAME,
|
|
53
|
+
)
|
|
49
54
|
from socx.core._paths import USER_LOG_FILE as USER_LOG_FILE
|
|
50
55
|
from socx.core._paths import USER_CONFIG_FILE as USER_CONFIG_FILE
|
|
56
|
+
from socx.core._paths import USER_ROTATING_LOG_FILE as USER_ROTATING_LOG_FILE
|
|
51
57
|
|
|
52
58
|
# Local Paths
|
|
53
59
|
from socx.core._paths import LOCAL_CONFIG_FILE as LOCAL_CONFIG_FILE
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"""Expose logging, console, and decorator utilities for I/O facilities."""
|
|
2
2
|
|
|
3
3
|
__all__ = (
|
|
4
|
-
# Modules
|
|
5
|
-
"log",
|
|
6
4
|
# Constants
|
|
7
5
|
"DEFAULT_LEVEL",
|
|
8
6
|
"DEFAULT_FORMAT",
|
|
@@ -32,12 +30,6 @@ __all__ = (
|
|
|
32
30
|
"print_command_outputs",
|
|
33
31
|
)
|
|
34
32
|
|
|
35
|
-
from socx.io import log as log
|
|
36
|
-
|
|
37
|
-
from socx.io.log import DEFAULT_LEVEL as DEFAULT_LEVEL
|
|
38
|
-
from socx.io.log import DEFAULT_FORMAT as DEFAULT_FORMAT
|
|
39
|
-
from socx.io.log import DEFAULT_HANDLERS as DEFAULT_HANDLERS
|
|
40
|
-
from socx.io.log import DEFAULT_TIME_FORMAT as DEFAULT_TIME_FORMAT
|
|
41
33
|
from socx.io.log import Level as Level
|
|
42
34
|
from socx.io.log import logger as logger
|
|
43
35
|
from socx.io.log import get_level as get_level
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
"""Logging helpers that standardise Rich-powered output across SoCX."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
+
from types import ModuleType
|
|
4
5
|
|
|
5
|
-
import os
|
|
6
6
|
import enum
|
|
7
7
|
import logging
|
|
8
8
|
import logging.handlers
|
|
9
|
-
from typing import Any
|
|
9
|
+
from typing import Any, IO
|
|
10
10
|
from pathlib import Path
|
|
11
11
|
from collections import ChainMap
|
|
12
12
|
from collections.abc import Iterable
|
|
13
13
|
|
|
14
14
|
from rich.console import Console
|
|
15
15
|
from rich.logging import RichHandler
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
from socx.config._config import settings
|
|
18
|
+
from socx.core.metadata import __appname__
|
|
17
19
|
|
|
18
20
|
__all__ = (
|
|
19
21
|
# Logging
|
|
@@ -39,10 +41,7 @@ __all__ = (
|
|
|
39
41
|
# Types
|
|
40
42
|
"Level",
|
|
41
43
|
# Defaults
|
|
42
|
-
"DEFAULT_LEVEL",
|
|
43
|
-
"DEFAULT_FORMAT",
|
|
44
44
|
"DEFAULT_HANDLERS",
|
|
45
|
-
"DEFAULT_TIME_FORMAT",
|
|
46
45
|
)
|
|
47
46
|
|
|
48
47
|
|
|
@@ -59,97 +58,194 @@ class Level(enum.IntEnum):
|
|
|
59
58
|
CRITICAL = logging.CRITICAL
|
|
60
59
|
|
|
61
60
|
|
|
62
|
-
def
|
|
61
|
+
def _get_console(
|
|
62
|
+
file: IO | None = None,
|
|
63
|
+
stderr: bool = False,
|
|
64
|
+
markup: bool = True,
|
|
65
|
+
tab_size: int = 4,
|
|
66
|
+
force_terminal: bool = True,
|
|
67
|
+
**kwargs: Any,
|
|
68
|
+
) -> Console:
|
|
69
|
+
defaults = dict(
|
|
70
|
+
file=file,
|
|
71
|
+
markup=markup,
|
|
72
|
+
stderr=stderr,
|
|
73
|
+
tab_size=tab_size,
|
|
74
|
+
force_terminal=force_terminal,
|
|
75
|
+
)
|
|
76
|
+
kwargs = dict(ChainMap(kwargs, defaults))
|
|
77
|
+
return Console(**kwargs)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _get_level(level: str | int | Level) -> Level:
|
|
81
|
+
if isinstance(level, str):
|
|
82
|
+
level = Level[level]
|
|
83
|
+
elif isinstance(level, int):
|
|
84
|
+
level = Level(level)
|
|
85
|
+
return level
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _get_console_handler(
|
|
89
|
+
file: IO | None = None,
|
|
90
|
+
level: int | str | Level = Level.INFO,
|
|
91
|
+
stderr: bool = False,
|
|
92
|
+
tab_size: int = 4,
|
|
93
|
+
tracebacks: bool = True,
|
|
94
|
+
force_terminal: bool = True,
|
|
95
|
+
tracebacks_theme: str | None = None,
|
|
96
|
+
tracebacks_suppress: Iterable[ModuleType] | None = None,
|
|
97
|
+
tracebacks_show_locals: bool = True,
|
|
98
|
+
) -> logging.Handler:
|
|
63
99
|
"""Create a Rich console handler configured for interactive output."""
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
100
|
+
import click
|
|
101
|
+
import rich_click
|
|
102
|
+
from socx.io.console import console as _console
|
|
103
|
+
|
|
104
|
+
level = _get_level(level)
|
|
105
|
+
tracebacks_theme = tracebacks_theme or "ansi_dark"
|
|
106
|
+
tracebacks_suppress = tracebacks_suppress or [click, rich_click]
|
|
107
|
+
if file is None and stderr is None:
|
|
108
|
+
console = _console
|
|
109
|
+
else:
|
|
110
|
+
console = _get_console(
|
|
111
|
+
file=file,
|
|
112
|
+
stderr=stderr,
|
|
113
|
+
tab_size=tab_size,
|
|
114
|
+
force_terminal=force_terminal,
|
|
115
|
+
)
|
|
116
|
+
handler = RichHandler(
|
|
67
117
|
console=console,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
118
|
+
rich_tracebacks=tracebacks,
|
|
119
|
+
tracebacks_theme=tracebacks_theme,
|
|
120
|
+
tracebacks_suppress=tracebacks_suppress,
|
|
121
|
+
tracebacks_show_locals=tracebacks_show_locals,
|
|
71
122
|
)
|
|
123
|
+
formatter = logging.Formatter(**settings.logging.formatters.default)
|
|
124
|
+
handler.name = "console"
|
|
125
|
+
handler.setLevel(level)
|
|
126
|
+
handler.setFormatter(formatter)
|
|
127
|
+
return handler
|
|
72
128
|
|
|
73
129
|
|
|
74
130
|
def _get_file_handler(
|
|
75
|
-
path: str | Path,
|
|
131
|
+
path: str | Path,
|
|
132
|
+
mode: str | None = None,
|
|
133
|
+
level: Level = Level.INFO,
|
|
134
|
+
stderr: bool = False,
|
|
135
|
+
tab_size: int = 4,
|
|
136
|
+
tracebacks: bool = True,
|
|
137
|
+
force_terminal: bool = False,
|
|
138
|
+
tracebacks_theme: str | None = None,
|
|
139
|
+
tracebacks_suppress: Iterable[ModuleType] | None = None,
|
|
140
|
+
tracebacks_show_locals: bool = True,
|
|
141
|
+
) -> logging.Handler:
|
|
142
|
+
import atexit
|
|
143
|
+
|
|
144
|
+
def close_if_open(file: IO) -> None:
|
|
145
|
+
if not file.closed:
|
|
146
|
+
file.close()
|
|
147
|
+
|
|
148
|
+
mode = mode or "a"
|
|
149
|
+
file = open(path, mode=mode) # noqa: SIM115
|
|
150
|
+
atexit.register(close_if_open, file)
|
|
151
|
+
handler = _get_console_handler(
|
|
152
|
+
file=file,
|
|
153
|
+
level=level,
|
|
154
|
+
stderr=stderr,
|
|
155
|
+
tab_size=tab_size,
|
|
156
|
+
tracebacks=tracebacks,
|
|
157
|
+
force_terminal=force_terminal,
|
|
158
|
+
tracebacks_theme=tracebacks_theme,
|
|
159
|
+
tracebacks_suppress=tracebacks_suppress,
|
|
160
|
+
tracebacks_show_locals=tracebacks_show_locals,
|
|
161
|
+
)
|
|
162
|
+
handler.name = "file"
|
|
163
|
+
handler.setFormatter(DEFAULT_CHILD_FORMATTER)
|
|
164
|
+
return handler
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _get_rotating_file_handler(
|
|
168
|
+
path: str | Path,
|
|
169
|
+
level: Level = Level.DEBUG,
|
|
170
|
+
stderr: bool = False,
|
|
171
|
+
mode: str | None = None,
|
|
76
172
|
) -> logging.Handler:
|
|
77
173
|
"""Create a Rich handler that writes log output to ``path``."""
|
|
174
|
+
|
|
175
|
+
def MBs(n: int) -> int: # noqa: N802
|
|
176
|
+
return 1024 * 1024 * n
|
|
177
|
+
|
|
178
|
+
mode = mode or "w"
|
|
78
179
|
handler = logging.handlers.RotatingFileHandler(
|
|
79
|
-
path,
|
|
180
|
+
path,
|
|
181
|
+
mode=mode,
|
|
182
|
+
maxBytes=MBs(10),
|
|
183
|
+
backupCount=5,
|
|
80
184
|
)
|
|
185
|
+
handler.name = "rotating_file"
|
|
81
186
|
handler.setLevel(level)
|
|
82
|
-
handler.setFormatter(
|
|
83
|
-
logging.Formatter(DEFAULT_CHILD_FORMAT, DEFAULT_TIME_FORMAT)
|
|
84
|
-
)
|
|
187
|
+
handler.setFormatter(DEFAULT_CHILD_FORMATTER)
|
|
85
188
|
return handler
|
|
86
189
|
|
|
87
190
|
|
|
88
|
-
|
|
89
|
-
|
|
191
|
+
def _get_handler(handler: str) -> logging.Handler | None:
|
|
192
|
+
match handler:
|
|
193
|
+
case "file":
|
|
194
|
+
return _get_file_handler(**settings.logging.handlers.file)
|
|
195
|
+
case "console":
|
|
196
|
+
return _get_console_handler(**settings.logging.handlers.console)
|
|
197
|
+
case "rotating_file":
|
|
198
|
+
return _get_rotating_file_handler(
|
|
199
|
+
**settings.logging.handlers.rotating_file
|
|
200
|
+
)
|
|
201
|
+
case _:
|
|
202
|
+
return None
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def _get_logger() -> logging.Logger:
|
|
206
|
+
"""Initialise and return the module-level root logger."""
|
|
207
|
+
socx_logger = logging.getLogger(__appname__)
|
|
208
|
+
|
|
209
|
+
if not socx_logger.hasHandlers():
|
|
210
|
+
unknown_handlers = []
|
|
90
211
|
|
|
91
|
-
|
|
92
|
-
|
|
212
|
+
for handler_name in settings.logging.handlers:
|
|
213
|
+
handler = _get_handler(handler_name)
|
|
214
|
+
if handler is not None:
|
|
215
|
+
socx_logger.addHandler(handler)
|
|
216
|
+
else:
|
|
217
|
+
unknown_handlers.append(handler_name)
|
|
93
218
|
|
|
94
|
-
|
|
95
|
-
"
|
|
219
|
+
for handler in unknown_handlers:
|
|
220
|
+
msg = f"Ignored unknown handler configuration: '{handler}'"
|
|
221
|
+
socx_logger.warning(msg)
|
|
96
222
|
|
|
97
|
-
|
|
98
|
-
"""Default log message format used by the root handler."""
|
|
223
|
+
return socx_logger
|
|
99
224
|
|
|
100
|
-
DEFAULT_TIME_FORMAT: str = os.environ.get("SOCX_TIME_FORMAT", "[%x %X]")
|
|
101
|
-
"""Default timestamp format injected into log records."""
|
|
102
225
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
"%(asctime)s %(levelname)5s - %(filename)5s:%(lineno)-4d - %(message)s",
|
|
226
|
+
DEFAULT_FORMATTER: logging.Formatter = logging.Formatter(
|
|
227
|
+
**settings.logging.formatters.default
|
|
106
228
|
)
|
|
107
|
-
"""
|
|
229
|
+
"""Default application logging formatter."""
|
|
108
230
|
|
|
109
231
|
DEFAULT_CHILD_FORMATTER: logging.Formatter = logging.Formatter(
|
|
110
|
-
|
|
232
|
+
**settings.logging.formatters.child
|
|
111
233
|
)
|
|
112
234
|
"""Formatter applied to file handlers registered on child loggers."""
|
|
113
235
|
|
|
114
|
-
DEFAULT_LOG_DIRECTORY: Path = Path(
|
|
115
|
-
os.environ.get(
|
|
116
|
-
"SOCX_LOG_DIR",
|
|
117
|
-
user_log_path(appname=APP_LIB_NAME, ensure_exists=True),
|
|
118
|
-
)
|
|
119
|
-
)
|
|
120
|
-
"""Default application log directory."""
|
|
121
|
-
|
|
122
|
-
DEFAULT_LOG_FILE: str = os.environ.get("SOCX_LOG_FILE", f"{APP_LIB_NAME}.log")
|
|
123
|
-
"""Default application log file."""
|
|
124
|
-
|
|
125
236
|
DEFAULT_HANDLERS: list[logging.Handler] = [
|
|
126
|
-
|
|
127
|
-
|
|
237
|
+
_get_file_handler(**settings.logging.handlers.file),
|
|
238
|
+
_get_console_handler(**settings.logging.handlers.console),
|
|
239
|
+
_get_rotating_file_handler(**settings.logging.handlers.rotating_file),
|
|
128
240
|
]
|
|
129
241
|
"""Handlers attached to the module-level logger by default."""
|
|
130
242
|
|
|
131
|
-
DEFAULT_LOGGING_CONFIG: dict[str, Any] = dict(
|
|
132
|
-
level=DEFAULT_LEVEL,
|
|
133
|
-
format=DEFAULT_FORMAT,
|
|
134
|
-
handlers=DEFAULT_HANDLERS,
|
|
135
|
-
encoding=DEFAULT_ENCODING,
|
|
136
|
-
datefmt=DEFAULT_TIME_FORMAT,
|
|
137
|
-
)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
def _get_logger(**kwargs: Any) -> logging.Logger:
|
|
141
|
-
"""Initialise and return the module-level root logger."""
|
|
142
|
-
logging.basicConfig(**dict(ChainMap(kwargs, DEFAULT_LOGGING_CONFIG)))
|
|
143
|
-
return logging.getLogger(APP_LIB_NAME)
|
|
144
|
-
|
|
145
243
|
|
|
146
244
|
def get_logger(name: str, filename: str | None = None) -> logging.Logger:
|
|
147
245
|
"""Return a child logger configured with optional file output."""
|
|
148
246
|
rv = logger.getChild(name)
|
|
149
247
|
if filename is not None:
|
|
150
|
-
|
|
151
|
-
handler.setFormatter(DEFAULT_CHILD_FORMATTER)
|
|
152
|
-
rv.addHandler(handler)
|
|
248
|
+
rv.addHandler(_get_file_handler(filename))
|
|
153
249
|
return rv
|
|
154
250
|
|
|
155
251
|
|
|
@@ -243,8 +339,11 @@ def get_level(logger_: logging.Logger | None = None) -> Level:
|
|
|
243
339
|
|
|
244
340
|
|
|
245
341
|
def set_level(level: Level, logger_: logging.Logger | None = None) -> None:
|
|
246
|
-
"""Set the log level on
|
|
342
|
+
"""Set the log level on ``logger_`` and all currently attached handlers."""
|
|
247
343
|
logger_ = logger_ or logger
|
|
344
|
+
level = level if isinstance(level, str | int) else level.value
|
|
345
|
+
for handler in logger_.handlers:
|
|
346
|
+
handler.setLevel(level)
|
|
248
347
|
logger_.setLevel(level)
|
|
249
348
|
|
|
250
349
|
|
|
@@ -6,7 +6,6 @@ __all__ = (
|
|
|
6
6
|
"TestStatus",
|
|
7
7
|
"TestResult",
|
|
8
8
|
"Regression",
|
|
9
|
-
"RegressionTree",
|
|
10
9
|
"RegressionProgress",
|
|
11
10
|
)
|
|
12
11
|
|
|
@@ -15,5 +14,4 @@ from socx.regression.test import TestBase as TestBase
|
|
|
15
14
|
from socx.regression.test import TestStatus as TestStatus
|
|
16
15
|
from socx.regression.test import TestResult as TestResult
|
|
17
16
|
from socx.regression.regression import Regression as Regression
|
|
18
|
-
from socx.regression.regression import RegressionTree as RegressionTree
|
|
19
17
|
from socx.regression.progress import RegressionProgress as RegressionProgress
|