knitout_interpreter.knitout_operations.Header_Line module

Module containing the classes for Header Lines in Knitout

class Knitout_Header_Line_Type(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of properties that can be set in the header.

Machine = 'machine'
Gauge = 'gauge'
Position = 'position'
Carriers = 'carrier_count'
Knitout_Version = 'version'
get_specification_value(specification)[source]
Parameters:

specification (Knitting_Machine_Specification) – The specification to retrieve the value associated with this header line type.

Returns:

Return the value in the specification associated with this header type.

Return type:

Knitting_Machine_Type | int | Knitting_Position

property specification_keyword: str

Returns: str: The keyword to initialize this value in a Knitting_Machine_Specification.

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 Knitout_Header_Line(*args, **kwargs)[source]

Bases: Knitout_Line

__init__(header_type, header_value, comment=None)[source]
Parameters:
  • header_type (Knitout_Header_Line_Type) – The type of value set by this header line.

  • header_value (Knitting_Machine_Type | int | Knitting_Position) – The value set by this header line.

  • comment (str, optional) – Additional details in the comments. Defaults to no comment.

property header_type: Knitout_Header_Line_Type

Returns: Knitout_Header_Line_Type: The type of value to be changed by this header line.

property header_value: Knitting_Machine_Type | int | Knitting_Position

Returns: Knitting_Machine_Type | int | Knitting_Position: The value set by this header line.

value_matches_spec(specification)[source]
Parameters:

specification (Knitting_Machine_Specification) – The machine specification to compare this header line to.

Returns:

True if the given header value matches the value in the given specification.

Return type:

bool

updates_machine_state(machine_state)[source]

Check if this header would update the given machine state.

Parameters:

machine_state (Knitting_Machine) – The machine state to check against.

Returns:

True if this header would update the given machine state, False otherwise.

Return type:

bool

execute(machine_state)[source]

Execute the instruction on the machine state.

Parameters:

machine_state (Knitting_Machine) – The knitting machine state to update.

Returns:

True if the process completes an update. False, otherwise.

Return type:

bool

__eq__(other)[source]
Parameters:

other (Knitout_Header_Line) – The other header line to compare to.

Returns:

True if other is of the same type and share the same header values.

Return type:

bool

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = False
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

class Knitout_Version_Line(*args, **kwargs)[source]

Bases: Knitout_Header_Line

Represents a knitout version specification line.

__init__(version=2, comment=None)[source]

Initialize a version line.

Parameters:
  • version (int, optional) – The knitout version number. Defaults to 2.

  • comment (str, optional) – Optional comment for the version line.

property version: int

Returns: int: The version of knitout to use in the program.

__eq__(other)
Parameters:

other (Knitout_Header_Line) – The other header line to compare to.

Returns:

True if other is of the same type and share the same header values.

Return type:

bool

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

execute(machine_state)

Execute the instruction on the machine state.

Parameters:

machine_state (Knitting_Machine) – The knitting machine state to update.

Returns:

True if the process completes an update. False, otherwise.

Return type:

bool

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

property header_type: Knitout_Header_Line_Type

Returns: Knitout_Header_Line_Type: The type of value to be changed by this header line.

property header_value: Knitting_Machine_Type | int | Knitting_Position

Returns: Knitting_Machine_Type | int | Knitting_Position: The value set by this header line.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = False
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

updates_machine_state(machine_state)

Check if this header would update the given machine state.

Parameters:

machine_state (Knitting_Machine) – The machine state to check against.

Returns:

True if this header would update the given machine state, False otherwise.

Return type:

bool

value_matches_spec(specification)
Parameters:

specification (Knitting_Machine_Specification) – The machine specification to compare this header line to.

Returns:

True if the given header value matches the value in the given specification.

Return type:

bool

comment: str | None
class Machine_Header_Line(*args, **kwargs)[source]

Bases: Knitout_Header_Line

__init__(machine_type, comment=None)[source]
Parameters:
  • machine_type (str) – The name of the type of machine the knitout should be executed on.

  • comment (str, optional) – Additional details in the comments. Defaults to no comment.

property machine_type: Knitting_Machine_Type

Returns: Knitting_Machine_Type: The type of machine the header line is set to.

__eq__(other)
Parameters:

other (Knitout_Header_Line) – The other header line to compare to.

Returns:

True if other is of the same type and share the same header values.

Return type:

bool

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

execute(machine_state)

Execute the instruction on the machine state.

Parameters:

machine_state (Knitting_Machine) – The knitting machine state to update.

Returns:

True if the process completes an update. False, otherwise.

Return type:

bool

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

property header_type: Knitout_Header_Line_Type

Returns: Knitout_Header_Line_Type: The type of value to be changed by this header line.

property header_value: Knitting_Machine_Type | int | Knitting_Position

Returns: Knitting_Machine_Type | int | Knitting_Position: The value set by this header line.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = False
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

updates_machine_state(machine_state)

Check if this header would update the given machine state.

Parameters:

machine_state (Knitting_Machine) – The machine state to check against.

Returns:

True if this header would update the given machine state, False otherwise.

Return type:

bool

value_matches_spec(specification)
Parameters:

specification (Knitting_Machine_Specification) – The machine specification to compare this header line to.

Returns:

True if the given header value matches the value in the given specification.

Return type:

bool

comment: str | None
class Gauge_Header_Line(*args, **kwargs)[source]

Bases: Knitout_Header_Line

__init__(gauge, comment=None)[source]
Parameters:
  • gauge (int) – The number of needles per inch on the knitting machine.

  • comment (str, optional) – Additional details in the comments. Defaults to no comment.

property gauge: int

Returns: int: The Gauge value set by this header line.

__eq__(other)
Parameters:

other (Knitout_Header_Line) – The other header line to compare to.

Returns:

True if other is of the same type and share the same header values.

Return type:

bool

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

execute(machine_state)

Execute the instruction on the machine state.

Parameters:

machine_state (Knitting_Machine) – The knitting machine state to update.

Returns:

True if the process completes an update. False, otherwise.

Return type:

bool

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

property header_type: Knitout_Header_Line_Type

Returns: Knitout_Header_Line_Type: The type of value to be changed by this header line.

property header_value: Knitting_Machine_Type | int | Knitting_Position

Returns: Knitting_Machine_Type | int | Knitting_Position: The value set by this header line.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = False
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

updates_machine_state(machine_state)

Check if this header would update the given machine state.

Parameters:

machine_state (Knitting_Machine) – The machine state to check against.

Returns:

True if this header would update the given machine state, False otherwise.

Return type:

bool

value_matches_spec(specification)
Parameters:

specification (Knitting_Machine_Specification) – The machine specification to compare this header line to.

Returns:

True if the given header value matches the value in the given specification.

Return type:

bool

comment: str | None
class Position_Header_Line(*args, **kwargs)[source]

Bases: Knitout_Header_Line

__init__(position, comment=None)[source]
Parameters:
  • position (str | Knitting_Position) – Indicates the position of the knitting area on the needle beds.

  • comment (str, optional) – Additional details in the comments. Defaults to no comment.

property position: Knitting_Position

Returns: Knitting_Position: The position of the knitting area on the needle beds.

__eq__(other)
Parameters:

other (Knitout_Header_Line) – The other header line to compare to.

Returns:

True if other is of the same type and share the same header values.

Return type:

bool

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

execute(machine_state)

Execute the instruction on the machine state.

Parameters:

machine_state (Knitting_Machine) – The knitting machine state to update.

Returns:

True if the process completes an update. False, otherwise.

Return type:

bool

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

property header_type: Knitout_Header_Line_Type

Returns: Knitout_Header_Line_Type: The type of value to be changed by this header line.

property header_value: Knitting_Machine_Type | int | Knitting_Position

Returns: Knitting_Machine_Type | int | Knitting_Position: The value set by this header line.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = False
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

updates_machine_state(machine_state)

Check if this header would update the given machine state.

Parameters:

machine_state (Knitting_Machine) – The machine state to check against.

Returns:

True if this header would update the given machine state, False otherwise.

Return type:

bool

value_matches_spec(specification)
Parameters:

specification (Knitting_Machine_Specification) – The machine specification to compare this header line to.

Returns:

True if the given header value matches the value in the given specification.

Return type:

bool

comment: str | None
class Carriers_Header_Line(*args, **kwargs)[source]

Bases: Knitout_Header_Line

__init__(carrier_ids=10, comment=None)[source]
Parameters:
  • carrier_ids (list[int] | int | Yarn_Carrier_Set | Yarn_Carrier) – Indicates the carriers available on the knitting machine when executing the knitting program.

  • comment (str, optional) – Additional details in the comments. Defaults to no comment.

property carrier_count: int

Returns: int: The number of carriers on this machine.

property carrier_str: str

Returns: str: The string of carriers used to initialize the header string.

__eq__(other)
Parameters:

other (Knitout_Header_Line) – The other header line to compare to.

Returns:

True if other is of the same type and share the same header values.

Return type:

bool

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

execute(machine_state)

Execute the instruction on the machine state.

Parameters:

machine_state (Knitting_Machine) – The knitting machine state to update.

Returns:

True if the process completes an update. False, otherwise.

Return type:

bool

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

property header_type: Knitout_Header_Line_Type

Returns: Knitout_Header_Line_Type: The type of value to be changed by this header line.

property header_value: Knitting_Machine_Type | int | Knitting_Position

Returns: Knitting_Machine_Type | int | Knitting_Position: The value set by this header line.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = False
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

updates_machine_state(machine_state)

Check if this header would update the given machine state.

Parameters:

machine_state (Knitting_Machine) – The machine state to check against.

Returns:

True if this header would update the given machine state, False otherwise.

Return type:

bool

value_matches_spec(specification)[source]
Parameters:

specification (Knitting_Machine_Specification) – The machine specification to compare this header line to.

Returns:

True if the given header value matches the value in the given specification.

Return type:

bool

comment: str | None