cocotb 2.0.1__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.
Files changed (152) hide show
  1. cocotb/_ANSI.py +65 -0
  2. cocotb/__init__.py +127 -0
  3. cocotb/_base_triggers.py +515 -0
  4. cocotb/_bridge.py +186 -0
  5. cocotb/_decorators.py +515 -0
  6. cocotb/_deprecation.py +36 -0
  7. cocotb/_exceptions.py +7 -0
  8. cocotb/_extended_awaitables.py +419 -0
  9. cocotb/_gpi_triggers.py +385 -0
  10. cocotb/_init.py +301 -0
  11. cocotb/_outcomes.py +54 -0
  12. cocotb/_profiling.py +46 -0
  13. cocotb/_py_compat.py +150 -0
  14. cocotb/_scheduler.py +448 -0
  15. cocotb/_test.py +248 -0
  16. cocotb/_test_factory.py +312 -0
  17. cocotb/_test_functions.py +42 -0
  18. cocotb/_typing.py +7 -0
  19. cocotb/_utils.py +274 -0
  20. cocotb/_version.py +4 -0
  21. cocotb/_xunit_reporter.py +103 -0
  22. cocotb/clock.py +419 -0
  23. cocotb/debug.py +24 -0
  24. cocotb/handle.py +1752 -0
  25. cocotb/libs/cocotb.dll +0 -0
  26. cocotb/libs/cocotb.exp +0 -0
  27. cocotb/libs/cocotb.lib +0 -0
  28. cocotb/libs/cocotbfli_modelsim.dll +0 -0
  29. cocotb/libs/cocotbfli_modelsim.exp +0 -0
  30. cocotb/libs/cocotbfli_modelsim.lib +0 -0
  31. cocotb/libs/cocotbutils.dll +0 -0
  32. cocotb/libs/cocotbutils.exp +0 -0
  33. cocotb/libs/cocotbutils.lib +0 -0
  34. cocotb/libs/cocotbvhpi_aldec.dll +0 -0
  35. cocotb/libs/cocotbvhpi_aldec.exp +0 -0
  36. cocotb/libs/cocotbvhpi_aldec.lib +0 -0
  37. cocotb/libs/cocotbvhpi_modelsim.dll +0 -0
  38. cocotb/libs/cocotbvhpi_modelsim.exp +0 -0
  39. cocotb/libs/cocotbvhpi_modelsim.lib +0 -0
  40. cocotb/libs/cocotbvhpi_nvc.dll +0 -0
  41. cocotb/libs/cocotbvhpi_nvc.exp +0 -0
  42. cocotb/libs/cocotbvhpi_nvc.lib +0 -0
  43. cocotb/libs/cocotbvpi_aldec.dll +0 -0
  44. cocotb/libs/cocotbvpi_aldec.exp +0 -0
  45. cocotb/libs/cocotbvpi_aldec.lib +0 -0
  46. cocotb/libs/cocotbvpi_ghdl.dll +0 -0
  47. cocotb/libs/cocotbvpi_ghdl.exp +0 -0
  48. cocotb/libs/cocotbvpi_ghdl.lib +0 -0
  49. cocotb/libs/cocotbvpi_icarus.exp +0 -0
  50. cocotb/libs/cocotbvpi_icarus.lib +0 -0
  51. cocotb/libs/cocotbvpi_icarus.vpl +0 -0
  52. cocotb/libs/cocotbvpi_modelsim.dll +0 -0
  53. cocotb/libs/cocotbvpi_modelsim.exp +0 -0
  54. cocotb/libs/cocotbvpi_modelsim.lib +0 -0
  55. cocotb/libs/embed.dll +0 -0
  56. cocotb/libs/embed.exp +0 -0
  57. cocotb/libs/embed.lib +0 -0
  58. cocotb/libs/gpi.dll +0 -0
  59. cocotb/libs/gpi.exp +0 -0
  60. cocotb/libs/gpi.lib +0 -0
  61. cocotb/libs/gpilog.dll +0 -0
  62. cocotb/libs/gpilog.exp +0 -0
  63. cocotb/libs/gpilog.lib +0 -0
  64. cocotb/libs/pygpilog.dll +0 -0
  65. cocotb/libs/pygpilog.exp +0 -0
  66. cocotb/libs/pygpilog.lib +0 -0
  67. cocotb/logging.py +417 -0
  68. cocotb/py.typed +0 -0
  69. cocotb/queue.py +235 -0
  70. cocotb/regression.py +900 -0
  71. cocotb/result.py +38 -0
  72. cocotb/share/def/.gitignore +2 -0
  73. cocotb/share/def/README.md +4 -0
  74. cocotb/share/def/aldec.def +61 -0
  75. cocotb/share/def/aldec.exp +0 -0
  76. cocotb/share/def/aldec.lib +0 -0
  77. cocotb/share/def/ghdl.def +43 -0
  78. cocotb/share/def/ghdl.exp +0 -0
  79. cocotb/share/def/ghdl.lib +0 -0
  80. cocotb/share/def/icarus.def +43 -0
  81. cocotb/share/def/icarus.exp +0 -0
  82. cocotb/share/def/icarus.lib +0 -0
  83. cocotb/share/def/modelsim.def +138 -0
  84. cocotb/share/def/modelsim.exp +0 -0
  85. cocotb/share/def/modelsim.lib +0 -0
  86. cocotb/share/def/nvcvhpi.def +18 -0
  87. cocotb/share/def/nvcvhpi.exp +0 -0
  88. cocotb/share/def/nvcvhpi.lib +0 -0
  89. cocotb/share/include/cocotb_utils.h +70 -0
  90. cocotb/share/include/embed.h +33 -0
  91. cocotb/share/include/exports.h +20 -0
  92. cocotb/share/include/gpi.h +459 -0
  93. cocotb/share/include/gpi_logging.h +291 -0
  94. cocotb/share/include/py_gpi_logging.h +33 -0
  95. cocotb/share/include/vhpi_user_ext.h +26 -0
  96. cocotb/share/include/vpi_user_ext.h +33 -0
  97. cocotb/share/lib/verilator/verilator.cpp +209 -0
  98. cocotb/simtime.py +238 -0
  99. cocotb/simulator.cp38-win32.exp +0 -0
  100. cocotb/simulator.cp38-win32.lib +0 -0
  101. cocotb/simulator.cp38-win32.pyd +0 -0
  102. cocotb/simulator.cp38-win32.pyd.2.config +8 -0
  103. cocotb/simulator.pyi +107 -0
  104. cocotb/task.py +590 -0
  105. cocotb/triggers.py +67 -0
  106. cocotb/types/__init__.py +31 -0
  107. cocotb/types/_abstract_array.py +151 -0
  108. cocotb/types/_array.py +297 -0
  109. cocotb/types/_indexing.py +17 -0
  110. cocotb/types/_logic.py +333 -0
  111. cocotb/types/_logic_array.py +884 -0
  112. cocotb/types/_range.py +197 -0
  113. cocotb/types/_resolve.py +76 -0
  114. cocotb/utils.py +110 -0
  115. cocotb-2.0.1.dist-info/LICENSE +29 -0
  116. cocotb-2.0.1.dist-info/METADATA +44 -0
  117. cocotb-2.0.1.dist-info/RECORD +152 -0
  118. cocotb-2.0.1.dist-info/WHEEL +5 -0
  119. cocotb-2.0.1.dist-info/entry_points.txt +2 -0
  120. cocotb-2.0.1.dist-info/top_level.txt +18 -0
  121. cocotb_tools/__init__.py +0 -0
  122. cocotb_tools/_coverage.py +33 -0
  123. cocotb_tools/_vendor/__init__.py +3 -0
  124. cocotb_tools/_vendor/distutils_version.py +346 -0
  125. cocotb_tools/check_results.py +65 -0
  126. cocotb_tools/combine_results.py +152 -0
  127. cocotb_tools/config.py +242 -0
  128. cocotb_tools/ipython_support.py +99 -0
  129. cocotb_tools/makefiles/Makefile.deprecations +27 -0
  130. cocotb_tools/makefiles/Makefile.inc +198 -0
  131. cocotb_tools/makefiles/Makefile.sim +96 -0
  132. cocotb_tools/makefiles/simulators/Makefile.activehdl +72 -0
  133. cocotb_tools/makefiles/simulators/Makefile.cvc +61 -0
  134. cocotb_tools/makefiles/simulators/Makefile.dsim +39 -0
  135. cocotb_tools/makefiles/simulators/Makefile.ghdl +84 -0
  136. cocotb_tools/makefiles/simulators/Makefile.icarus +80 -0
  137. cocotb_tools/makefiles/simulators/Makefile.ius +93 -0
  138. cocotb_tools/makefiles/simulators/Makefile.modelsim +9 -0
  139. cocotb_tools/makefiles/simulators/Makefile.nvc +60 -0
  140. cocotb_tools/makefiles/simulators/Makefile.questa +29 -0
  141. cocotb_tools/makefiles/simulators/Makefile.questa-compat +143 -0
  142. cocotb_tools/makefiles/simulators/Makefile.questa-qisqrun +149 -0
  143. cocotb_tools/makefiles/simulators/Makefile.riviera +144 -0
  144. cocotb_tools/makefiles/simulators/Makefile.vcs +65 -0
  145. cocotb_tools/makefiles/simulators/Makefile.verilator +79 -0
  146. cocotb_tools/makefiles/simulators/Makefile.xcelium +104 -0
  147. cocotb_tools/py.typed +0 -0
  148. cocotb_tools/runner.py +2001 -0
  149. cocotb_tools/sim_versions.py +140 -0
  150. pygpi/__init__.py +0 -0
  151. pygpi/entry.py +42 -0
  152. pygpi/py.typed +0 -0
cocotb/libs/cocotb.dll ADDED
Binary file
cocotb/libs/cocotb.exp ADDED
Binary file
cocotb/libs/cocotb.lib ADDED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
cocotb/libs/embed.dll ADDED
Binary file
cocotb/libs/embed.exp ADDED
Binary file
cocotb/libs/embed.lib ADDED
Binary file
cocotb/libs/gpi.dll ADDED
Binary file
cocotb/libs/gpi.exp ADDED
Binary file
cocotb/libs/gpi.lib ADDED
Binary file
cocotb/libs/gpilog.dll ADDED
Binary file
cocotb/libs/gpilog.exp ADDED
Binary file
cocotb/libs/gpilog.lib ADDED
Binary file
Binary file
Binary file
Binary file
cocotb/logging.py ADDED
@@ -0,0 +1,417 @@
1
+ # Copyright cocotb contributors
2
+ # Copyright (c) 2013, 2018 Potential Ventures Ltd
3
+ # Copyright (c) 2013 SolarFlare Communications Inc
4
+ # Licensed under the Revised BSD License, see LICENSE for details.
5
+ # SPDX-License-Identifier: BSD-3-Clause
6
+
7
+ """
8
+ Everything related to logging
9
+ """
10
+
11
+ import logging
12
+ import os
13
+ import re
14
+ import sys
15
+ import time
16
+ import warnings
17
+ from functools import wraps
18
+ from typing import Optional, Tuple, Union
19
+
20
+ import cocotb.simtime
21
+ from cocotb import simulator
22
+ from cocotb._ANSI import ANSI
23
+ from cocotb._deprecation import deprecated
24
+ from cocotb.simtime import get_sim_time
25
+ from cocotb.utils import get_time_from_sim_steps
26
+
27
+ __all__ = (
28
+ "ANSI",
29
+ "SimLog",
30
+ "SimLogFormatter",
31
+ "SimTimeContextFilter",
32
+ "default_config",
33
+ "strip_ansi",
34
+ )
35
+
36
+ ANSI.__module__ = __name__
37
+
38
+ # Custom log level
39
+ logging.TRACE = 5 # type: ignore[attr-defined] # type checkers don't like adding module attributes after the fact
40
+ logging.addLevelName(5, "TRACE")
41
+
42
+
43
+ strip_ansi: bool = False
44
+ """Whether the default formatter should strip ANSI (color) escape codes from log messages.
45
+
46
+ Defaults to ``True`` if ``stdout`` is not a TTY and ``False`` otherwise;
47
+ but can be overridden with the :envvar:`NO_COLOR` or :envvar:`COCOTB_ANSI_OUTPUT` environment variable.
48
+ """
49
+
50
+
51
+ def default_config(
52
+ reduced_log_fmt: bool = True,
53
+ strip_ansi: Optional[bool] = None,
54
+ prefix_format: Optional[str] = None,
55
+ ) -> None:
56
+ """Apply the default cocotb log formatting to the root logger.
57
+
58
+ This hooks up the logger to write to stdout, using :class:`SimLogFormatter` for formatting.
59
+ It also adds a :class:`SimTimeContextFilter` filter so that the
60
+ :attr:`~logging.LogRecord.created_sim_time` attribute on :class:`~logging.LogRecord`
61
+ is available to the formatter.
62
+
63
+ If desired, this logging configuration can be overwritten by calling
64
+ ``logging.basicConfig(..., force=True)`` (in Python 3.8 onwards),
65
+ or by manually resetting the root logger instance.
66
+ An example of this can be found in the section on :ref:`rotating-logger`.
67
+
68
+ Args:
69
+ reduced_log_fmt:
70
+ If ``True``, use a reduced log format that does not include the
71
+ filename, line number, and function name in the log prefix.
72
+
73
+ .. versionadded:: 2.0
74
+
75
+ strip_ansi:
76
+ If ``True``, strip ANSI (color) escape codes in log messages.
77
+ If ``False``, do not strip ANSI escape codes in log messages.
78
+ If ``None``, use the value of :data:`strip_ansi`.
79
+
80
+ .. versionadded:: 2.0
81
+
82
+ prefix_format:
83
+ An f-string to build a prefix for each log message.
84
+
85
+ .. versionadded:: 2.0
86
+
87
+ .. versionadded:: 1.4
88
+
89
+ .. versionchanged:: 2.0
90
+ Now captures warnings and outputs them through the logging system using
91
+ :func:`logging.captureWarnings`.
92
+ """
93
+ logging.basicConfig()
94
+
95
+ hdlr = logging.StreamHandler(sys.stdout)
96
+ hdlr.addFilter(SimTimeContextFilter())
97
+ hdlr.setFormatter(
98
+ SimLogFormatter(
99
+ reduced_log_fmt=reduced_log_fmt,
100
+ strip_ansi=strip_ansi,
101
+ prefix_format=prefix_format,
102
+ )
103
+ )
104
+ logging.getLogger().handlers = [hdlr] # overwrite default handlers
105
+
106
+ logging.getLogger("cocotb").setLevel(logging.INFO)
107
+ logging.getLogger("gpi").setLevel(logging.INFO)
108
+
109
+ logging.captureWarnings(True)
110
+
111
+
112
+ def _init() -> None:
113
+ """cocotb-specific logging setup.
114
+
115
+ - Decides whether ANSI escape code stripping is desired by checking
116
+ :envvar:`NO_COLOR` and :envvar:`COCOTB_ANSI_OUTPUT`.
117
+ - Initializes the GPI logger and sets up the GPI logging optimization.
118
+ - Sets the log level of the ``"cocotb"`` and ``"gpi"`` loggers based on
119
+ :envvar:`COCOTB_LOG_LEVEL` and :envvar:`GPI_LOG_LEVEL`, respectively.
120
+ """
121
+ global strip_ansi
122
+ strip_ansi = not sys.stdout.isatty() # default to color for TTYs
123
+ if os.getenv("NO_COLOR", ""):
124
+ strip_ansi = True
125
+ ansi_output = os.getenv("COCOTB_ANSI_OUTPUT")
126
+ if ansi_output is not None:
127
+ strip_ansi = not int(ansi_output)
128
+ in_gui = os.getenv("GUI")
129
+ if in_gui is not None:
130
+ strip_ansi = bool(int(in_gui))
131
+
132
+ # Monkeypatch "gpi" logger with function that also sets a PyGPI-local logger level
133
+ # as an optimization.
134
+ gpi_logger = logging.getLogger("gpi")
135
+ old_setLevel = gpi_logger.setLevel
136
+
137
+ @wraps(old_setLevel)
138
+ def setLevel(level: Union[int, str]) -> None:
139
+ old_setLevel(level)
140
+ simulator.set_gpi_log_level(gpi_logger.getEffectiveLevel())
141
+
142
+ gpi_logger.setLevel = setLevel # type: ignore[method-assign]
143
+
144
+ # Initialize PyGPI logging
145
+ simulator.initialize_logger(_log_from_c, logging.getLogger)
146
+
147
+ # Set "cocotb" and "gpi" logger based on environment variables
148
+ def set_level(logger_name: str, envvar: str) -> None:
149
+ log_level = os.environ.get(envvar)
150
+ if log_level is None:
151
+ return
152
+
153
+ log_level = log_level.upper()
154
+
155
+ logger = logging.getLogger(logger_name)
156
+
157
+ try:
158
+ logger.setLevel(log_level)
159
+ except ValueError:
160
+ valid_levels = ", ".join(
161
+ ("CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE", "NOTSET")
162
+ )
163
+ raise ValueError(
164
+ f"Invalid log level {log_level!r} passed through the "
165
+ f"{envvar} environment variable. Valid log "
166
+ f"levels: {valid_levels}"
167
+ ) from None
168
+
169
+ set_level("gpi", "GPI_LOG_LEVEL")
170
+ set_level("cocotb", "COCOTB_LOG_LEVEL")
171
+
172
+
173
+ def _configure(_: object) -> None:
174
+ """Configure basic logging."""
175
+ reduced_log_fmt = True
176
+ try:
177
+ reduced_log_fmt = bool(int(os.environ.get("COCOTB_REDUCED_LOG_FMT", "1")))
178
+ except ValueError:
179
+ pass
180
+ prefix_format = os.environ.get("COCOTB_LOG_PREFIX", None)
181
+ default_config(reduced_log_fmt=reduced_log_fmt, prefix_format=prefix_format)
182
+
183
+
184
+ @deprecated('Use `logging.getLogger(f"{name}.0x{ident:x}")` instead')
185
+ def SimLog(name: str, ident: Union[int, None] = None) -> logging.Logger:
186
+ """Like :func:`logging.getLogger`, but append a numeric identifier to the name.
187
+
188
+ Args:
189
+ name: Logger name.
190
+ ident: Unique integer identifier.
191
+
192
+ Returns:
193
+ The Logger named ``{name}.0x{ident:x}``.
194
+
195
+ .. deprecated:: 2.0
196
+
197
+ Use ``logging.getLogger(f"{name}.0x{ident:x}")`` instead.
198
+ """
199
+ if ident is not None:
200
+ name = f"{name}.0x{ident:x}"
201
+ return logging.getLogger(name)
202
+
203
+
204
+ class SimTimeContextFilter(logging.Filter):
205
+ """
206
+ A filter to inject simulator times into the log records.
207
+
208
+ This uses the approach described in the :ref:`Python logging cookbook <python:filters-contextual>`
209
+ which adds the :attr:`~logging.LogRecord.created_sim_time` attribute.
210
+
211
+ .. versionadded:: 1.4
212
+ """
213
+
214
+ def filter(self, record: logging.LogRecord) -> bool:
215
+ try:
216
+ record.created_sim_time = get_sim_time()
217
+ except RecursionError:
218
+ # get_sim_time may try to log - if that happens, we can't
219
+ # attach a simulator time to this message.
220
+ record.created_sim_time = None
221
+ return True
222
+
223
+
224
+ class SimLogFormatter(logging.Formatter):
225
+ """Log formatter to provide consistent log message handling.
226
+
227
+ This will only add simulator timestamps if the handler object this
228
+ formatter is attached to has a :class:`SimTimeContextFilter` filter
229
+ attached, which cocotb ensures by default.
230
+
231
+ See :func:`.default_config` for a description of the arguments.
232
+ """
233
+
234
+ loglevel2colour = {
235
+ logging.TRACE: "", # type: ignore[attr-defined] # type checkers don't like adding module attributes after the fact
236
+ logging.DEBUG: "",
237
+ logging.INFO: "",
238
+ logging.WARNING: ANSI.YELLOW_FG,
239
+ logging.ERROR: ANSI.RED_FG,
240
+ logging.CRITICAL: ANSI.RED_BG + ANSI.BLACK_FG,
241
+ }
242
+
243
+ prefix_func_globals = {
244
+ "time": time,
245
+ "simtime": cocotb.simtime,
246
+ "ANSI": ANSI,
247
+ }
248
+
249
+ def __init__(
250
+ self,
251
+ *,
252
+ reduced_log_fmt: bool = True,
253
+ strip_ansi: Union[bool, None] = None,
254
+ prefix_format: Optional[str] = None,
255
+ ) -> None:
256
+ self._reduced_log_fmt = reduced_log_fmt
257
+ self._strip_ansi = strip_ansi
258
+ self._prefix_func = (
259
+ eval(
260
+ f"lambda record: f'''{prefix_format}'''",
261
+ type(self).prefix_func_globals,
262
+ )
263
+ if prefix_format is not None
264
+ else None
265
+ )
266
+ self._ansi_escape_pattern = re.compile(
267
+ r"""
268
+ \x1B
269
+ (?: # either 7-bit C1, two bytes, ESC Fe (omitting CSI)
270
+ [@-Z\\-_]
271
+ | # or 7-bit CSI (ESC [) + control codes
272
+ \[
273
+ [0-?]* # Parameter bytes
274
+ [ -/]* # Intermediate bytes
275
+ [@-~] # Final byte
276
+ )
277
+ """,
278
+ re.VERBOSE,
279
+ )
280
+
281
+ def strip_ansi(self) -> bool:
282
+ return strip_ansi if self._strip_ansi is None else self._strip_ansi
283
+
284
+ # Justify and truncate
285
+ @staticmethod
286
+ def ljust(string: str, chars: int) -> str:
287
+ if len(string) > chars:
288
+ return ".." + string[(chars - 2) * -1 :]
289
+ return string.ljust(chars)
290
+
291
+ @staticmethod
292
+ def rjust(string: str, chars: int) -> str:
293
+ if len(string) > chars:
294
+ return ".." + string[(chars - 2) * -1 :]
295
+ return string.rjust(chars)
296
+
297
+ def formatPrefix(self, record: logging.LogRecord) -> Tuple[str, int]:
298
+ sim_time = getattr(record, "created_sim_time", None)
299
+ if sim_time is None:
300
+ sim_time_str = " -.--ns"
301
+ else:
302
+ time_ns = get_time_from_sim_steps(sim_time, "ns")
303
+ sim_time_str = f"{time_ns:6.2f}ns"
304
+
305
+ if self.strip_ansi():
306
+ highlight_start = ""
307
+ highlight_end = ""
308
+ else:
309
+ highlight_start = self.loglevel2colour.get(record.levelno, "")
310
+ highlight_end = ANSI.DEFAULT
311
+
312
+ if self._prefix_func is not None:
313
+ prefix = self._prefix_func(record)
314
+ stripped_prefix = self._ansi_escape_pattern.sub("", prefix)
315
+ prefix_len = len(stripped_prefix)
316
+ return prefix, prefix_len
317
+ else:
318
+ prefix = f"{sim_time_str:>11} {highlight_start}{record.levelname:<8}{highlight_end} {self.ljust(record.name, 34)} "
319
+ if not self._reduced_log_fmt:
320
+ prefix = f"{prefix}{self.rjust(record.filename, 20)}:{record.lineno:<4} in {self.ljust(str(record.funcName), 31)} "
321
+
322
+ prefix_len = len(prefix) - len(highlight_start) - len(highlight_end)
323
+ return prefix, prefix_len
324
+
325
+ def formatMessage(self, record: logging.LogRecord) -> str:
326
+ msg = record.getMessage()
327
+
328
+ if self.strip_ansi():
329
+ highlight_start = ""
330
+ highlight_end = ""
331
+ msg = self._ansi_escape_pattern.sub("", msg)
332
+ else:
333
+ highlight_start = self.loglevel2colour.get(record.levelno, "")
334
+ highlight_end = ANSI.DEFAULT
335
+
336
+ msg = f"{highlight_start}{msg}{highlight_end}"
337
+
338
+ return msg
339
+
340
+ def formatExcInfo(self, record: logging.LogRecord) -> str:
341
+ msg = ""
342
+
343
+ # these lines are copied and updated from the built-in logger
344
+ if record.exc_info:
345
+ # Cache the traceback text to avoid converting it multiple times
346
+ # (it's constant anyway)
347
+ if not record.exc_text:
348
+ record.exc_text = self.formatException(record.exc_info)
349
+ if record.exc_text:
350
+ msg += record.exc_text
351
+ if record.stack_info:
352
+ if not msg.endswith("\n"):
353
+ msg += "\n"
354
+ msg += self.formatStack(record.stack_info)
355
+
356
+ return msg
357
+
358
+ def format(self, record: logging.LogRecord) -> str:
359
+ prefix, prefix_len = self.formatPrefix(record)
360
+ msg = self.formatMessage(record)
361
+ exc_info = self.formatExcInfo(record)
362
+
363
+ lines = msg.splitlines()
364
+ lines.extend(exc_info.splitlines())
365
+
366
+ # add prefix to first line of message
367
+ lines[0] = prefix + lines[0]
368
+
369
+ # add padding to each line of message
370
+ pad = "\n" + " " * prefix_len
371
+ return pad.join(lines)
372
+
373
+
374
+ class SimColourLogFormatter(SimLogFormatter):
375
+ """Log formatter similar to :class:`SimLogFormatter`, but with colored output by default.
376
+
377
+ .. deprecated:: 2.0
378
+ Use :class:`!SimLogFormatter` with ``strip_ansi=False`` instead.
379
+ """
380
+
381
+ def __init__(
382
+ self,
383
+ *,
384
+ reduced_log_fmt: bool = True,
385
+ strip_ansi: Union[bool, None] = False,
386
+ prefix_format: Optional[str] = None,
387
+ ) -> None:
388
+ warnings.warn(
389
+ "SimColourLogFormatter is deprecated and will be removed in a future release. "
390
+ "Use SimLogFormatter with `strip_ansi=False` instead.",
391
+ DeprecationWarning,
392
+ stacklevel=2,
393
+ )
394
+ super().__init__(
395
+ reduced_log_fmt=reduced_log_fmt,
396
+ strip_ansi=strip_ansi,
397
+ prefix_format=prefix_format,
398
+ )
399
+
400
+
401
+ def _log_from_c(
402
+ logger: logging.Logger,
403
+ level: int,
404
+ filename: str,
405
+ lineno: int,
406
+ msg: str,
407
+ function_name: str,
408
+ ) -> None:
409
+ """
410
+ This is for use from the C world, and allows us to insert C stack
411
+ information.
412
+ """
413
+ if logger.isEnabledFor(level):
414
+ record = logger.makeRecord(
415
+ logger.name, level, filename, lineno, msg, (), None, function_name
416
+ )
417
+ logger.handle(record)
cocotb/py.typed ADDED
File without changes