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:
ABCAbstract 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.
- 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,BaseConfigConfiguration 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)
- direct_write: DirectWrite
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class vpype_gscrib.config.ConfigLoader(command: Command)
Bases:
objectUtility 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]
- class vpype_gscrib.config.ConfigOption(option_name: str, **kwargs)
Bases:
OptionCustom 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
- class vpype_gscrib.config.LengthFieldInfo(default: float, units: str, **kwargs: Any)
Bases:
FieldInfoField info for length values that stores length units.
- default: Any
- evaluated
- class vpype_gscrib.config.PathFieldInfo(default: float | None, **kwargs: Any)
Bases:
FieldInfoField info for file path values.
- default: Any
- evaluated
- 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,BaseConfigConfiguration 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.
- coolant_type: CoolantType
- length_units: LengthUnits
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- power_mode: PowerMode
- spin_mode: SpinMode
- time_units: TimeUnits