From 26d81d6475e84ba1025ec435c202b8440035c5f5 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 16 Dec 2020 12:16:03 -0300 Subject: [PATCH] Added support for missing field names in libraries. - Closes #32 - Reported on SnapEda libs --- CHANGELOG.md | 2 ++ kibot/kicad/v5_sch.py | 9 ++++++--- kibot/misc.py | 1 + tests/board_samples/kicad_5/l1.lib | 2 ++ tests/test_plot/test_print_sch.py | 10 +++++----- tests/test_plot/test_sch_errors.py | 5 +++-- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8bf6e85..0a555743 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - iBoM output: file name patterns are allowed for the `netlist_file` option. - File name patterns: %F is the name of the source file without extension, but with the path. +### Fixed +- Now we support missing field names in schematic library entries. ## [0.8.1] - 2020-12-09 ### Added diff --git a/kibot/kicad/v5_sch.py b/kibot/kicad/v5_sch.py index a673bd8b..52a4e054 100644 --- a/kibot/kicad/v5_sch.py +++ b/kibot/kicad/v5_sch.py @@ -16,7 +16,7 @@ from .config import KiConf, un_quote from ..gs import GS from ..misc import (W_BADPOLI, W_POLICOORDS, W_BADSQUARE, W_BADCIRCLE, W_BADARC, W_BADTEXT, W_BADPIN, W_BADCOMP, W_BADDRAW, W_UNKDCM, W_UNKAR, W_ARNOPATH, W_ARNOREF, W_MISCFLD, W_EXTRASPC, W_NOLIB, W_INCPOS, W_NOANNO, W_MISSLIB, - W_MISSDCM, W_MISSCMP) + W_MISSDCM, W_MISSCMP, W_MISFLDNAME) from .. import log logger = log.get_logger(__name__) @@ -139,8 +139,11 @@ class LibComponentField(object): field.name = gs[9][1:-1] else: if field.number > 3: - raise SchLibError('Missing component field name', line, f) - field.name = ['Reference', 'Value', 'Footprint', 'Datasheet'][field.number] + logger.warning(W_MISFLDNAME + 'Missing component field name ({} line {})'.format(lib_name, f.line)) + # KiCad falls-back to `FieldN` + field.name = 'Field'+str(field.number) + else: + field.name = ['Reference', 'Value', 'Footprint', 'Datasheet'][field.number] return field def write(self, f): diff --git a/kibot/misc.py b/kibot/misc.py index b20cb533..84c3ca6d 100644 --- a/kibot/misc.py +++ b/kibot/misc.py @@ -156,6 +156,7 @@ W_MISSDCM = '(W042) ' W_MISSCMP = '(W043) ' W_VARSCH = '(W044) ' W_WRONGPASTE = '(W045) ' +W_MISFLDNAME = '(W046) ' class Rect(object): diff --git a/tests/board_samples/kicad_5/l1.lib b/tests/board_samples/kicad_5/l1.lib index 8804f064..97c0a112 100644 --- a/tests/board_samples/kicad_5/l1.lib +++ b/tests/board_samples/kicad_5/l1.lib @@ -28,6 +28,8 @@ F0 "#SYM_CAUTION" 0 150 50 H I C CNN F1 "SYM_CAUTION" 0 -175 50 H I C CNN F2 "Tedy:Symbol_Caution_Type2_FSilkS_Small" 100 -250 50 H I C CNN F3 "" 0 0 50 H I C CNN +# No field name, KiCad assigns Field4 +F4 "Hi!" 0 0 50 H I C CNN DRAW A 0 35 16 1616 184 0 0 0 N -15 40 15 40 C 0 -46 10 0 0 0 F diff --git a/tests/test_plot/test_print_sch.py b/tests/test_plot/test_print_sch.py index f58a688c..e2909590 100644 --- a/tests/test_plot/test_print_sch.py +++ b/tests/test_plot/test_print_sch.py @@ -131,18 +131,18 @@ def test_print_sch_variant_ni_2(): ctx.clean_up() -def test_sch_missing(): +def test_sch_missing_1(): """ R1 exists in l1.lib, but the lib isn't specified. R2 is bogus, completely missing """ prj = 'missing' - ctx = context.TestContextSCH('test_sch_missing', prj, 'sch_no_inductors_1', PDF_DIR) + ctx = context.TestContextSCH('test_sch_missing_1', prj, 'sch_no_inductors_1', PDF_DIR) ctx.run() o_name = os.path.join(NI_DIR, prj+'.sch') ctx.expect_out_file(o_name) ctx.search_err("Component .?Resistor.? doesn't specify its library") ctx.search_err("Missing component .?l1:FooBar.?") ctx.search_err("Missing component(.*)Resistor", invert=True) - ctx.search_err(r"Found 2 unique warning/s \(3 total\)") + ctx.search_err(r"Found 3 unique warning/s \(4 total\)") ctx.clean_up() @@ -150,14 +150,14 @@ def test_sch_missing_filtered(): """ R1 exists in l1.lib, but the lib isn't specified. R2 is bogus, completely missing """ prj = 'missing' - ctx = context.TestContextSCH('test_sch_missing', prj, 'sch_no_inductors_1_filtered', PDF_DIR) + ctx = context.TestContextSCH('test_sch_missing_filtered', prj, 'sch_no_inductors_1_filtered', PDF_DIR) ctx.run() o_name = os.path.join(NI_DIR, prj+'.sch') ctx.expect_out_file(o_name) ctx.search_err("Component .?Resistor.? doesn't specify its library") ctx.search_err("Missing component .?l1:FooBar.?", invert=True) ctx.search_err("Missing component(.*)Resistor", invert=True) - ctx.search_err(r"Found 1 unique warning/s \(3 total, 2 filtered\)") + ctx.search_err(r"Found 2 unique warning/s \(4 total, 2 filtered\)") ctx.clean_up() diff --git a/tests/test_plot/test_sch_errors.py b/tests/test_plot/test_sch_errors.py index ebed55b3..e28eae75 100644 --- a/tests/test_plot/test_sch_errors.py +++ b/tests/test_plot/test_sch_errors.py @@ -61,8 +61,9 @@ def test_sch_errors_l3(): setup_ctx('l3', 'Malformed component field') -def test_sch_errors_l4(): - setup_ctx('l4', 'Missing component field name') +# Now we support it: +# def test_sch_errors_l4(): +# setup_ctx('l4', 'Missing component field name') def test_sch_errors_l5():