Skip to main content

Model to text framework for PyEcore, including the Ecore to Python generator

Project description

pypiversion masterbuild coverage license

Overview

pyecoregen 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 the pyecore metamodel.

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 see pyecore for documentation how to work with them.

Installation

pyecoregen comes in form or a regular Python distribution and can be installed from Github or PyPI with a simple:

$ pip install pyecoregen

The library works with any version of Python >= 3.5.

Usage

Code generation can be done programmatically and directly at the command line.

Command line interface

After installation an executable script pyecoregen has been installed. Assuming library.ecore is your Ecore XMI file, and you want to generate the classes in some/folder, you can do:

$ pyecoregen -vv -e library.ecore -o some/folder

The -vv is optional to raise verbosity to log level DEBUG. 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'

The pyecoregen command line interface also allows you to generate the classes from a remote Ecore XMI file if its “path” starts with http(s)://. The usage does not change:

$ pyecoregen -e "http://path/towards/my/ecore" -o some/folder

Programmatic interface

If you need to generate code from an in-memory representation of a pyecore model, you instantiate the EcoreGenerator class and call the generate method. Assuming you have loaded above model and hold it’s root package in library_pkg, you would generate with:

generator = EcoreGenerator()
generator.generate(library_pkg, 'some/folder')

Generator options

The 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-param is then turning into a keyword argument my_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-module my.custom_mod will make the generated code import mixin classes from a module my.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 are dependencies of the input metamodel. A metamodel dependency is typically a reference from the input metamodel to another .ecore file. Please note that this option introduces slower code generation as all metamodels must be scanned in order to determine dependencies.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyecoregen-0.5.1.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

pyecoregen-0.5.1-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file pyecoregen-0.5.1.tar.gz.

File metadata

  • Download URL: pyecoregen-0.5.1.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.7

File hashes

Hashes for pyecoregen-0.5.1.tar.gz
Algorithm Hash digest
SHA256 3e675ea2f60cf0e0cb0cb9bf4ba41692eb966110bf457f6f38d7a35ebac66d3a
MD5 27e181d71496dd1d7d2d3393268f5261
BLAKE2b-256 37cdb8966c28c7382d77073e64b10f1bf31e1380fd6217571700e660554c4ce7

See more details on using hashes here.

File details

Details for the file pyecoregen-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: pyecoregen-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.7

File hashes

Hashes for pyecoregen-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7467d91b43b80ca4eb7c9b8c54413c6d6fdbf0f8ee26820a4843b76d5c36b1f
MD5 820d09901c4ced2626e8f2d088fb2782
BLAKE2b-256 61c26872d77c1382affd69a964159c8883a158317d6c2653bb8184eef2e8405d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page