cocotb 1.9.2__cp38-cp38-win32.whl → 2.0.0b1__cp38-cp38-win32.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 cocotb might be problematic. Click here for more details.
- cocotb/{ANSI.py → _ANSI.py} +5 -25
- cocotb/__init__.py +76 -332
- cocotb/_base_triggers.py +513 -0
- cocotb/_bridge.py +187 -0
- cocotb/_decorators.py +515 -0
- cocotb/_deprecation.py +3 -3
- cocotb/_exceptions.py +7 -0
- cocotb/_extended_awaitables.py +419 -0
- cocotb/_gpi_triggers.py +382 -0
- cocotb/_init.py +295 -0
- cocotb/_outcomes.py +54 -0
- cocotb/_profiling.py +46 -0
- cocotb/_py_compat.py +100 -29
- cocotb/_scheduler.py +454 -0
- cocotb/_test.py +245 -0
- cocotb/_test_factory.py +309 -0
- cocotb/_test_functions.py +42 -0
- cocotb/_typing.py +7 -0
- cocotb/_utils.py +296 -0
- cocotb/_version.py +3 -7
- cocotb/_xunit_reporter.py +66 -0
- cocotb/clock.py +271 -108
- cocotb/handle.py +1342 -795
- cocotb/libs/cocotb.dll +0 -0
- cocotb/libs/cocotb.exp +0 -0
- cocotb/libs/cocotb.lib +0 -0
- cocotb/libs/cocotbfli_modelsim.dll +0 -0
- cocotb/libs/cocotbfli_modelsim.exp +0 -0
- cocotb/libs/cocotbfli_modelsim.lib +0 -0
- cocotb/libs/cocotbutils.dll +0 -0
- cocotb/libs/cocotbutils.exp +0 -0
- cocotb/libs/cocotbutils.lib +0 -0
- cocotb/libs/cocotbvhpi_aldec.dll +0 -0
- cocotb/libs/cocotbvhpi_aldec.exp +0 -0
- cocotb/libs/cocotbvhpi_aldec.lib +0 -0
- cocotb/libs/cocotbvhpi_modelsim.dll +0 -0
- cocotb/libs/cocotbvhpi_modelsim.exp +0 -0
- cocotb/libs/cocotbvhpi_modelsim.lib +0 -0
- cocotb/libs/cocotbvpi_aldec.dll +0 -0
- cocotb/libs/cocotbvpi_aldec.exp +0 -0
- cocotb/libs/cocotbvpi_aldec.lib +0 -0
- cocotb/libs/cocotbvpi_ghdl.dll +0 -0
- cocotb/libs/cocotbvpi_ghdl.exp +0 -0
- cocotb/libs/cocotbvpi_ghdl.lib +0 -0
- cocotb/libs/cocotbvpi_icarus.exp +0 -0
- cocotb/libs/cocotbvpi_icarus.lib +0 -0
- cocotb/libs/cocotbvpi_icarus.vpl +0 -0
- cocotb/libs/cocotbvpi_modelsim.dll +0 -0
- cocotb/libs/cocotbvpi_modelsim.exp +0 -0
- cocotb/libs/cocotbvpi_modelsim.lib +0 -0
- cocotb/libs/embed.dll +0 -0
- cocotb/libs/embed.exp +0 -0
- cocotb/libs/embed.lib +0 -0
- cocotb/libs/gpi.dll +0 -0
- cocotb/libs/gpi.exp +0 -0
- cocotb/libs/gpi.lib +0 -0
- cocotb/libs/gpilog.dll +0 -0
- cocotb/libs/gpilog.exp +0 -0
- cocotb/libs/gpilog.lib +0 -0
- cocotb/libs/pygpilog.dll +0 -0
- cocotb/libs/pygpilog.exp +0 -0
- cocotb/libs/pygpilog.lib +0 -0
- cocotb/{log.py → logging.py} +105 -110
- cocotb/queue.py +103 -57
- cocotb/regression.py +667 -712
- cocotb/result.py +17 -188
- cocotb/share/def/aldec.exp +0 -0
- cocotb/share/def/aldec.lib +0 -0
- cocotb/share/def/ghdl.exp +0 -0
- cocotb/share/def/ghdl.lib +0 -0
- cocotb/share/def/icarus.exp +0 -0
- cocotb/share/def/icarus.lib +0 -0
- cocotb/share/def/modelsim.def +1 -0
- cocotb/share/def/modelsim.exp +0 -0
- cocotb/share/def/modelsim.lib +0 -0
- cocotb/share/include/cocotb_utils.h +6 -29
- cocotb/share/include/embed.h +5 -28
- cocotb/share/include/gpi.h +137 -92
- cocotb/share/include/gpi_logging.h +221 -142
- cocotb/share/include/py_gpi_logging.h +7 -4
- cocotb/share/include/vpi_user_ext.h +4 -26
- cocotb/share/lib/verilator/verilator.cpp +59 -54
- cocotb/simulator.cp38-win32.exp +0 -0
- cocotb/simulator.cp38-win32.lib +0 -0
- cocotb/simulator.cp38-win32.pyd +0 -0
- cocotb/simulator.pyi +107 -0
- cocotb/task.py +434 -212
- cocotb/triggers.py +55 -1092
- cocotb/types/__init__.py +25 -47
- cocotb/types/_abstract_array.py +151 -0
- cocotb/types/_array.py +264 -0
- cocotb/types/_logic.py +296 -0
- cocotb/types/_logic_array.py +834 -0
- cocotb/types/{range.py → _range.py} +36 -44
- cocotb/types/_resolve.py +76 -0
- cocotb/utils.py +119 -587
- cocotb-2.0.0b1.dist-info/METADATA +46 -0
- cocotb-2.0.0b1.dist-info/RECORD +143 -0
- {cocotb-1.9.2.dist-info → cocotb-2.0.0b1.dist-info}/WHEEL +1 -1
- cocotb-2.0.0b1.dist-info/entry_points.txt +2 -0
- {cocotb-1.9.2.dist-info → cocotb-2.0.0b1.dist-info}/top_level.txt +1 -0
- cocotb_tools/__init__.py +0 -0
- cocotb_tools/_coverage.py +33 -0
- cocotb_tools/_vendor/__init__.py +3 -0
- cocotb_tools/check_results.py +65 -0
- cocotb_tools/combine_results.py +152 -0
- cocotb_tools/config.py +241 -0
- {cocotb → cocotb_tools}/ipython_support.py +29 -22
- cocotb_tools/makefiles/Makefile.deprecations +27 -0
- {cocotb/share → cocotb_tools}/makefiles/Makefile.inc +82 -54
- {cocotb/share → cocotb_tools}/makefiles/Makefile.sim +8 -33
- {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.activehdl +9 -16
- cocotb_tools/makefiles/simulators/Makefile.cvc +61 -0
- cocotb_tools/makefiles/simulators/Makefile.dsim +39 -0
- {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.ghdl +13 -42
- cocotb_tools/makefiles/simulators/Makefile.icarus +80 -0
- cocotb_tools/makefiles/simulators/Makefile.ius +93 -0
- cocotb_tools/makefiles/simulators/Makefile.modelsim +9 -0
- cocotb_tools/makefiles/simulators/Makefile.nvc +60 -0
- cocotb_tools/makefiles/simulators/Makefile.questa +29 -0
- cocotb/share/makefiles/simulators/Makefile.questa → cocotb_tools/makefiles/simulators/Makefile.questa-compat +26 -54
- cocotb_tools/makefiles/simulators/Makefile.questa-qisqrun +149 -0
- {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.riviera +17 -56
- cocotb_tools/makefiles/simulators/Makefile.vcs +65 -0
- {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.verilator +15 -22
- {cocotb/share → cocotb_tools}/makefiles/simulators/Makefile.xcelium +20 -52
- cocotb_tools/py.typed +0 -0
- {cocotb → cocotb_tools}/runner.py +794 -361
- cocotb/_sim_versions.py → cocotb_tools/sim_versions.py +16 -21
- pygpi/entry.py +34 -17
- pygpi/py.typed +0 -0
- cocotb/binary.py +0 -858
- cocotb/config.py +0 -289
- cocotb/decorators.py +0 -332
- cocotb/memdebug.py +0 -35
- cocotb/outcomes.py +0 -56
- cocotb/scheduler.py +0 -1099
- cocotb/share/makefiles/Makefile.deprecations +0 -12
- cocotb/share/makefiles/simulators/Makefile.cvc +0 -94
- cocotb/share/makefiles/simulators/Makefile.icarus +0 -111
- cocotb/share/makefiles/simulators/Makefile.ius +0 -125
- cocotb/share/makefiles/simulators/Makefile.modelsim +0 -32
- cocotb/share/makefiles/simulators/Makefile.nvc +0 -64
- cocotb/share/makefiles/simulators/Makefile.vcs +0 -98
- cocotb/types/array.py +0 -309
- cocotb/types/logic.py +0 -292
- cocotb/types/logic_array.py +0 -298
- cocotb/wavedrom.py +0 -199
- cocotb/xunit_reporter.py +0 -80
- cocotb-1.9.2.dist-info/METADATA +0 -168
- cocotb-1.9.2.dist-info/RECORD +0 -121
- cocotb-1.9.2.dist-info/entry_points.txt +0 -2
- /cocotb/{_vendor/__init__.py → py.typed} +0 -0
- {cocotb-1.9.2.dist-info → cocotb-2.0.0b1.dist-info}/LICENSE +0 -0
- {cocotb → cocotb_tools}/_vendor/distutils_version.py +0 -0
cocotb/libs/cocotb.dll
CHANGED
|
Binary file
|
cocotb/libs/cocotb.exp
CHANGED
|
Binary file
|
cocotb/libs/cocotb.lib
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
cocotb/libs/cocotbutils.dll
CHANGED
|
Binary file
|
cocotb/libs/cocotbutils.exp
CHANGED
|
Binary file
|
cocotb/libs/cocotbutils.lib
CHANGED
|
Binary file
|
cocotb/libs/cocotbvhpi_aldec.dll
CHANGED
|
Binary file
|
cocotb/libs/cocotbvhpi_aldec.exp
CHANGED
|
Binary file
|
cocotb/libs/cocotbvhpi_aldec.lib
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
cocotb/libs/cocotbvpi_aldec.dll
CHANGED
|
Binary file
|
cocotb/libs/cocotbvpi_aldec.exp
CHANGED
|
Binary file
|
cocotb/libs/cocotbvpi_aldec.lib
CHANGED
|
Binary file
|
cocotb/libs/cocotbvpi_ghdl.dll
CHANGED
|
Binary file
|
cocotb/libs/cocotbvpi_ghdl.exp
CHANGED
|
Binary file
|
cocotb/libs/cocotbvpi_ghdl.lib
CHANGED
|
Binary file
|
cocotb/libs/cocotbvpi_icarus.exp
CHANGED
|
Binary file
|
cocotb/libs/cocotbvpi_icarus.lib
CHANGED
|
Binary file
|
cocotb/libs/cocotbvpi_icarus.vpl
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
cocotb/libs/embed.dll
CHANGED
|
Binary file
|
cocotb/libs/embed.exp
CHANGED
|
Binary file
|
cocotb/libs/embed.lib
CHANGED
|
Binary file
|
cocotb/libs/gpi.dll
CHANGED
|
Binary file
|
cocotb/libs/gpi.exp
CHANGED
|
Binary file
|
cocotb/libs/gpi.lib
CHANGED
|
Binary file
|
cocotb/libs/gpilog.dll
CHANGED
|
Binary file
|
cocotb/libs/gpilog.exp
CHANGED
|
Binary file
|
cocotb/libs/gpilog.lib
CHANGED
|
Binary file
|
cocotb/libs/pygpilog.dll
CHANGED
|
Binary file
|
cocotb/libs/pygpilog.exp
CHANGED
|
Binary file
|
cocotb/libs/pygpilog.lib
CHANGED
|
Binary file
|
cocotb/{log.py → logging.py}
RENAMED
|
@@ -1,29 +1,8 @@
|
|
|
1
|
+
# Copyright cocotb contributors
|
|
1
2
|
# Copyright (c) 2013, 2018 Potential Ventures Ltd
|
|
2
3
|
# Copyright (c) 2013 SolarFlare Communications Inc
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
# Redistribution and use in source and binary forms, with or without
|
|
6
|
-
# modification, are permitted provided that the following conditions are met:
|
|
7
|
-
# * Redistributions of source code must retain the above copyright
|
|
8
|
-
# notice, this list of conditions and the following disclaimer.
|
|
9
|
-
# * Redistributions in binary form must reproduce the above copyright
|
|
10
|
-
# notice, this list of conditions and the following disclaimer in the
|
|
11
|
-
# documentation and/or other materials provided with the distribution.
|
|
12
|
-
# * Neither the name of Potential Ventures Ltd,
|
|
13
|
-
# SolarFlare Communications Inc nor the
|
|
14
|
-
# names of its contributors may be used to endorse or promote products
|
|
15
|
-
# derived from this software without specific prior written permission.
|
|
16
|
-
#
|
|
17
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
18
|
-
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19
|
-
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
-
# DISCLAIMED. IN NO EVENT SHALL POTENTIAL VENTURES LTD BE LIABLE FOR ANY
|
|
21
|
-
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
22
|
-
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
23
|
-
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
24
|
-
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
-
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
-
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4
|
+
# Licensed under the Revised BSD License, see LICENSE for details.
|
|
5
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
27
6
|
|
|
28
7
|
"""
|
|
29
8
|
Everything related to logging
|
|
@@ -32,12 +11,14 @@ Everything related to logging
|
|
|
32
11
|
import logging
|
|
33
12
|
import os
|
|
34
13
|
import sys
|
|
35
|
-
import
|
|
36
|
-
import
|
|
14
|
+
from functools import wraps
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Union
|
|
37
17
|
|
|
38
|
-
|
|
39
|
-
from cocotb import
|
|
40
|
-
from cocotb.
|
|
18
|
+
from cocotb import _ANSI, simulator
|
|
19
|
+
from cocotb._deprecation import deprecated
|
|
20
|
+
from cocotb._utils import want_color_output
|
|
21
|
+
from cocotb.utils import get_sim_time, get_time_from_sim_steps
|
|
41
22
|
|
|
42
23
|
try:
|
|
43
24
|
_suppress = int(os.environ.get("COCOTB_REDUCED_LOG_FMT", "1"))
|
|
@@ -52,14 +33,20 @@ _LINENO_CHARS = 4
|
|
|
52
33
|
_FUNCNAME_CHARS = 31
|
|
53
34
|
|
|
54
35
|
# Custom log level
|
|
55
|
-
logging.TRACE = 5
|
|
36
|
+
logging.TRACE = 5 # type: ignore[attr-defined] # type checkers don't like adding module attributes after the fact
|
|
56
37
|
logging.addLevelName(5, "TRACE")
|
|
57
38
|
|
|
58
|
-
# Default log level if not overwritten by the user.
|
|
59
|
-
_COCOTB_LOG_LEVEL_DEFAULT = "INFO"
|
|
60
39
|
|
|
40
|
+
__all__ = (
|
|
41
|
+
"SimColourLogFormatter",
|
|
42
|
+
"SimLog",
|
|
43
|
+
"SimLogFormatter",
|
|
44
|
+
"SimTimeContextFilter",
|
|
45
|
+
"default_config",
|
|
46
|
+
)
|
|
61
47
|
|
|
62
|
-
|
|
48
|
+
|
|
49
|
+
def default_config() -> None:
|
|
63
50
|
"""Apply the default cocotb log formatting to the root logger.
|
|
64
51
|
|
|
65
52
|
This hooks up the logger to write to stdout, using either
|
|
@@ -68,17 +55,16 @@ def default_config():
|
|
|
68
55
|
:class:`SimTimeContextFilter` filter so that
|
|
69
56
|
:attr:`~logging.LogRecord.created_sim_time` is available to the formatter.
|
|
70
57
|
|
|
71
|
-
The logging level for cocotb logs is set based on the
|
|
72
|
-
:envvar:`COCOTB_LOG_LEVEL` environment variable, which defaults to ``INFO``.
|
|
73
|
-
|
|
74
58
|
If desired, this logging configuration can be overwritten by calling
|
|
75
59
|
``logging.basicConfig(..., force=True)`` (in Python 3.8 onwards), or by
|
|
76
60
|
manually resetting the root logger instance.
|
|
77
61
|
An example of this can be found in the section on :ref:`rotating-logger`.
|
|
78
62
|
|
|
79
63
|
.. versionadded:: 1.4
|
|
64
|
+
|
|
65
|
+
.. versionchanged:: 2.0
|
|
66
|
+
No longer set the log level of the ``cocotb`` and ``gpi`` loggers.
|
|
80
67
|
"""
|
|
81
|
-
# construct an appropriate handler
|
|
82
68
|
hdlr = logging.StreamHandler(sys.stdout)
|
|
83
69
|
hdlr.addFilter(SimTimeContextFilter())
|
|
84
70
|
if want_color_output():
|
|
@@ -86,66 +72,71 @@ def default_config():
|
|
|
86
72
|
else:
|
|
87
73
|
hdlr.setFormatter(SimLogFormatter())
|
|
88
74
|
|
|
89
|
-
logging.setLoggerClass(SimBaseLog) # For backwards compatibility
|
|
90
75
|
logging.basicConfig()
|
|
91
76
|
logging.getLogger().handlers = [hdlr] # overwrite default handlers
|
|
92
77
|
|
|
93
|
-
# apply level settings for cocotb
|
|
94
|
-
log = logging.getLogger("cocotb")
|
|
95
|
-
|
|
96
|
-
try:
|
|
97
|
-
# All log levels are upper case, convert the user input for convenience.
|
|
98
|
-
level = os.environ["COCOTB_LOG_LEVEL"].upper()
|
|
99
|
-
except KeyError:
|
|
100
|
-
level = _COCOTB_LOG_LEVEL_DEFAULT
|
|
101
|
-
|
|
102
|
-
try:
|
|
103
|
-
log.setLevel(level)
|
|
104
|
-
except ValueError:
|
|
105
|
-
valid_levels = ("CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE")
|
|
106
|
-
raise ValueError(
|
|
107
|
-
"Invalid log level %r passed through the "
|
|
108
|
-
"COCOTB_LOG_LEVEL environment variable. Valid log "
|
|
109
|
-
"levels: %s" % (level, ", ".join(valid_levels))
|
|
110
|
-
)
|
|
111
78
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
logging.getLogger("gpi").setLevel(level)
|
|
79
|
+
def _init(_: object) -> None:
|
|
80
|
+
"""Set cocotb and pygpi log levels."""
|
|
115
81
|
|
|
82
|
+
# Monkeypatch "gpi" logger with function that also sets a PyGPI-local logger level
|
|
83
|
+
# as an optimization.
|
|
84
|
+
gpi_logger = logging.getLogger("gpi")
|
|
85
|
+
old_setLevel = gpi_logger.setLevel
|
|
116
86
|
|
|
117
|
-
|
|
118
|
-
|
|
87
|
+
@wraps(old_setLevel)
|
|
88
|
+
def setLevel(level: Union[int, str]) -> None:
|
|
89
|
+
old_setLevel(level)
|
|
90
|
+
simulator.set_gpi_log_level(gpi_logger.getEffectiveLevel())
|
|
119
91
|
|
|
120
|
-
|
|
121
|
-
def logger(self):
|
|
122
|
-
warnings.warn(
|
|
123
|
-
"the .logger attribute should not be used now that `SimLog` "
|
|
124
|
-
"returns a native logger instance directly.",
|
|
125
|
-
DeprecationWarning,
|
|
126
|
-
stacklevel=2,
|
|
127
|
-
)
|
|
128
|
-
return self
|
|
129
|
-
|
|
130
|
-
@property
|
|
131
|
-
def colour(self):
|
|
132
|
-
warnings.warn(
|
|
133
|
-
"the .colour attribute may be removed in future, use the "
|
|
134
|
-
"equivalent `cocotb.utils.want_color_output()` instead",
|
|
135
|
-
DeprecationWarning,
|
|
136
|
-
stacklevel=2,
|
|
137
|
-
)
|
|
138
|
-
return want_color_output()
|
|
92
|
+
gpi_logger.setLevel = setLevel # type: ignore[method-assign]
|
|
139
93
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
94
|
+
# Initialize PyGPI logging
|
|
95
|
+
simulator.initialize_logger(_log_from_c, logging.getLogger)
|
|
96
|
+
|
|
97
|
+
# Set "cocotb" and "gpi" logger based on environment variables
|
|
98
|
+
def set_level(logger_name: str, envvar: str, default_level: str) -> None:
|
|
99
|
+
log_level = os.environ.get(envvar, default_level)
|
|
100
|
+
log_level = log_level.upper()
|
|
101
|
+
|
|
102
|
+
logger = logging.getLogger(logger_name)
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
logger.setLevel(log_level)
|
|
106
|
+
except ValueError:
|
|
107
|
+
valid_levels = ", ".join(
|
|
108
|
+
("CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE", "NOTSET")
|
|
109
|
+
)
|
|
110
|
+
raise ValueError(
|
|
111
|
+
f"Invalid log level {log_level!r} passed through the "
|
|
112
|
+
f"{envvar} environment variable. Valid log "
|
|
113
|
+
f"levels: {valid_levels}"
|
|
114
|
+
) from None
|
|
144
115
|
|
|
116
|
+
set_level("gpi", "GPI_LOG_LEVEL", "INFO")
|
|
117
|
+
set_level("cocotb", "COCOTB_LOG_LEVEL", "INFO")
|
|
145
118
|
|
|
146
|
-
|
|
147
|
-
def
|
|
148
|
-
"""
|
|
119
|
+
|
|
120
|
+
def _setup_formatter(_: object) -> None:
|
|
121
|
+
"""Setup cocotb's logging formatter."""
|
|
122
|
+
default_config()
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
@deprecated('Use `logging.getLogger(f"{name}.0x{ident:x}")` instead')
|
|
126
|
+
def SimLog(name: str, ident: Union[int, None] = None) -> logging.Logger:
|
|
127
|
+
"""Like logging.getLogger, but append a numeric identifier to the name.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
name: Logger name.
|
|
131
|
+
ident: Unique integer identifier.
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
The Logger named ``{name}.0x{ident:x}``.
|
|
135
|
+
|
|
136
|
+
.. deprecated:: 2.0
|
|
137
|
+
|
|
138
|
+
Use ``logging.getLogger(f"{name}.0x{ident:x}")`` instead.
|
|
139
|
+
"""
|
|
149
140
|
if ident is not None:
|
|
150
141
|
name = f"{name}.0x{ident:x}"
|
|
151
142
|
return logging.getLogger(name)
|
|
@@ -163,11 +154,11 @@ class SimTimeContextFilter(logging.Filter):
|
|
|
163
154
|
"""
|
|
164
155
|
|
|
165
156
|
# needed to make our docs render well
|
|
166
|
-
def __init__(self):
|
|
157
|
+
def __init__(self) -> None:
|
|
167
158
|
""""""
|
|
168
159
|
super().__init__()
|
|
169
160
|
|
|
170
|
-
def filter(self, record):
|
|
161
|
+
def filter(self, record: logging.LogRecord) -> bool:
|
|
171
162
|
try:
|
|
172
163
|
record.created_sim_time = get_sim_time()
|
|
173
164
|
except RecursionError:
|
|
@@ -187,24 +178,26 @@ class SimLogFormatter(logging.Formatter):
|
|
|
187
178
|
|
|
188
179
|
# Removes the arguments from the base class. Docstring needed to make
|
|
189
180
|
# sphinx happy.
|
|
190
|
-
def __init__(self):
|
|
181
|
+
def __init__(self) -> None:
|
|
191
182
|
"""Takes no arguments."""
|
|
192
183
|
super().__init__()
|
|
193
184
|
|
|
194
185
|
# Justify and truncate
|
|
195
186
|
@staticmethod
|
|
196
|
-
def ljust(string, chars):
|
|
187
|
+
def ljust(string: str, chars: int) -> str:
|
|
197
188
|
if len(string) > chars:
|
|
198
189
|
return ".." + string[(chars - 2) * -1 :]
|
|
199
190
|
return string.ljust(chars)
|
|
200
191
|
|
|
201
192
|
@staticmethod
|
|
202
|
-
def rjust(string, chars):
|
|
193
|
+
def rjust(string: str, chars: int) -> str:
|
|
203
194
|
if len(string) > chars:
|
|
204
195
|
return ".." + string[(chars - 2) * -1 :]
|
|
205
196
|
return string.rjust(chars)
|
|
206
197
|
|
|
207
|
-
def _format(
|
|
198
|
+
def _format(
|
|
199
|
+
self, level: str, record: logging.LogRecord, msg: str, coloured: bool = False
|
|
200
|
+
) -> str:
|
|
208
201
|
sim_time = getattr(record, "created_sim_time", None)
|
|
209
202
|
if sim_time is None:
|
|
210
203
|
sim_time_str = " -.--ns"
|
|
@@ -221,7 +214,7 @@ class SimLogFormatter(logging.Formatter):
|
|
|
221
214
|
)
|
|
222
215
|
if not _suppress:
|
|
223
216
|
prefix += (
|
|
224
|
-
self.rjust(
|
|
217
|
+
self.rjust(Path(record.filename).name, _FILENAME_CHARS)
|
|
225
218
|
+ ":"
|
|
226
219
|
+ self.ljust(str(record.lineno), _LINENO_CHARS)
|
|
227
220
|
+ " in "
|
|
@@ -229,7 +222,7 @@ class SimLogFormatter(logging.Formatter):
|
|
|
229
222
|
+ " "
|
|
230
223
|
)
|
|
231
224
|
|
|
232
|
-
# these lines are copied from the
|
|
225
|
+
# these lines are copied from the built-in logger
|
|
233
226
|
if record.exc_info:
|
|
234
227
|
# Cache the traceback text to avoid converting it multiple times
|
|
235
228
|
# (it's constant anyway)
|
|
@@ -246,8 +239,8 @@ class SimLogFormatter(logging.Formatter):
|
|
|
246
239
|
pad = "\n" + " " * (prefix_len)
|
|
247
240
|
return prefix + pad.join(msg.split("\n"))
|
|
248
241
|
|
|
249
|
-
def format(self, record):
|
|
250
|
-
"""Prettify the log output
|
|
242
|
+
def format(self, record: logging.LogRecord) -> str:
|
|
243
|
+
"""Prettify the log output by annotating with simulation time."""
|
|
251
244
|
|
|
252
245
|
msg = record.getMessage()
|
|
253
246
|
level = record.levelname.ljust(_LEVEL_CHARS)
|
|
@@ -259,16 +252,16 @@ class SimColourLogFormatter(SimLogFormatter):
|
|
|
259
252
|
"""Log formatter to provide consistent log message handling."""
|
|
260
253
|
|
|
261
254
|
loglevel2colour = {
|
|
262
|
-
logging.TRACE: "%s",
|
|
255
|
+
logging.TRACE: "%s", # type: ignore[attr-defined] # type checkers don't like adding module attributes after the fact
|
|
263
256
|
logging.DEBUG: "%s",
|
|
264
257
|
logging.INFO: "%s",
|
|
265
|
-
logging.WARNING:
|
|
266
|
-
logging.ERROR:
|
|
267
|
-
logging.CRITICAL:
|
|
258
|
+
logging.WARNING: _ANSI.COLOR_WARNING + "%s" + _ANSI.COLOR_DEFAULT,
|
|
259
|
+
logging.ERROR: _ANSI.COLOR_ERROR + "%s" + _ANSI.COLOR_DEFAULT,
|
|
260
|
+
logging.CRITICAL: _ANSI.COLOR_CRITICAL + "%s" + _ANSI.COLOR_DEFAULT,
|
|
268
261
|
}
|
|
269
262
|
|
|
270
|
-
def format(self, record):
|
|
271
|
-
"""Prettify the log output
|
|
263
|
+
def format(self, record: logging.LogRecord) -> str:
|
|
264
|
+
"""Prettify the log output by annotating with simulation time."""
|
|
272
265
|
|
|
273
266
|
msg = record.getMessage()
|
|
274
267
|
|
|
@@ -286,18 +279,20 @@ class SimColourLogFormatter(SimLogFormatter):
|
|
|
286
279
|
return self._format(level, record, msg, coloured=True)
|
|
287
280
|
|
|
288
281
|
|
|
289
|
-
def
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
282
|
+
def _log_from_c(
|
|
283
|
+
logger: logging.Logger,
|
|
284
|
+
level: int,
|
|
285
|
+
filename: str,
|
|
286
|
+
lineno: int,
|
|
287
|
+
msg: str,
|
|
288
|
+
function_name: str,
|
|
289
|
+
) -> None:
|
|
294
290
|
"""
|
|
295
291
|
This is for use from the C world, and allows us to insert C stack
|
|
296
292
|
information.
|
|
297
293
|
"""
|
|
298
|
-
logger = logging.getLogger(logger_name)
|
|
299
294
|
if logger.isEnabledFor(level):
|
|
300
295
|
record = logger.makeRecord(
|
|
301
|
-
logger.name, level, filename, lineno, msg,
|
|
296
|
+
logger.name, level, filename, lineno, msg, (), None, function_name
|
|
302
297
|
)
|
|
303
298
|
logger.handle(record)
|