Esempio n. 1
0
def color(the_color, message=''):
    from colorlog.escape_codes import escape_codes, parse_colors

    if not message:
        res = parse_colors(the_color)
    else:
        res = parse_colors(the_color) + message + escape_codes['reset']

    return res
Esempio n. 2
0
def color(the_color, *args, reset=None):
    """Color helper."""
    from colorlog.escape_codes import escape_codes, parse_colors
    try:
        if not args:
            assert reset is None, "You cannot reset if nothing being printed"
            return parse_colors(the_color)
        return parse_colors(the_color) + ' '.join(args) + \
            escape_codes[reset or 'reset']
    except KeyError as k:
        raise ValueError("Invalid color {} in {}".format(str(k), the_color))
Esempio n. 3
0
def color(the_color, *args, reset=None):
    """Color helper."""
    from colorlog.escape_codes import escape_codes, parse_colors
    try:
        if len(args) == 0:
            assert reset is None, "You cannot reset if nothing being printed"
            return parse_colors(the_color)
        return parse_colors(the_color) + ' '.join(args) + \
            escape_codes[reset or 'reset']
    except KeyError as k:
        raise ValueError("Invalid color {} in {}".format(str(k), the_color))
Esempio n. 4
0
def honor_list_request(
    manifest: Manifest, global_config: Namespace
) -> Union[Manifest, int]:
    """If --list was passed, simply list the manifest and exit cleanly.

    Args:
        manifest (~.Manifest): The manifest of sessions to be run.
        global_config (~nox.main.GlobalConfig): The global configuration.

    Returns:
        Union[~.Manifest,int]: ``0`` if a listing is all that is requested,
            the manifest otherwise (to be sent to the next task).
    """
    if not global_config.list_sessions:
        return manifest

    # If the user just asked for a list of sessions, print that
    # and be done.

    print("Sessions defined in {noxfile}:\n".format(noxfile=global_config.noxfile))

    reset = parse_colors("reset") if global_config.color else ""
    selected_color = parse_colors("cyan") if global_config.color else ""
    skipped_color = parse_colors("white") if global_config.color else ""

    for session, selected in manifest.list_all_sessions():
        output = "{marker} {color}{session}{reset}"

        if selected:
            marker = "*"
            color = selected_color
        else:
            marker = "-"
            color = skipped_color

        if session.description is not None:
            output += " -> {description}"

        print(
            output.format(
                color=color,
                reset=reset,
                session=session.friendly_name,
                description=session.description,
                marker=marker,
            )
        )

    print(
        "\nsessions marked with {selected_color}*{reset} are selected, sessions marked with {skipped_color}-{reset} are skipped.".format(
            selected_color=selected_color, skipped_color=skipped_color, reset=reset
        )
    )
    return 0
Esempio n. 5
0
def color(the_color, *args, reset=None):
    """Color helper."""
    # pylint: disable=import-outside-toplevel
    from colorlog.escape_codes import escape_codes, parse_colors

    try:
        if not args:
            assert reset is None, "You cannot reset if nothing being printed"
            return parse_colors(the_color)
        return parse_colors(the_color) + " ".join(args) + escape_codes[reset or "reset"]
    except KeyError as k:
        raise ValueError(f"Invalid color {k!s} in {the_color}") from k
Esempio n. 6
0
def _produce_listing(manifest: Manifest, global_config: Namespace) -> None:
    # If the user just asked for a list of sessions, print that
    # and any docstring specified in noxfile.py and be done. This
    # can also be called if Noxfile sessions is an empty list.

    if manifest.module_docstring:
        print(manifest.module_docstring.strip(), end="\n\n")

    print(f"Sessions defined in {global_config.noxfile}:\n")

    reset = parse_colors("reset") if global_config.color else ""
    selected_color = parse_colors("cyan") if global_config.color else ""
    skipped_color = parse_colors("white") if global_config.color else ""

    for session, selected in manifest.list_all_sessions():
        output = "{marker} {color}{session}{reset}"

        if selected:
            marker = "*"
            color = selected_color
        else:
            marker = "-"
            color = skipped_color

        if session.description is not None:
            output += " -> {description}"

        print(
            output.format(
                color=color,
                reset=reset,
                session=session.friendly_name,
                description=session.description,
                marker=marker,
            ))

    print(
        f"\nsessions marked with {selected_color}*{reset} are selected, sessions marked"
        f" with {skipped_color}-{reset} are skipped.")
Esempio n. 7
0
def color(the_color, message='', reset=None):
    """Color helper."""
    from colorlog.escape_codes import escape_codes, parse_colors
    if not message:
        return parse_colors(the_color)
    return parse_colors(the_color) + message + escape_codes[reset or 'reset']
Esempio n. 8
0
 def color(self, log_colors, level_name):
     """Return escape codes from a ``log_colors`` dict."""
     return parse_colors(log_colors.get(level_name, ""))
Esempio n. 9
0
 def __missing__(self, name):
     try:
         return parse_colors(name)
     except Exception:
         raise KeyError("{} is not a valid record attribute "
                        "or color sequence".format(name))
Esempio n. 10
0
def test_parse_multiple_colors():
    assert parse_colors('bold_red,bg_bold_blue') == '\033[01;31m\033[104m'
Esempio n. 11
0
def test_parse_invalid_colors():
    with pytest.raises(KeyError):
        parse_colors('false')
Esempio n. 12
0
def test_parse_colors():
    assert parse_colors('reset') == '\033[0m'
Esempio n. 13
0
 def __missing__(self, name):
     try:
         return parse_colors(name)
     except Exception:
         raise KeyError("{} is not a valid record attribute "
                        "or color sequence".format(name))
Esempio n. 14
0
 def color(self, log_colors, name):
     """Return escape codes from a ``log_colors`` dict."""
     return parse_colors(log_colors.get(name, ""))
Esempio n. 15
0
def test_parse_multiple_colors():
    assert parse_colors("bold_red,bg_bold_blue") == "\033[01;31m\033[104m"
Esempio n. 16
0
def test_parse_colors():
    assert parse_colors("reset") == "\033[0m"