Added support for missing field names in libraries.

- Closes #32
- Reported on SnapEda libs
This commit is contained in:
Salvador E. Tropea 2020-12-16 12:16:03 -03:00
parent b17e9d78b2
commit 26d81d6475
6 changed files with 19 additions and 10 deletions

View File

@ -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. - 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 - File name patterns: %F is the name of the source file without extension, but
with the path. with the path.
### Fixed
- Now we support missing field names in schematic library entries.
## [0.8.1] - 2020-12-09 ## [0.8.1] - 2020-12-09
### Added ### Added

View File

@ -16,7 +16,7 @@ from .config import KiConf, un_quote
from ..gs import GS 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, 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_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 from .. import log
logger = log.get_logger(__name__) logger = log.get_logger(__name__)
@ -139,8 +139,11 @@ class LibComponentField(object):
field.name = gs[9][1:-1] field.name = gs[9][1:-1]
else: else:
if field.number > 3: if field.number > 3:
raise SchLibError('Missing component field name', line, f) logger.warning(W_MISFLDNAME + 'Missing component field name ({} line {})'.format(lib_name, f.line))
field.name = ['Reference', 'Value', 'Footprint', 'Datasheet'][field.number] # KiCad falls-back to `FieldN`
field.name = 'Field'+str(field.number)
else:
field.name = ['Reference', 'Value', 'Footprint', 'Datasheet'][field.number]
return field return field
def write(self, f): def write(self, f):

View File

@ -156,6 +156,7 @@ W_MISSDCM = '(W042) '
W_MISSCMP = '(W043) ' W_MISSCMP = '(W043) '
W_VARSCH = '(W044) ' W_VARSCH = '(W044) '
W_WRONGPASTE = '(W045) ' W_WRONGPASTE = '(W045) '
W_MISFLDNAME = '(W046) '
class Rect(object): class Rect(object):

View File

@ -28,6 +28,8 @@ F0 "#SYM_CAUTION" 0 150 50 H I C CNN
F1 "SYM_CAUTION" 0 -175 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 F2 "Tedy:Symbol_Caution_Type2_FSilkS_Small" 100 -250 50 H I C CNN
F3 "" 0 0 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 DRAW
A 0 35 16 1616 184 0 0 0 N -15 40 15 40 A 0 35 16 1616 184 0 0 0 N -15 40 15 40
C 0 -46 10 0 0 0 F C 0 -46 10 0 0 0 F

View File

@ -131,18 +131,18 @@ def test_print_sch_variant_ni_2():
ctx.clean_up() ctx.clean_up()
def test_sch_missing(): def test_sch_missing_1():
""" R1 exists in l1.lib, but the lib isn't specified. """ R1 exists in l1.lib, but the lib isn't specified.
R2 is bogus, completely missing """ R2 is bogus, completely missing """
prj = '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() ctx.run()
o_name = os.path.join(NI_DIR, prj+'.sch') o_name = os.path.join(NI_DIR, prj+'.sch')
ctx.expect_out_file(o_name) ctx.expect_out_file(o_name)
ctx.search_err("Component .?Resistor.? doesn't specify its library") ctx.search_err("Component .?Resistor.? doesn't specify its library")
ctx.search_err("Missing component .?l1:FooBar.?") ctx.search_err("Missing component .?l1:FooBar.?")
ctx.search_err("Missing component(.*)Resistor", invert=True) 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() ctx.clean_up()
@ -150,14 +150,14 @@ def test_sch_missing_filtered():
""" R1 exists in l1.lib, but the lib isn't specified. """ R1 exists in l1.lib, but the lib isn't specified.
R2 is bogus, completely missing """ R2 is bogus, completely missing """
prj = '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() ctx.run()
o_name = os.path.join(NI_DIR, prj+'.sch') o_name = os.path.join(NI_DIR, prj+'.sch')
ctx.expect_out_file(o_name) ctx.expect_out_file(o_name)
ctx.search_err("Component .?Resistor.? doesn't specify its library") ctx.search_err("Component .?Resistor.? doesn't specify its library")
ctx.search_err("Missing component .?l1:FooBar.?", invert=True) ctx.search_err("Missing component .?l1:FooBar.?", invert=True)
ctx.search_err("Missing component(.*)Resistor", 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() ctx.clean_up()

View File

@ -61,8 +61,9 @@ def test_sch_errors_l3():
setup_ctx('l3', 'Malformed component field') setup_ctx('l3', 'Malformed component field')
def test_sch_errors_l4(): # Now we support it:
setup_ctx('l4', 'Missing component field name') # def test_sch_errors_l4():
# setup_ctx('l4', 'Missing component field name')
def test_sch_errors_l5(): def test_sch_errors_l5():