Printing/Debugging

A Concourse resource is supposed to print output (such as versions and metadata) to stdout, and all debugging messages to stderr. The ConcourseResource class automatically redirects stdout to stderr when running its methods, meaning that all printed output from you (and from your dependencies) automatically ends up in stderr.

Colour

The Concourse web UI will interpret ANSI colour codes, and so a handful of rudimentary functions for formatting with colour are include in concoursetools.colour.

Tip

There are plenty of more mature libraries for printing coloured output, such as termcolor and Rich. Concourse Tools specifically has no external dependencies, and so these must be actively installed and managed by a user.

concoursetools.colour.colourise(string, colour)[source]

Convert a string into a string which will be coloured on print.

This enables coloured output within an f-string or similar. It is not recommended for colouring complete strings, as it is far less efficient than the other functions.

Parameters:
Example:
>>> print(f"Hello {colourise('world', colour=Colour.RED)}")
Return type:

str

concoursetools.colour.colour_print(*values, colour=_NoPrint(), bold=False, underline=False, **print_kwargs)[source]

Print something in colour.

This function behaves exactly like print(), just with more functionality:

Parameters:
Example:
>>> colour_print(1, 2, 3, sep="-", colour=Colour.GREEN)
Return type:

None

concoursetools.colour.print_in_colour(colour, bold=False, underline=False)[source]

Print anything in colour within a context manager.

This is especially useful for colourising output from other external functions which you cannot control.

Parameters:
Example:
>>> with print_in_colour(Colour.BLUE, bold=True):
...     print("Hello!")
Return type:

Generator[None]

Available Colours

All colour arguments are ANSI colour escape codes, but a number of common codes are available as attributes of the Colour class:

class concoursetools.colour.Colour[source]

A few common ANSI colours.

BLUE = '\x1b[94m'
CYAN = '\x1b[96m'
GREEN = '\x1b[92m'
PURPLE = '\x1b[95m'
RED = '\x1b[91m'
YELLOW = '\x1b[93m'