<commit_before># This file is part of BenchExec, a framework for reliable benchmarking:
# https://github.com/sosy-lab/benchexec
#
# SPDX-FileCopyrightText: 2007-2020 <NAME> <https://www.sosy-lab.org>
#
# SPDX-License-Identifier: Apache-2.0

import argparse
import contextlib
import logging
import inspect
import os
import sys

import benchexec
import benchexec.benchexec
from benchexec import model
from benchexec import util
import benchexec.tools.template

sys.dont_write_bytecode = True  # prevent creation of .pyc files

COLOR_RED = "\033[31;1m"
COLOR_GREEN = "\033[32;1m"
COLOR_ORANGE = "\033[33;1m"
COLOR_MAGENTA = "\033[35;1m"

if util.should_color_output():
    COLOR_DEFAULT = "\033[m"
    COLOR_DESCRIPTION = COLOR_MAGENTA
    COLOR_VALUE = COLOR_GREEN
    COLOR_WARNING = COLOR_RED
else:
    COLOR_DEFAULT = ""
    COLOR_DESCRIPTION = ""
    COLOR_VALUE = ""
    COLOR_WARNING = ""


def print_value(description, value, extra_line=False):
    print(
        "{}{}{}:{}“{}{}{}”".format(
            COLOR_DESCRIPTION,
            description,
            COLOR_DEFAULT,
            "\n\t" if extra_line else " ",
            COLOR_VALUE,
            value,
            COLOR_DEFAULT,
        ),
        file=sys.stderr,
    )


def print_list(description, value):
    print_value(description, list(value), extra_line=True)


def print_multiline_list(description, values):
    print(
        "{}{}{}:".format(COLOR_DESCRIPTION, description, COLOR_DEFAULT), file=sys.stderr
    )
    for value in values:
        print("\t“{}{}{}”".format(COLOR_VALUE, value, COLOR_DEFAULT), file=sys.stderr)


def print_multiline_text(description, value):
    if value is None:
        print(
            "{}{}{}: {}None{}".format(
                COLOR_DESCRIPTION,
                description,
                COLOR_DEFAULT,
                COLOR_WARNING,
                COLOR_DEFAULT,
            ),
            file=sys.stderr,
        )
    elif not value.strip():
        print(
            "{}{}{}: {}“{}”{}".format(
                COLOR_DESCRIPTION,
                description,
                COLOR_DEFAULT,
                COLOR_WARNING,
                value,
                COLOR_DEFAULT,
            ),
            file=sys.stderr,
        )
    else:
        print(
            "{}{}{}:".format(COLOR_DESCRIPTION, description, COLOR_DEFAULT),
            file=sys.stderr,
        )
        for line in value.splitlines():
            print("\t{}{}{}".format(COLOR_VALUE, line, COLOR_DEFAULT), file=sys.stderr)


@contextlib.contextmanager
def log_if_unsupported(msg):
    """Catch any exception in block and log it with a message about an unsupported feature"""
    try:
        yield  # call code block to be executed
    except BaseException as e:
        logging.warning(
            "Tool-info module does not support %s: “%s”",
            msg,
            e,
            exc_info=not isinstance(
                e, benchexec.tools.template.UnsupportedFeatureException
            ),
        )


def print_tool_info(tool):
    print_multiline_text("Documentation of tool module", inspect.getdoc(tool))

    print_value("Name of tool", tool.name())

    executable = tool.executable()
    print_value("Executable", executable)
    if not os.path.isabs(executable):
        print_value("Executable (absolute path)", os.path.abspath(executable))
    else:
        logging.warning(
            "Path to executable is absolute, this might be problematic "
            "in scenarios where runs are distributed to other machines."
        )

    try:
        print_value("Version", tool.version(executable))
    except:  # noqa: E722
        logging.warning("Determining version failed:", exc_info=1)

    working_directory = tool.working_directory(executable)<commit_msg>Add some more warnings to test_tool_info<commit_after># This file is part of BenchExec, a framework for reliable benchmarking:
# https://github.com/sosy-lab/benchexec
#
# SPDX-FileCopyrightText: 2007-2020 <NAME> <https://www.sosy-lab.org>
#
# SPDX-License-Identifier: Apache-2.0

import argparse
import contextlib
import logging
import inspect
import os
import sys

import benchexec
import benchexec.benchexec
from benchexec import model
from benchexec import util
import benchexec.tools.template

sys.dont_write_bytecode = True  # prevent creation of .pyc files

COLOR_RED = "\033[31;1m"
COLOR_GREEN = "\033[32;1m"
COLOR_ORANGE = "\033[33;1m"
COLOR_MAGENTA = "\033[35;1m"

if util.should_color_output():
    COLOR_DEFAULT = "\033[m"
    COLOR_DESCRIPTION = COLOR_MAGENTA
    COLOR_VALUE = COLOR_GREEN
    COLOR_WARNING = COLOR_RED
else:
    COLOR_DEFAULT = ""
    COLOR_DESCRIPTION = ""
    COLOR_VALUE = ""
    COLOR_WARNING = ""


def print_value(description, value, extra_line=False):
    print(
        "{}{}{}:{}“{}{}{}”".format(
            COLOR_DESCRIPTION,
            description,
            COLOR_DEFAULT,
            "\n\t" if extra_line else " ",
            COLOR_VALUE,
            value,
            COLOR_DEFAULT,
        ),
        file=sys.stderr,
    )


def print_list(description, value):
    print_value(description, list(value), extra_line=True)


def print_multiline_list(description, values):
    print(
        "{}{}{}:".format(COLOR_DESCRIPTION, description, COLOR_DEFAULT), file=sys.stderr
    )
    for value in values:
        print("\t“{}{}{}”".format(COLOR_VALUE, value, COLOR_DEFAULT), file=sys.stderr)


def print_multiline_text(description, value):
    if value is None:
        print(
            "{}{}{}: {}None{}".format(
                COLOR_DESCRIPTION,
                description,
                COLOR_DEFAULT,
                COLOR_WARNING,
                COLOR_DEFAULT,
            ),
            file=sys.stderr,
        )
    elif not value.strip():
        print(
            "{}{}{}: {}“{}”{}".format(
                COLOR_DESCRIPTION,
                description,
                COLOR_DEFAULT,
                COLOR_WARNING,
                value,
                COLOR_DEFAULT,
            ),
            file=sys.stderr,
        )
    else:
        print(
            "{}{}{}:".format(COLOR_DESCRIPTION, description, COLOR_DEFAULT),
            file=sys.stderr,
        )
        for line in value.splitlines():
            print("\t{}{}{}".format(COLOR_VALUE, line, COLOR_DEFAULT), file=sys.stderr)


@contextlib.contextmanager
def log_if_unsupported(msg):
    """Catch any exception in block and log it with a message about an unsupported feature"""
    try:
        yield  # call code block to be executed
    except BaseException as e:
        logging.warning(
            "Tool-info module does not support %s: “%s”",
            msg,
            e,
            exc_info=not isinstance(
                e, benchexec.tools.template.UnsupportedFeatureException
            ),
        )


def print_tool_info(tool):
    print_multiline_text("Documentation of tool module", inspect.getdoc(tool))

    print_value("Name of tool", tool.name())

    executable = tool.executable()
    print_value("Executable", executable)
    if not os.path.isabs(executable):
        print_value("Executable (absolute path)", os.path.abspath(executable))
    else:
        logging.warning(
            "Path to executable is absolute, this might be problematic "
            "in scenarios where runs are distributed to other machines."
        )
    if os.path.isdir(executable):
        logging.warning("Designated executable is a directory.")
    elif not os.path.isfile(executable):
        logging.warning("Designated executable does not exist.")
    elif not os.access(executable, os.X_OK):
        logging.warning("Designated executable is not marked as executable.")

    try:
        print_value("Version", tool.version(executable))
    except:  # noqa: E722
        logging.warning("Determining version failed:", exc_info=1)

    working_directory = tool.working_directory(executable)
{'fraction_non_alphanumeric': 0.11067593177511055, 'fraction_numerical': 0.010360075805432722, 'mean_word_length': 2.3857998289136013, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5600517', 'n_tokens_mistral': 2439, 'n_tokens_neox': 2283, 'n_words': 536}