Closed wez closed 7 years ago
This seems to make things get further along:
$ git diff
diff --git a/pykicad/sexpr.py b/pykicad/sexpr.py
index e66b497..2bb50e1 100644
--- a/pykicad/sexpr.py
+++ b/pykicad/sexpr.py
@@ -109,7 +109,7 @@ def generate_parser(tag, schema, attr=None, optional=False):
children = []
for key, value in schema.items():
if not (key.isdigit() or key[0] == '_'):
- attr = None
+ attr = schema.get('_attr', None)
if type(value) == type:
attr = key
children.append(generate_parser(key, value, attr=attr, optional=True))
that is really weird, are you using the latest commit? I'm not suppressing anything anymore...
The testfile parses fine for me...?!
I'm hitting an issue with python2. Let me see if I can reproduce with python2...
Here's a generated pcb file using python2 and your module:
I created a test environment using guix environment --ad-hoc python@2 python2-pyparsing kicad --pure to make sure there is nothing in my path messing with things
I'm based on rev 0d15e39 (looks like that is still the latest)
This is with the macOS python, not sure if that matters:
$ /usr/bin/python
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
adding in some debugging showed that the Model was seeing (at (xyz 0 0 0))
as xyz: [0,0,0]
; in other words, the attribute name was missing, which is why I tried adding that explicit check for _attr
in the comment above.
The schema parser is a pain to debug and understand I know. Probably was not worth the complexity, probably won't be writing parser generators again. Anyway I think it's nearly there, so starting from scratch at this point is probably a bad idea.
What happens when you run the unit tests? They are really good at detecting errors and are a life saver with this kind of code.
I added a test case:
diff --git a/tests/test_module.py b/tests/test_module.py
index 7f0d0e4..d58f496 100644
--- a/tests/test_module.py
+++ b/tests/test_module.py
@@ -1,3 +1,4 @@
+from __future__ import unicode_literals
import unittest
from pytest import *
from pykicad.module import *
@@ -112,3 +113,13 @@ class NetTests(unittest.TestCase):
assert n1.code == 1
assert n2.code == 2
assert n3.code == 3
+
+class ModelTests(unittest.TestCase):
+ def test_model(self):
+ model_string = (
+ '\n(model Diodes_THT.3dshapes/D_DO-41_SOD81_P7.62mm_Horizontal.wrl \n'
+ ' (at (xyz 0 0 0)) \n'
+ ' (scale (xyz 0.3937010000 0.3937010000 0.3937010000)) \n'
+ ' (rotate (xyz 0 0 0)))''')
+ model = Model.parse(model_string)
+ self.assertEqual(model_string, model.to_string())
diff --git a/tests/test_sexpr.py b/tests/test_sexpr.py
index 80f8e2e..ce2abde 100644
--- a/tests/test_sexpr.py
+++ b/tests/test_sexpr.py
@@ -1,3 +1,5 @@
+# vim: set fileencoding=utf-8
+from __future__ import unicode_literals
import unittest
from pytest import *
from pyparsing import ParseException
This makes it easier to see the error:
$ git diff
diff --git a/pykicad/sexpr.py b/pykicad/sexpr.py
index 27004b4..ae37c4a 100644
--- a/pykicad/sexpr.py
+++ b/pykicad/sexpr.py
@@ -308,7 +308,10 @@ class AST(object):
result[key] = [result[key]]
result[key].append(res[key])
- return cls(**result)
+ try:
+ return cls(**result)
+ except TypeError as e:
+ raise TypeError('%r: %s (%r)' % (cls, e, result))
@classmethod
def from_schema(cls, tag, schema):
ERROR: test_model (test_module.ModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/wez/src/kbdmakerutils/pykicad/tests/test_module.py", line 124, in test_model
model = Model.parse(model_string)
File "pykicad/sexpr.py", line 314, in parse
raise TypeError('%r: %s (%r)' % (cls, e, result))
TypeError: <class 'pykicad.module.Model'>: __init__() got an unexpected keyword argument 'xyz' ({'path': u'Diodes_THT.3dshapes/D_DO-41_SOD81_P7.62mm_Horizontal.wrl', 'xyz': [0.0, 0.0, 0.0, [0.393701, 0.393701, 0.393701], [0.0, 0.0, 0.0]]})
Note that the change I suggested in https://github.com/dvc94ch/pykicad/issues/11#issuecomment-296396424 allows the file to be compiled, but when you dump out the resulting module, the model stanza loses the xyz
level of nesting and the resultant pcb file fails to parse when loaded by kicad.
For now, I'm working around this with the the one-liner I suggested above, and to make sure that I get a valid pcb, I'm setting module.model = None before I save it.
If you submit a PR for the test I'll fix it on Wednesday... I still don't understand why I wasn't getting that error dough...
I think this is fixed now, could you let me know if you are still having this issue?
Finally got around to looking at this again; with master in github this error is resolved, but not with the currently released package installed via pip
Here's the error:
Here's the module: