knitout_interpreter.debugger.knitout_debugger module
Module containing the Knitout_Debugger class.
- class Debug_Mode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumEnumeration of stepping modes for the debugger
- Step_Instruction = 'step-instruction'
- Continue = 'continue'
- Step_Carriage_Pass = 'step-carriage-pass'
- classmethod __contains__(member)
Return True if member is a member of this enum raises TypeError if member is not an enum member
note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum
- classmethod __getitem__(name)
Return the member matching name.
- classmethod __iter__()
Return members in definition order.
- classmethod __len__()
Return the number of members (no aliases)
- class Debuggable_Knitout_Execution(*args, **kwargs)[source]
Bases:
Machine_Component[Knitout_LoopT],ProtocolA protocol for knitout execution processes that can be debugged by the Knitout_Debugger class.
- executed_instructions: Knitout_Program
- debugger: Knitout_Debugger | None
- property starting_new_carriage_pass: bool
Returns: bool: True if the next instruction to be processed will initiate a new carriage pass, False otherwise.
- property knitting_machine: Knitout_Knitting_Machine[Knitout_LoopT]
Returns: Knitout_Knitting_Machine[Knitout_LoopT]: The knitting machine that the program is executing on.
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- __init__(*args, **kwargs)
- handle_violations(response_policy=None, handler=None)
Context manager that catches exceptions and routes them through the violation policy.
- Parameters:
response_policy (ViolationResponse | Violation, optional) – The ViolationResponse policy for this code block. If given a Violation, the response will be the policy assigned to that violation in the violation policy. Defaults to the response will be the default response of the violation policy.
handler (Callable[..., Any], optional) – Optional handler to attempt before falling back to the policy response.
- property machine_is_all_needle_racked: bool
Returns: bool: True if the knitting machine is racked for all needle knitting.
- property machine_specification: Knitting_Machine_Specification
Returns: Knitting_Machine_Specification: The machine specification of the machine associated with this component.
- property needle_count_of_machine: int
Returns: int: The number of needles on each bed of the knitting machine. Defaults to the bed size in the knitting machine specification.
- property rightmost_slot_on_machine: int
Returns: int: The rightmost slot on this knitting machine. Defaults to the standard bed size in the knitting machine specification.
- set_response_for(violation, response=None)
Sets the response for the given violation to the given response.
- Parameters:
violation (Violation) – The violation to set the response for.
response (ViolationResponse, optional) – The response to set for the given violation. Defaults to the default response of this policy.
- property violation_policy: Knitting_Machine_Error_Policy
Returns: Knitting_Machine_Error_Policy: The policy for handling machine state errors.
- class Knitout_Debugger[source]
Bases:
objectDebugger for knitout execution with breakpoints and stepping.
- machine_snapshots
Dictionary mapping line numbers that were paused on to the state of the knitting machine at that line.
- attach_executer(executer)[source]
Attaches the given executer to this debugger.
- Parameters:
executer (Knitout_Executer) – The executer to attach to this debugger.
- property take_step: bool
Returns: bool: True if the debugger is set to step on every instruction line. False, otherwise.
- property take_carriage_pass_step: bool
Returns: bool: True if the debugger is set to step until the end of the current carriage pass. False, otherwise.
- property continue_to_end: bool
Returns: bool: True if the debugger is set to continue to the next active breakpoint. False, otherwise.
- property taking_snapshots: bool
- Returns:
True if the debugger is set to take snapshots of the knitting machine state when paused. False, otherwise.
- Return type:
Notes
Snapshots are stored in the debugger’s machine_snapshots dictionary.
- property stop_on_condition_errors: bool
Returns: bool: True if the debugger will stop when conditions trigger an exception. False, otherwise.
- property knitting_machine: Knitout_Knitting_Machine | None
Returns: Knitout_Knitting_Machine | None: The knitting machine the debugged process is running on or None if it has no debugging process.
- step(step_carriage_passes_only=False)[source]
Sets the debugger to a stepping mode. By default, enter instruction level step mode. :param step_carriage_passes_only: If True, debugger set to step over carriage passes, instead of every line. Defaults to stepping every line (False). :type step_carriage_passes_only: bool, optional
- step_carriage_pass()[source]
Sets the debugger to step over each carriage pass unless a breakpoint is hit inside the carriage pass.
- continue_knitout()[source]
Sets the debugger to continue to the next breakpoint or end of the knitout program.
- enable_snapshots()[source]
Sets the debugger to take snapshots of the knitting machine state whenever it pauses.
- ignore_condition_exceptions()[source]
Sets the debugger to ignore condition exceptions and continue over these breakpoints.
- pause_on_condition_exceptions()[source]
Sets the debugger to stop when a breakpoint condition raises an exception.
- disable_breakpoint(line_number)[source]
Sets the debugger to ignore any breakpoint at the given line number.
- Parameters:
line_number (int) – The line number of the breakpoint to ignore.
- enable_breakpoint(line_number)[source]
Allows the debugger to consider the breakpoint at the given line number. If a breakpoint was not already present, a breakpoint with no condition is set.
- Parameters:
line_number (int) – The line number of the breakpoint to consider.
- enable_step_condition(name, condition, is_carriage_pass_step=False)[source]
Adds the given condition to the debugger.
- Parameters:
name (str) – The unique name of the condition, used to deactivate it.
condition (Callable[[Knitout_Debugger, Knitout_Comment_Line | Knitout_Instruction], bool]) – The condition to be tested for pausing.
is_carriage_pass_step (bool, optional) – If true, only sets the condition on carriage pass steps. Defaults to setting the condition for all steps.
- disable_condition(name, disable_steps=True, disable_carriage_pass=True)[source]
Removes any step conditions by the given name.
- Parameters:
name (str) – The name of the condition to deactivate. If no condition exists by that name, nothing will happen.
disable_steps (bool, optional) – If True, disables condition on stepping. Defaults to True.
disable_carriage_pass (bool, optional) – If True, disables condition on carriage pass steps. Defaults to True.
- property has_step_conditions: bool
Returns: bool: True if the debugger has one or more conditions applied to it pausing at each step. False, otherwise.
- property has_carriage_pass_conditions: bool
Returns: bool: True if the debugger has one or more conditions applied to pausing at the beginning of a carriage pass. False, otherwise.
- meets_carriage_pass_conditions(instruction)[source]
- Parameters:
instruction (Knitout_Comment_Line | Knitout_Instruction) – The instruction to consider pausing before.
- Returns:
True if the all step-carriage-pass conditions are met or a condition error is encountered. False, otherwise.
- Return type:
- pause_on_step(instruction)[source]
- Parameters:
instruction (Knitout_Comment_Line | Knitout_Instruction) – The instruction to pause before.
- Returns:
True if the debugger should pause before the next instruction because of step-mode. False, otherwise.
- Return type:
- pause_on_carriage_pass(instruction)[source]
- Parameters:
instruction (Knitout_Comment_Line | Knitout_Instruction) – The instruction to pause before.
- Returns:
True if the debugger should pause before the next instruction because of step-carriage-pass-mode. False, otherwise.
- Return type:
- should_break(instruction)[source]
- Parameters:
instruction (Knitout_Comment_Line | Knitout_Instruction) – The instruction or comment that is about to be executed.
- Returns:
True if the debugger should pause execution given the current state of the knitting machine and upcoming instruction. False otherwise.
- Return type:
- debug_instruction(knitout_instruction)[source]
The debugging protocol given the state of the debugger and the instruction about to be executed.
- Parameters:
knitout_instruction (Knitout_Comment_Line | Knitout_Instruction) – The knitout instruction to pause the debugger on or continue.
- debug_exception(knitout_instruction, exception)[source]
Trigger a breakpoint immediately after a knitout instruction causes an exception. Raise the exception after the debugger continues.
- Parameters:
knitout_instruction (Knitout_Comment_Line | Knitout_Instruction) – The knitout instruction that triggered the exception.
exception (BaseException) – The exception that the debugger will pause on.