Skip to content

add_global_label() data not serialized to output file #204

@smazurov

Description

@smazurov

Bug

add_global_label() stores data correctly into _data["global_label"], but _schematic_data_to_sexp() in core/parser.py never iterates over that key. The data is silently dropped on save().

Reproducer

import kicad_sch_api as ksa

sch = ksa.create_schematic("test")
sch.add_global_label(text="NRESET", position=(80, 50), shape="bidirectional")
sch.save_as("test.kicad_sch")

with open("test.kicad_sch") as f:
    content = f.read()

assert "global_label" in content  # FAILS — no global_label in output

Root cause

_schematic_data_to_sexp() has loops for labels, hierarchical_labels, no_connects, etc. but no loop for global_label:

# These exist:
for label in schematic_data.get("labels", []):
    sexp_data.append(self._label_to_sexp(label))
for hlabel in schematic_data.get("hierarchical_labels", []):
    sexp_data.append(self._hierarchical_label_to_sexp(hlabel))

# This is missing:
# for glabel in schematic_data.get("global_label", []):
#     sexp_data.append(self._global_label_to_sexp(glabel))

Additionally, label_parser.py has _label_to_sexp() and _hierarchical_label_to_sexp() but no _global_label_to_sexp().

The save() method in schematic.py also lacks a _sync_global_labels_to_data() call (though the text_element_manager writes directly to _data, so sync may not be strictly needed — the serializer loop is the primary gap).

Expected fix

  1. Add _global_label_to_sexp() to label_parser.py (same format as _hierarchical_label_to_sexp(), just global_label tag)
  2. Add the iteration loop in _schematic_data_to_sexp()

Version

v0.5.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions