X(), for low level debugging.
X() is my function for low level ad hoc debug messages.
It takes a message and optional format arguments for use with %.
It is presented here in its own module for reuse:
from cs.x import X
...
X("foo: x=%s, a=%r", x, a)
It normally writes directly to sys.stderr but accepts an optional
keyword argument file to specify a different filelike object.
The following globals further tune its behaviour,
absent the file= parameter:
X_default_colour: if set, messages will be ANSI coloured usingcs.ansi_colour.colouriseX_discard: if true then discard the message. Otherwise write the message tosys.stderr.X_discard's default value isnot sys.stderr.isatty().X_logger: if notNonethen log a warning to that logger.X_via_tty: if true then a pathname to which to append messages.
The following environment variables affect the initial values of the globals:
$CS_X_COLOUR: this setsX_default_colour.$CS_X_LOGGER: if present, an empty value setsX_loggerto the root logger and a nonempty value names a logger.$CS_X_VIA_TTY: if missing or empty,X_via_ttywill be false. Otherwise, if$CS_X_VIA_TTYhas a nonempty value which is a full path to an existing filesystem object (typically a tty) then is will be used forX_via_tty, otherwiseX_via_ttywill be set to'/dev/tty'. This is handy for getting debugging out of test suites, which often divertsys.stderr.
Short summary:
-
X: Unconditionally write the messagemsg. -
Y: Wrapper forX()rendering in yellow.
Functions
X(msg, *args, file=None, colour=None)
Unconditionally write the message msg.
If there are positional arguments after msg,
format msg using %-expansion with those arguments.
Keyword arguments:
file: optional keyword argument specifying the output file.colour: optional text colour. If specified, surround the message with ANSI escape sequences to render the text in that colour.
If file is not None, write to it unconditionally.
Otherwise, the following globals are consulted in order:
X_logger: if notNonethen log a warning to that loggerX_via_tty: if true then append the message to the path it containsX_discard: if true then discard the message Otherwise write the message tosys.stderr.
X_logger is None by default.
X_via_tty is initialised from the environment variable $CS_X_VIA_TTY.
X_discard is true unless sys.stderr.isatty() is true.
Y(msg, *a, **kw)
Wrapper for X() rendering in yellow.
Metadata
Release files for cs-x 20261016.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cs_x-20261016.1.tar.gz | 3.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cs_x-20261016.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.8 kB
Release files / cs_x-20261016.1.tar.gz
| Download URL | cs_x-20261016.1.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
55faf8b021b9a3098f23a45db6b9284cadfff69c28555fbe9795cf53663901d6
|
|
BLAKE2b-256 checksum How to use checksums |
416d5853002a26bd49995856c8161ee4d934719d11cb2db696b1542a8f1f8ac2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / cs_x-20261016.1-py3-none-any.whl
| Download URL | cs_x-20261016.1-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
26b8ad80b79126a101428bd599cc481530f37ac858189304f683fe0887cd6ff4
|
|
BLAKE2b-256 checksum How to use checksums |
acdc7c7d3e57b262524a1b23ed74dde3a7faba1b81771d24d8ce04d381d42206
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|