Package: pyecoregen
ContentsOverviewInstallationUsageCommand line interfaceProgrammatic interfaceGenerator optionsOverviewpyecoregen is a code generator, producing Python classes from Ecore models. It can be used at the
command line as well as a module. In the latter case the passed model is expected to be an instance
of thepyecoremetamodel.After using pyecoregen, you have a Python package representing the classes from the Ecore model. The
generated classes are instances of the pyecore metaclasses. Please seepyecorefor documentation how to work with them.Installationpyecoregen comes in form or a regular Python distribution and can be installed from Github or PyPI
with a simple:$pipinstallpyecoregenThe library works with any version of Python >= 3.5.UsageCode generation can be done programmatically and directly at the command line.Command line interfaceAfter installation an executable scriptpyecoregenhas been installed. Assuminglibrary.ecoreis your Ecore XMI file, and you want to generate the classes insome/folder,
you can do:$pyecoregen-vv-elibrary.ecore-osome/folderThe-vvis optional to raise verbosity to log levelDEBUG. You should see output like this:2017-05-26 08:06:54,303 INFO [multigen.generator] Generating code to '/here/some/folder'.
2017-05-26 08:06:54,304 DEBUG [multigen.generator] <pyecore.ecore.EPackage object at 0x000001DCF3C61E80> --> '/here/some/folder/library/__init__.py'
2017-05-26 08:06:54,363 DEBUG [multigen.generator] <pyecore.ecore.EPackage object at 0x000001DCF3C61E80> --> '/here/some/folder/library/library.py'Thepyecoregencommand line interface also allows you to generate the classes from a
remote Ecore XMI file if its “path” starts withhttp(s)://. The usage does not change:$pyecoregen-e"http://path/towards/my/ecore"-osome/folderProgrammatic interfaceIf you need to generate code from an in-memory representation of a pyecore model, you instantiate
theEcoreGeneratorclass and call the generate method. Assuming you have loaded above model and
hold it’s root package inlibrary_pkg, you would generate with:generator=EcoreGenerator()generator.generate(library_pkg,'some/folder')Generator optionsThe end user can control some of the features how the metamodel code is generated. This can be done
at the command line as well as via programmatic invocation. A command line parameter--my-paramis then turning into a keyword argumentmy_param.--auto-register-package(Default:False)If enabled, the generated packages are automatically added to pyecore’s global namespace
registry, which makes them available during XMI deserialization.--user-module(Default:None)If specified, the given string is interpreted as a dotted Python module path. E.g.--user-modulemy.custom_modwill make the generated code import mixin classes from a modulemy.custom_mod. A generated class with name<name>then derives from a mixin<name>Mixin, which is expected to be part of the user module. If this option is used, the
generator also produces a skeleton file which contains all required mixin classes and methods.
Usually you copy parts of this template to your own module, which is then checked into version
control all your other code.--with-dependencies(Default:False)If enabled, the generator also generates code from all metamodels that aredependenciesof the
input metamodel. A metamodel dependency is typically a reference from the input
metamodel to another.ecorefile. Please note that this option introduces slower code
generation as all metamodels must be scanned in order to determine dependencies.