PyTraceToIX Module
- pytracetoix.Allow_Result
Format Type – Defines how result and input values will be formatted.
- Parameters:
result – The format of the result value to be displayed. Defaults to ‘{name}:{value}’.
input – The format of the input value to be displayed. Defaults to ‘{name}:{value}’.
thread – The format of the thread id format to be displayed. Defaults to ‘{id}: ‘.
sep – The separator text between each input and the result. Defaults to ‘ | ‘.
new_line – If True it will add a new line at the end of output.
alias of
bool
|Any
- pytracetoix.c__(value: Any, name: str | Callable[[int, int, Any], str] = None, allow: bool | Callable[[int, str, Any], str] | Any = True, level: int = 0)[source]
Captures the input value for the current thread.
If no name is provided, it generates a default name.
- Parameters:
value (Any) – The input value to store.
name (Union[str, Callable[[int, int, Any], str]], optional) – The name of the input. Defaults to ‘i%d’ where %d is the number of inputs for the thread.
allow (Callable[[int, str, Any], str]], optional) – A function or value to allow tracing the input. allow is called before name. If it returns a boolean, it will allow or disallow respectively. Otherwise it will display the allow result instead of the input value.
level (int, optional) – The level number to be used when there is more than one d__ within the same expression or function. Defaults to 0.
- Returns:
value
Examples
>>> c__(x)
>>> c__(x, name="var-name") >>> c__(x, name=lambda index, allow_index, value: f"{index}")
>>> [c__(i, allow=lambda index, name, value: index > 2) for i in range(5)] >>> [c__(x, allow=lambda index, name, value: value == 20) for x in [10, 20, 30]]
>>> z = d__(c__(outside_1) + y * c__(outside_2) + d__(k * c__(inside(5), level=1)))
- pytracetoix.d__(value: Any, name: str = '_', allow: Callable[[Dict[str, Any]], bool | Any] = None, before: Callable[[Dict[str, Any]], bool] = None, after: Callable[[Dict[str, Any]], None] = None, inputs: Dict[str, Any] = None, format: Dict[str, str | bool] = None)[source]
Displays formatted result and inputs for the current thread using a given format.
Optionally calls allow, before and after functions with the data.
- allow, before and after will receive a parameter data with the allowed inputs.
With the following meta values:
meta__: List of meta keys including the name key.
thread_id__: Id of the thread being executed.
allow_input_count__: Total number of inputs that are allowed.
input_count__: Total number of inputs being captured.
allow__: If false it was allowed. Use this for after callback.
output__: Text passed to before without new_line.
name: value parameter.
- Parameters:
value (Any) – The result to trace.
name (str, optional) – The name of the function being traced. Defaults to ‘_’.
allow (Callable[[Dict[str, Any]], bool], optional) – A function to call to allow tracing. If it returns False, tracing is skipped but after is still called. If it returns not bool, then it will display the allow result instead of the result.
before (Callable[[Dict[str, Any]], bool], optional) – A function to call before displaying the output. If it returns False, tracing is skipped.
after (Callable[[Dict[str, Any]], None], optional) – A function to call after displaying the output. After is always called even if not allow.
inputs (Dict[str, Any], optional) – Dictionary of additional inputs.
format (Format, optional) – Alternative output format.
- Returns:
value
Examples
>>> d__(x) >>> d__(c__(x) + c__(y))
>>> d__(c__(x) + c__(y, name="y"), name="output")
>>> d__(c__(x) + c__(y), allow=lambda data: data['input_count__'] == 2) >>> d__(c__(x) + c__(y), allow=lambda data: data['i0'] == 10.0) >>> d__(c__(x, allow=lambda index, name, value: value > 10) + c__(y), allow=lambda data: data['allow_input_count__'] == 2)
>>> d__([c__(x) for x in ['10', '20']], before=lambda data: '10' in data['output__'])
>>> d__([c__(x) for x in ['1', '2']], allow=lambda data: data['allow_input_count__'] == 2, after=lambda data: call_after(data) if data['allow__'] else "")
- pytracetoix.init__(stream: Any = None, multithreading: bool = False, format: Dict[str, str | bool] = {'input': '{name}:`{value}`', 'new_line': True, 'result': '{name}:`{value}`', 'sep': ' | ', 'thread': '{id}: '}, enabled=True)[source]
Initializes global settings of the tracing tool.
- Parameters:
stream (stream, optional) – The output stream to write the output lines. Defaults to sys.stdout.
multithreading (bool, optional) – If True, it prefixes the output with thread_id:. Defaults to False.
format (Format, optional) – Format dictionary. Defaults to DEFAULT_FORMAT.
enabled (bool) – If False, it disables t__, c__ and d__. Defaults to True.
- pytracetoix.t__(name: str = None, thread_id: int = None)[source]
Assigns a name to a thread.
If no name is provided, it generates a name based on the number of threads.
If no thread_id is provided, uses the current thread ID.
- Parameters:
name (str, optional) – The name for the thread. Defaults to ‘t%d’ where %d is the number of threads.
thread_id (int, optional) – The ID of the thread. Defaults to the current thread ID.