Repository URL to install this package:
|
Version:
1.26.0.dev0+gite506aa5f ▾
|
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from dataclasses import dataclass
from pants.reporting.report import Report
class ReporterDestination:
OUT = 0
ERR = 1
class Reporter:
"""Formats and emits reports.
Subclasses implement the callback methods, to provide specific reporting functionality, e.g., to
console or to browser.
"""
@dataclass(frozen=True)
class Settings:
"""Generic reporting settings.
Subclasses of Reporter should extend their own Settings and add any additional settings
they'd like.
"""
log_level: str # Display log messages up to this level.
def __init__(self, run_tracker, settings):
self.run_tracker = run_tracker
self.settings = settings
def open(self):
"""Begin the report."""
pass
def close(self):
"""End the report."""
pass
def start_workunit(self, workunit):
"""A new workunit has started."""
pass
def end_workunit(self, workunit):
"""A workunit has finished."""
pass
def bulk_record_workunits(self, engine_workunits):
"""A collection of workunits from v2 engine part."""
pass
def handle_log(self, workunit, level, *msg_elements):
"""Handle a message logged by pants code.
level: One of the constants above.
Each element in msg_elements is either a message or a (message, detail) pair.
A subclass must show the message, but may choose to show the detail in some
sensible way (e.g., when the message text is clicked on in a browser).
This convenience implementation filters by log level and then delegates to do_handle_log.
"""
if level <= self.level_for_workunit(workunit, self.settings.log_level):
self.do_handle_log(workunit, level, *msg_elements)
def do_handle_log(self, workunit, level, *msg_elements):
"""Handle a message logged by pants code, after it's passed the log level check."""
pass
def handle_output(self, workunit, label, s):
"""Handle output captured from an invoked tool (e.g., javac).
workunit: The innermost WorkUnit in which the tool was invoked.
label: Classifies the output e.g., 'stdout' for output captured from a tool's stdout or
'debug' for debug output captured from a tool's logfiles.
s: The content captured.
"""
pass
def is_under_background_root(self, workunit):
"""Is the workunit running under the main thread's root."""
return self.run_tracker.is_under_background_root(workunit)
def level_for_workunit(self, workunit, default_level):
if workunit.log_config and workunit.log_config.level:
# The value of the level option is a string defined in global_options.py
if workunit.log_config.level == "warn":
return Report.WARN
if workunit.log_config.level == "debug":
return Report.DEBUG
if workunit.log_config.level == "info":
return Report.INFO
return default_level
def use_color_for_workunit(self, workunit, default_use_colors):
if workunit.log_config and workunit.log_config.colors is not None:
return workunit.log_config.colors
return default_use_colors