Checker

Checker interface

Proxies for the KiCad design rule checkers.

class edea.kicad.checker.CheckResult(*, source: str, level: Severity, version: str, timestamp: datetime, dr: KicadDRCReporter | None = None, er: KicadERCReporter | None = None)

The result of a KiCad design check.

Parameters:
  • source – The KiCad file got checked.

  • level – The severity.

  • version – The Kiad version used for the check.

  • timestamp – The timestamp of running the checker.

  • dr – The KiCad Design Rule Check (DRC) report.

  • er – The KiCad Electrical Rule Check (ERC) report.

Returns:

The filtered and sorted check result.

source: str
level: Severity
version: str
timestamp: datetime
dr: KicadDRCReporter | None
er: KicadERCReporter | None
classmethod filter_by_level(value: Any) Any

Filters and sorts violations by severity level.

Parameters:

value – The raw check result dictionary.

Returns:

The filtered and sorted check result dictionary.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

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

model_fields: ClassVar[Dict[str, FieldInfo]] = {'dr': FieldInfo(annotation=Union[KicadDRCReporter, NoneType], required=False, default=None), 'er': FieldInfo(annotation=Union[KicadERCReporter, NoneType], required=False, default=None), 'level': FieldInfo(annotation=Severity, required=True), 'source': FieldInfo(annotation=str, required=True), 'timestamp': FieldInfo(annotation=datetime, required=True), 'version': FieldInfo(annotation=str, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

edea.kicad.checker.check(path: Path | str, custom_design_rules_path: Path | None = None, custom_design_rules_url: str | None = None, level: Severity = 'ignore') CheckResult

Checks a KiCad project for design rule violations.

Parameters:
  • path – The directory path or the path of the KiCad project to be checked.

  • custom_design_rules_path – The path to custom design rules file.

  • custom_design_rules_url – The URL to custom design rules file.

  • level – The severity level to filter violations.

Returns:

The check result.

Raises:

FileNotFoundError – If the project files (.kicad_pcb or .kicad_sch) are not found.

edea.kicad.checker.find_design_rules_file(project_path: Path)
edea.kicad.checker.custom_design_rules(custom_rules_path: Path | None, custom_design_rules_url: str | None, project_path: Path)

A context manager that adds the design rules to project and delete it on exiting the context.

Parameters:
  • custom_rules_path – The path to custom design rules file on disk.

  • custom_design_rules_url – The URL to custom design rules file.

  • project_path – The path to the KiCad project.

Raises:
  • FileNotFoundError – If the project file or custom rules file is not found.

  • ValueError – If the custom design rules are not in kicad_dru format.

Yields:

The path to the temporary custom design rules file added to the project.

Design rules checker

Partially generated by datamodel-codegen:

filename: https://gitlab.com/kicad/code/kicad/-/raw/master/resources/schemas/drc.v1.json timestamp: 2024-01-03T16:11:36+00:00

class edea.kicad.checker.drc.KicadDRCReport(*, field_schema: str | None, source: str, date: datetime, kicad_version: str, violations: List[Violation], unconnected_items: List[Violation], schematic_parity: List[Violation], coordinate_units: CoordinateUnits)

Bases: BaseModel

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'populate_by_name': True}

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

field_schema: str | None
source: str
date: datetime
kicad_version: Annotated[str, constr(pattern='^\\d{1,2}(\\.\\d{1,2}(\\.\\d{1,2})?)?$')]
violations: List[Violation]
unconnected_items: List[Violation]
schematic_parity: List[Violation]
coordinate_units: CoordinateUnits
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_fields: ClassVar[Dict[str, FieldInfo]] = {'coordinate_units': FieldInfo(annotation=CoordinateUnits, required=True, description='Units that all coordinates in this report are encoded in'), 'date': FieldInfo(annotation=datetime, required=True, description='Time at generation of report'), 'field_schema': FieldInfo(annotation=Union[str, NoneType], required=True, alias='$schema', alias_priority=2, description='JSON schema reference'), 'kicad_version': FieldInfo(annotation=str, required=True, description='KiCad version used to generate the report', metadata=[typing.Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=None, pattern='^\\d{1,2}(\\.\\d{1,2}(\\.\\d{1,2})?)?$')]]), 'schematic_parity': FieldInfo(annotation=List[Violation], required=True), 'source': FieldInfo(annotation=str, required=True, description='Source file path'), 'unconnected_items': FieldInfo(annotation=List[Violation], required=True), 'violations': FieldInfo(annotation=List[Violation], required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

Electrical rules checker

Partially generated by datamodel-codegen:

filename: https://gitlab.com/kicad/code/kicad/-/raw/master/resources/schemas/erc.v1.json timestamp: 2024-01-04T10:32:53+00:00

class edea.kicad.checker.erc.Sheet(*, uuid_path: str, path: str, violations: List[Violation])

Bases: BaseModel

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

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

uuid_path: str
path: str
violations: List[Violation]
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_fields: ClassVar[Dict[str, FieldInfo]] = {'path': FieldInfo(annotation=str, required=True, description='KiCad type name for the violation'), 'uuid_path': FieldInfo(annotation=str, required=True), 'violations': FieldInfo(annotation=List[Violation], required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class edea.kicad.checker.erc.KicadERCReport(*, field_schema: str | None, source: str, date: datetime, kicad_version: str, sheets: List[Sheet], coordinate_units: CoordinateUnits | None = None)

Bases: BaseModel

A KiCad Electrical Rule Check (ERC) report.

Parameters:
  • field_schema – The JSON schema reference.

  • source – The source file path.

  • date – The time at generation of report.

  • kicad_version – The KiCad version used to generate the report.

  • sheets – List of sheets containing violations.

  • coordinate_units – The units that all coordinates in this report are encoded in.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'populate_by_name': True}

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

field_schema: str | None
source: str
date: datetime
kicad_version: Annotated[str, constr(pattern='^\\d{1,2}(\\.\\d{1,2}(\\.\\d{1,2})?)?$')]
sheets: List[Sheet]
coordinate_units: CoordinateUnits | None
property violations: List[Violation]

Gets a list of all violations from all sheets in the report.

Returns:

List of violations.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_fields: ClassVar[Dict[str, FieldInfo]] = {'coordinate_units': FieldInfo(annotation=Union[CoordinateUnits, NoneType], required=False, default=None, description='Units that all coordinates in this report are encoded in'), 'date': FieldInfo(annotation=datetime, required=True, description='Time at generation of report'), 'field_schema': FieldInfo(annotation=Union[str, NoneType], required=True, alias='$schema', alias_priority=2, description='JSON schema reference'), 'kicad_version': FieldInfo(annotation=str, required=True, description='KiCad version used to generate the report', metadata=[typing.Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=None, pattern='^\\d{1,2}(\\.\\d{1,2}(\\.\\d{1,2})?)?$')]]), 'sheets': FieldInfo(annotation=List[Sheet], required=True), 'source': FieldInfo(annotation=str, required=True, description='Source file path')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

Reporter

Load KiCad reports and generate reports from KiCad files.

class edea.kicad.checker.reporter.RCReporter

Bases: BaseModel

KiCad checker report generator.

classmethod from_json_report(path: str | Path)

Creates a reporter instance from a JSON report file.

Parameters:

path – The path to the JSON report file.

Returns:

Instance of RCReporter.

classmethod from_kicad_file(path: str | Path)

Creates a reporter instance from a KiCad file.

Parameters:

path – The path to the KiCad file.

Returns:

Instance of RCReporter.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

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

model_fields: ClassVar[Dict[str, FieldInfo]] = {}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class edea.kicad.checker.reporter.KicadERCReporter(*, field_schema: str | None, source: str, date: datetime, kicad_version: str, sheets: List[Sheet], coordinate_units: CoordinateUnits | None = None)

Bases: RCReporter, KicadERCReport

A KiCad Electrical Rule Check (ERC).

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'populate_by_name': True}

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

model_fields: ClassVar[Dict[str, FieldInfo]] = {'coordinate_units': FieldInfo(annotation=Union[CoordinateUnits, NoneType], required=False, default=None, description='Units that all coordinates in this report are encoded in'), 'date': FieldInfo(annotation=datetime, required=True, description='Time at generation of report'), 'field_schema': FieldInfo(annotation=Union[str, NoneType], required=True, alias='$schema', alias_priority=2, description='JSON schema reference'), 'kicad_version': FieldInfo(annotation=str, required=True, description='KiCad version used to generate the report', metadata=[typing.Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=None, pattern='^\\d{1,2}(\\.\\d{1,2}(\\.\\d{1,2})?)?$')]]), 'sheets': FieldInfo(annotation=List[Sheet], required=True), 'source': FieldInfo(annotation=str, required=True, description='Source file path')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class edea.kicad.checker.reporter.KicadDRCReporter(*, field_schema: str | None, source: str, date: datetime, kicad_version: str, violations: List[Violation], unconnected_items: List[Violation], schematic_parity: List[Violation], coordinate_units: CoordinateUnits)

Bases: KicadDRCReport, RCReporter

A KiCad Design Rule Check (DRC).

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'populate_by_name': True}

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

model_fields: ClassVar[Dict[str, FieldInfo]] = {'coordinate_units': FieldInfo(annotation=CoordinateUnits, required=True, description='Units that all coordinates in this report are encoded in'), 'date': FieldInfo(annotation=datetime, required=True, description='Time at generation of report'), 'field_schema': FieldInfo(annotation=Union[str, NoneType], required=True, alias='$schema', alias_priority=2, description='JSON schema reference'), 'kicad_version': FieldInfo(annotation=str, required=True, description='KiCad version used to generate the report', metadata=[typing.Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=None, max_length=None, pattern='^\\d{1,2}(\\.\\d{1,2}(\\.\\d{1,2})?)?$')]]), 'schematic_parity': FieldInfo(annotation=List[Violation], required=True), 'source': FieldInfo(annotation=str, required=True, description='Source file path'), 'unconnected_items': FieldInfo(annotation=List[Violation], required=True), 'violations': FieldInfo(annotation=List[Violation], required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.