vpype_gscrib.config

TOML and command-line configuration utilities.

This module provides a robust system for managing and validating configuration settings. Its main purpose is to ensure consistency and correctness when parsing and applying configuration data from both command-line inputs and TOML files.

class vpype_gscrib.config.BaseConfig

Bases: ABC

Abstract base class defining the interface for configuration objects.

classmethod validate_ge(model: BaseConfig, f1: str, f2: str)

Validate a field value is greater or equal to another.

classmethod validate_gt(model: BaseConfig, f1: str, f2: str)

Validate a field value is greater than another.

format_values(units: LengthUnits) Dict[str, str]

Format configuration values for display.

If applicable, numeric values are scaled to the given units, rounded to 6 decimal places and their units appended if the field is of type LengthField.

Parameters:

units (LengthUnits) – The work units to use for formatting.

Returns:

A dictionary containing the formatted configuration values.

Return type:

Dict[str, str]

class vpype_gscrib.config.BuilderConfig(*, output: str | None = None, decimal_places: Annotated[int, Ge(ge=0)] = 5, comment_symbols: str = '(', line_endings: str = 'os', print_lines: bool | str = False, direct_write: DirectWrite = DirectWrite.OFF, host: str = 'localhost', port: str = '8000', baudrate: Annotated[int, Ge(ge=0)] = 250000, x_axis: str = 'X', y_axis: str = 'Y', z_axis: str = 'Z')

Bases: BaseModel, BaseConfig

Configuration settings for the G-code builder.

This class stores various options that are passed directly to the GCodeBuilder instance, which is responsible for generating the G-Code. See the command line reference for detailed information about the properties of this class.

Example

>>> params = { 'output': 'output.gcode' }
>>> builder_config = BuilderConfig.model_validate(params)
>>> print(builder_config.output)
baudrate: int
comment_symbols: str
decimal_places: int
direct_write: DirectWrite
host: str
line_endings: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

output: str | None
port: str
print_lines: bool | str
x_axis: str
y_axis: str
z_axis: str
class vpype_gscrib.config.ConfigLoader(command: Command)

Bases: object

Utility class for loading and parsing configuration files.

This class manages the loading of settings from TOML files and validates the configuration against the expected schema.

read_config_file(path: str, document: Document) List[RenderConfig]

Read and process a configuration file for all document layers.

Loads the TOML configuration file and processes both document level and layer-specific configurations. A RenderConfig list is returned, where the first element is the document-level configuration followed by layer-specific configs.

Parameters:
  • path (str) – Path to the TOML configuration file.

  • document (Document) – Document instance

Returns:

List of RenderConfig objects

Return type:

List[RenderConfig]

validate_config(config: dict) dict

Validate configuration parameters from a dictionary.

Processes and validates configuration parameters using Click’s type system and command parameters. Each value is validated and converted according to its corresponding parameter type.

Parameters:

config (dict) – Dictionary of configuration parameters

Returns:

Validated and processed configuration parameters.

Return type:

dict

class vpype_gscrib.config.ConfigOption(option_name: str, **kwargs)

Bases: Option

Custom click option class that enforces units for length types and provides enhanced parameter handling.

This class extends click’s Option class to provide:

  • Automatic unit enforcement for length parameters

  • Enhanced help text formatting

  • Support for enum choices

  • Default value handling from configuration

Parameters:
  • name (str) – The name of the option

  • **kwargs – Additional arguments passed to parent Option

override_default_value(default_value: Any) None

Override the default value for the option.

class vpype_gscrib.config.LengthFieldInfo(default: float, units: str, **kwargs: Any)

Bases: FieldInfo

Field info for length values that stores length units.

alias: str | None
alias_priority: int | None
annotation: type[Any] | None
default: Any
default_factory: Callable[[], Any] | Callable[[dict[str, Any]], Any] | None
deprecated: Deprecated | str | bool | None
description: str | None
discriminator: str | types.Discriminator | None
evaluated
examples: list[Any] | None
exclude: bool | None
field_title_generator: Callable[[str, FieldInfo], str] | None
frozen: bool | None
init: bool | None
init_var: bool | None
json_schema_extra: JsonDict | Callable[[JsonDict], None] | None
kw_only: bool | None
metadata: list[Any]
repr: bool
serialization_alias: str | None
title: str | None
validate_default: bool | None
validation_alias: str | AliasPath | AliasChoices | None
class vpype_gscrib.config.PathFieldInfo(default: float | None, **kwargs: Any)

Bases: FieldInfo

Field info for file path values.

alias: str | None
alias_priority: int | None
annotation: type[Any] | None
default: Any
default_factory: Callable[[], Any] | Callable[[dict[str, Any]], Any] | None
deprecated: Deprecated | str | bool | None
description: str | None
discriminator: str | types.Discriminator | None
evaluated
examples: list[Any] | None
exclude: bool | None
field_title_generator: Callable[[str, FieldInfo], str] | None
frozen: bool | None
init: bool | None
init_var: bool | None
json_schema_extra: JsonDict | Callable[[JsonDict], None] | None
kw_only: bool | None
metadata: list[Any]
repr: bool
serialization_alias: str | None
title: str | None
validate_default: bool | None
validation_alias: str | AliasPath | AliasChoices | None
class vpype_gscrib.config.RenderConfig(*, header_gcode: str | None = None, footer_gcode: str | None = None, length_units: LengthUnits = LengthUnits.MILLIMETERS, time_units: TimeUnits = TimeUnits.SECONDS, coolant_type: CoolantType = CoolantType.OFF, head_type: HeadType = HeadType.STANDARD, rack_type: RackType = RackType.MANUAL, tool_type: ToolType = ToolType.MARKER, bed_type: BedType = BedType.OFF, fan_type: FanType = FanType.OFF, spin_mode: SpinMode = SpinMode.CLOCKWISE, power_mode: PowerMode = PowerMode.CONSTANT, power_level: Annotated[int, Ge(ge=0)] = 50.0, spindle_rpm: Annotated[int, Ge(ge=0)] = 1000, warmup_delay: Annotated[float, Ge(ge=0.001)] = 2.0, tool_number: Annotated[int, Ge(ge=1)] = 1, work_speed: Annotated[float, Ge(ge=0)] = 1889.7637795275593, plunge_speed: Annotated[float, Ge(ge=0)] = 377.9527559055118, travel_speed: Annotated[float, Ge(ge=0)] = 3779.5275590551187, retract_speed: Annotated[float, Ge(ge=0)] = 7937.007874015749, fan_speed: Annotated[int, Ge(ge=0), Le(le=255)] = 255, bed_temperature: int = 60, hotend_temperature: int = 120, work_z: float = 0.0, plunge_z: float = 3.7795275590551185, safe_z: float = 37.795275590551185, park_z: float = 188.9763779527559, nozzle_diameter: Annotated[float, Gt(gt=0)] = 1.5118110236220474, filament_diameter: Annotated[float, Gt(gt=0)] = 6.614173228346457, layer_height: Annotated[float, Gt(gt=0)] = 0.7559055118110237, retract_length: Annotated[float, Ge(ge=0)] = 5.669291338582678, height_map_path: str | None = None, height_map_scale: Annotated[float, Gt(gt=0)] = 1.0, height_map_tolerance: Annotated[float, Ge(ge=0)] = 0.37795275590551186, resolution: Annotated[float, Gt(gt=0)] = 0.37795275590551186)

Bases: BaseModel, BaseConfig

Configuration settings for G-Code generation.

This class defines motion parameters, spindle settings, and Z-axis positions. The default values are chosen to be safe for a variety of CNC machines, including milling machines, pen plotters, laser engravers, and 3D printers. See the command line reference for detailed information about the properties of this class.

Example

>>> params = { 'length_units': 'mm' }
>>> renderer_config = RenderConfig.model_validate(params)
>>> print(renderer_config.length_units)
validate_field_values() BaseConfig

Validate field values are consistent.

bed_temperature: int
bed_type: BedType
coolant_type: CoolantType
fan_speed: int
fan_type: FanType
filament_diameter: float
footer_gcode: str | None
head_type: HeadType
header_gcode: str | None
height_map_path: str | None
height_map_scale: float
height_map_tolerance: float
hotend_temperature: int
layer_height: float
length_units: LengthUnits
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

nozzle_diameter: float
park_z: float
plunge_speed: float
plunge_z: float
power_level: int
power_mode: PowerMode
rack_type: RackType
resolution: float
retract_length: float
retract_speed: float
safe_z: float
spin_mode: SpinMode
spindle_rpm: int
time_units: TimeUnits
tool_number: int
tool_type: ToolType
travel_speed: float
warmup_delay: float
work_speed: float
work_z: float
vpype_gscrib.config.LengthField(default: str, units: str, **kwargs)

Field for length values that stores their values in pixels.

vpype_gscrib.config.PathField(default: str | None, **kwargs)

Field for file path values.