Generator not working on ecore model
Closed this issue · 2 comments
I'm trying to use pyecoregen on an ecore model (which can be found here: https://github.com/EnergyTransition/ESDL/blob/master/esdl/model/esdl.ecore). The model is developed in Eclipse Photon.
I'm getting the following error when trying to generate the classes:
$ pyecoregen -vv -e C:\\Data\\git\\esdl.next\\model\\esdl.ecore -o gen
2018-10-03 15:20:56,926 INFO [multigen.generator] Generating code to 'gen'.
2018-10-03 15:20:56,926 DEBUG [multigen.generator] <pyecore.ecore.EPackage object at 0x6fffe7aa6d8> --> 'gen/esdl/__init__.py'
2018-10-03 15:20:57,566 DEBUG [multigen.generator] <pyecore.ecore.EPackage object at 0x6fffe7aa6d8> --> 'gen/esdl/esdl.py'
Traceback (most recent call last):
File "/usr/bin/pyecoregen", line 11, in <module>
sys.exit(main())
File "/usr/lib/python3.6/site-packages/pyecoregen/cli.py", line 15, in main
generate_from_cli(sys.argv[1:]) # nocover
File "/usr/lib/python3.6/site-packages/pyecoregen/cli.py", line 62, in generate_from_cli
).generate(model, parsed_args.out_folder)
File "/usr/lib/python3.6/site-packages/pyecoregen/ecore.py", line 330, in generate
super().generate(model, outfolder)
File "/usr/lib/python3.6/site-packages/multigen/generator.py", line 39, in generate
task.run(element, outfolder)
File "/usr/lib/python3.6/site-packages/multigen/generator.py", line 65, in run
self.generate_file(element, filepath)
File "/usr/lib/python3.6/site-packages/multigen/jinja.py", line 43, in generate_file
context = self.create_template_context(element=element)
File "/usr/lib/python3.6/site-packages/pyecoregen/ecore.py", line 118, in create_template_context
imported_classifiers=self.imported_classifiers(element)
File "/usr/lib/python3.6/site-packages/pyecoregen/ecore.py", line 96, in imported_classifiers
imported |= {t for t in attributes_types if t.ePackage not in {p, ecore.eClass, None}}
File "/usr/lib/python3.6/site-packages/pyecoregen/ecore.py", line 96, in <setcomp>
imported |= {t for t in attributes_types if t.ePackage not in {p, ecore.eClass, None}}
File "/usr/lib/python3.6/site-packages/pyecore/ecore.py", line 895, in __getattribute__
self._wrapped = decoded.eClass
AttributeError: 'NoneType' object has no attribute 'eClass'
Any idea what goes wrong here?
The issue here comes from PyEcore, I forgot to register an Ecore datatype as classifier in the core (the ELong
type...). I'm really sorry about that...
There is a way of patching the code and launching the generation by code. I made the test and everything works fine. Here is the code I used:
from pyecore.resources import ResourceSet
import pyecore.ecore as ecore
from pyecoregen.ecore import EcoreGenerator
def register_missing_type():
ecore.Core.register_classifier(ecore.ELong) # here is the missing type registration
def generate_code(folder='.', ecore_path=None):
rset = ResourceSet()
uml_root = rset.get_resource(ecore_path).contents[0]
generator = EcoreGenerator()
generator.generate(uml_root, folder)
if __name__ == '__main__':
register_missing_type()
generate_code(ecore_path='esdl.ecore', folder='gen') # change the path to your .ecore metamodel here
I will patch this on PyEcore asap. Again, sorry about that... Tell me if this snippet works for you!
Hi @aranega,
That is a fast reply! And it works, it generates the classes.
Thanks for your help!
Kind regards,
Ewoud