[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -1,23 +1,26 @@
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
"""Support for plugins."""
from __future__ import annotations
import os
import os.path
import sys
from types import FrameType
from typing import Any, Iterable, Iterator
from typing import Any
from typing import Iterable
from typing import Iterator
from coverage.exceptions import PluginError
from coverage.misc import isolate_module
from coverage.plugin import CoveragePlugin, FileTracer, FileReporter
from coverage.types import (
TArc, TConfigurable, TDebugCtl, TLineNo, TPluginConfig, TSourceTokenLines,
)
from coverage.plugin import CoveragePlugin
from coverage.plugin import FileReporter
from coverage.plugin import FileTracer
from coverage.types import TArc
from coverage.types import TConfigurable
from coverage.types import TDebugCtl
from coverage.types import TLineNo
from coverage.types import TPluginConfig
from coverage.types import TSourceTokenLines
os = isolate_module(os)
@ -55,7 +58,7 @@ class Plugins:
__import__(module)
mod = sys.modules[module]
coverage_init = getattr(mod, "coverage_init", None)
coverage_init = getattr(mod, 'coverage_init', None)
if not coverage_init:
raise PluginError(
f"Plugin module {module!r} didn't define a coverage_init function",
@ -113,10 +116,10 @@ class Plugins:
is a list to append the plugin to.
"""
plugin_name = f"{self.current_module}.{plugin.__class__.__name__}"
if self.debug and self.debug.should("plugin"):
self.debug.write(f"Loaded plugin {self.current_module!r}: {plugin!r}")
labelled = LabelledDebug(f"plugin {self.current_module!r}", self.debug)
plugin_name = f'{self.current_module}.{plugin.__class__.__name__}'
if self.debug and self.debug.should('plugin'):
self.debug.write(f'Loaded plugin {self.current_module!r}: {plugin!r}')
labelled = LabelledDebug(f'plugin {self.current_module!r}', self.debug)
plugin = DebugPluginWrapper(plugin, labelled)
plugin._coverage_plugin_name = plugin_name
@ -150,12 +153,12 @@ class LabelledDebug:
def message_prefix(self) -> str:
"""The prefix to use on messages, combining the labels."""
prefixes = self.labels + [""]
return ":\n".join(" "*i+label for i, label in enumerate(prefixes))
prefixes = self.labels + ['']
return ':\n'.join(' ' * i + label for i, label in enumerate(prefixes))
def write(self, message: str) -> None:
"""Write `message`, but with the labels prepended."""
self.debug.write(f"{self.message_prefix()}{message}")
self.debug.write(f'{self.message_prefix()}{message}')
class DebugPluginWrapper(CoveragePlugin):
@ -168,33 +171,33 @@ class DebugPluginWrapper(CoveragePlugin):
def file_tracer(self, filename: str) -> FileTracer | None:
tracer = self.plugin.file_tracer(filename)
self.debug.write(f"file_tracer({filename!r}) --> {tracer!r}")
self.debug.write(f'file_tracer({filename!r}) --> {tracer!r}')
if tracer:
debug = self.debug.add_label(f"file {filename!r}")
debug = self.debug.add_label(f'file {filename!r}')
tracer = DebugFileTracerWrapper(tracer, debug)
return tracer
def file_reporter(self, filename: str) -> FileReporter | str:
reporter = self.plugin.file_reporter(filename)
assert isinstance(reporter, FileReporter)
self.debug.write(f"file_reporter({filename!r}) --> {reporter!r}")
self.debug.write(f'file_reporter({filename!r}) --> {reporter!r}')
if reporter:
debug = self.debug.add_label(f"file {filename!r}")
debug = self.debug.add_label(f'file {filename!r}')
reporter = DebugFileReporterWrapper(filename, reporter, debug)
return reporter
def dynamic_context(self, frame: FrameType) -> str | None:
context = self.plugin.dynamic_context(frame)
self.debug.write(f"dynamic_context({frame!r}) --> {context!r}")
self.debug.write(f'dynamic_context({frame!r}) --> {context!r}')
return context
def find_executable_files(self, src_dir: str) -> Iterable[str]:
executable_files = self.plugin.find_executable_files(src_dir)
self.debug.write(f"find_executable_files({src_dir!r}) --> {executable_files!r}")
self.debug.write(f'find_executable_files({src_dir!r}) --> {executable_files!r}')
return executable_files
def configure(self, config: TConfigurable) -> None:
self.debug.write(f"configure({config!r})")
self.debug.write(f'configure({config!r})')
self.plugin.configure(config)
def sys_info(self) -> Iterable[tuple[str, Any]]:
@ -210,31 +213,33 @@ class DebugFileTracerWrapper(FileTracer):
def _show_frame(self, frame: FrameType) -> str:
"""A short string identifying a frame, for debug messages."""
return "%s@%d" % (
return '%s@%d' % (
os.path.basename(frame.f_code.co_filename),
frame.f_lineno,
)
def source_filename(self) -> str:
sfilename = self.tracer.source_filename()
self.debug.write(f"source_filename() --> {sfilename!r}")
self.debug.write(f'source_filename() --> {sfilename!r}')
return sfilename
def has_dynamic_source_filename(self) -> bool:
has = self.tracer.has_dynamic_source_filename()
self.debug.write(f"has_dynamic_source_filename() --> {has!r}")
self.debug.write(f'has_dynamic_source_filename() --> {has!r}')
return has
def dynamic_source_filename(self, filename: str, frame: FrameType) -> str | None:
dyn = self.tracer.dynamic_source_filename(filename, frame)
self.debug.write("dynamic_source_filename({!r}, {}) --> {!r}".format(
filename, self._show_frame(frame), dyn,
))
self.debug.write(
'dynamic_source_filename({!r}, {}) --> {!r}'.format(
filename, self._show_frame(frame), dyn,
),
)
return dyn
def line_number_range(self, frame: FrameType) -> tuple[TLineNo, TLineNo]:
pair = self.tracer.line_number_range(frame)
self.debug.write(f"line_number_range({self._show_frame(frame)}) --> {pair!r}")
self.debug.write(f'line_number_range({self._show_frame(frame)}) --> {pair!r}')
return pair
@ -248,50 +253,50 @@ class DebugFileReporterWrapper(FileReporter):
def relative_filename(self) -> str:
ret = self.reporter.relative_filename()
self.debug.write(f"relative_filename() --> {ret!r}")
self.debug.write(f'relative_filename() --> {ret!r}')
return ret
def lines(self) -> set[TLineNo]:
ret = self.reporter.lines()
self.debug.write(f"lines() --> {ret!r}")
self.debug.write(f'lines() --> {ret!r}')
return ret
def excluded_lines(self) -> set[TLineNo]:
ret = self.reporter.excluded_lines()
self.debug.write(f"excluded_lines() --> {ret!r}")
self.debug.write(f'excluded_lines() --> {ret!r}')
return ret
def translate_lines(self, lines: Iterable[TLineNo]) -> set[TLineNo]:
ret = self.reporter.translate_lines(lines)
self.debug.write(f"translate_lines({lines!r}) --> {ret!r}")
self.debug.write(f'translate_lines({lines!r}) --> {ret!r}')
return ret
def translate_arcs(self, arcs: Iterable[TArc]) -> set[TArc]:
ret = self.reporter.translate_arcs(arcs)
self.debug.write(f"translate_arcs({arcs!r}) --> {ret!r}")
self.debug.write(f'translate_arcs({arcs!r}) --> {ret!r}')
return ret
def no_branch_lines(self) -> set[TLineNo]:
ret = self.reporter.no_branch_lines()
self.debug.write(f"no_branch_lines() --> {ret!r}")
self.debug.write(f'no_branch_lines() --> {ret!r}')
return ret
def exit_counts(self) -> dict[TLineNo, int]:
ret = self.reporter.exit_counts()
self.debug.write(f"exit_counts() --> {ret!r}")
self.debug.write(f'exit_counts() --> {ret!r}')
return ret
def arcs(self) -> set[TArc]:
ret = self.reporter.arcs()
self.debug.write(f"arcs() --> {ret!r}")
self.debug.write(f'arcs() --> {ret!r}')
return ret
def source(self) -> str:
ret = self.reporter.source()
self.debug.write("source() --> %d chars" % (len(ret),))
self.debug.write('source() --> %d chars' % (len(ret),))
return ret
def source_token_lines(self) -> TSourceTokenLines:
ret = list(self.reporter.source_token_lines())
self.debug.write("source_token_lines() --> %d tokens" % (len(ret),))
self.debug.write('source_token_lines() --> %d tokens' % (len(ret),))
return ret