knit_script.knit_script_interpreter.scope.machine_scope module

Scope of machine variables.

This module provides the Machine_Scope class, which manages machine state and configuration within different execution scopes of a knit script program. It tracks machine settings like carriage direction, active carriers, racking position, gauge configuration, and active sheets while automatically generating appropriate knitout instructions when these settings change. The machine scope integrates with the broader scoping system to provide proper inheritance and isolation of machine state across different program contexts.

class Machine_Scope(context, prior_settings=None)[source]

Bases: object

Keeps track of the machine state within different scopes.

The Machine_Scope class manages knitting machine configuration and state within a specific execution scope. It tracks essential machine parameters including carriage direction, active yarn carriers, racking position, gauge settings, and active sheet configuration. When these parameters are modified, the class automatically generates the appropriate knitout instructions to implement the changes on the physical machine.

This class provides scope-aware machine state management, allowing different parts of a knit script program to have different machine configurations while maintaining proper inheritance and isolation. It integrates with the gauged sheet system to handle complex multi-sheet knitting operations and ensures that machine state changes are properly reflected in the generated knitout code.

__init__(context, prior_settings=None)[source]

Initialize the machine scope with default settings or inherited from prior scope.

Creates a new machine scope with default machine settings, then optionally inherits settings from a parent scope. This allows child scopes to start with the same machine configuration as their parent while maintaining the ability to make local changes.

Parameters:
  • context (Knit_Script_Context) – The execution context that this machine scope operates within.

  • prior_settings (Machine_Scope | None, optional) – A parent machine scope to inherit settings from. If provided, all machine settings will be copied from this scope. Defaults to None.

property machine_state: Knitting_Machine

Get the current machine state in the current context.

Returns:

The current machine state in the current context.

Return type:

Knitting_Machine

property direction: Carriage_Pass_Direction

Get the current direction the carriage will take.

Returns:

The current direction the carriage will take.

Return type:

Carriage_Pass_Direction

property Carrier: Yarn_Carrier_Set | None

Get the current carrier being used by the machine.

Returns:

The current carrier being used by the machine, or None if no carrier is active.

Return type:

Yarn_Carrier_Set | None

property last_working_carrier: Yarn_Carrier_Set | None

Returns: Yarn_Carrier_Set | None: The explicitly set working carrier or the active carrier with the most recently formed loop or None if there are no active carriers.

property Racking: float

Returns: float: Current racking of the machine as a floating-point value.

property Rack: float

Returns: float: Current racking of the machine as a floating-point value.

property gauged_sheet_record: Gauged_Sheet_Record

Get the gauged sheet record associated with this machine scope.

Returns:

The gauged sheet record associated with this machine scope, which tracks loop positions and sheet organization.

Return type:

Gauged_Sheet_Record

property Gauge: int

Get the current number of sheets on the machine.

Returns:

The current number of sheets on the machine.

Return type:

int

property Sheet: Sheet_Identifier

Get the current sheet being worked on the machine.

Returns:

The current sheet being worked on the machine.

Return type:

Sheet_Identifier

inherit_from_scope(scope, inherit_raw_values=False)[source]

Set the machine scope values based on the given scope.

Copies all machine configuration settings from the specified scope to this scope, including direction, carrier, racking, gauge, sheet, and gauged sheet record. This method is used to establish initial settings when creating child scopes.

Parameters:
  • inherit_raw_values (bool) – If true, don’t use the property setters which may modify the knitout.

  • scope (Machine_Scope) – The machine scope to inherit the values from.

update_parent_machine_scope(parent_scope)[source]

Passes machine status values up to the given parent scope with the following effects: * Resets the rack of the machine to the racking value of the parent scope. * Sets the direction of the parent scope to match the direction of this scope. * Update the sheet to the sheet in the parent scope. * Update the gauge sheet record of the parent to reflect the current state.

Parameters:

parent_scope (Machine_Scope) – The parent machine scope to pass values up to.

__contains__(variable_name)[source]
Parameters:

variable_name (str) – The variable to search for in the machine scope.

Returns:

True if the variable name is a machine scope property, False otherwise.

Return type:

bool

__getitem__(variable_name)[source]
Parameters:

variable_name (str) – The variable to get from the machine scope.

Returns:

The value to return from the machine scope. * Sheet will return a Sheet_Identifier. * Gauge will return an integer. * Racking or Rack will return a float. * Carrier will return a Yarn_Carrier_Set or None if there is not working carrier. * Direction will return a Carriage_Pass_Direction. * machine_state will return the current knitting machine state.

Return type:

Sheet_Identifier | int | float | Yarn_Carrier_Set | Carriage_Pass_Direction | Knitting_Machine | None

Raises:

AttributeError – If the variable name is not a machine scope variable.

__setitem__(variable_name, value)[source]

Sets the given value to the specified machine scope variable. :param variable_name: The variable to set to the machine scope. Expects: Sheet, Gauge, Rack, Racking, Carrier, or Direction. :type variable_name: str :param value: The value to set the specified variable. :type value: int | float | Sheet_Identifier | Sequence[int | Yarn_Carrier] | Yarn_Carrier_Set | Yarn_Carrier | Carriage_Pass_Direction | None

Raises:

AttributeError – If the variable name is not a machine scope variable.