Ecore to Python generator

Python code generator from Ecore metamodel.

The goal of this generator is to provide independent components (egg) in order to manipulate models.

This project is like the EMF generative part but aimed at Python.

Showcase

This demo does a quick tour of the Ecore2Python generative module..

Introduction

Ecore modeling

This generator uses Ecore models in order to produce the corresponding Python code.

Using Ecore one may design classes, attributes and relations between these classes.

The relations may have special properties like being unique, having cardinality or being an opposite relation.

Using Eclipse you may write your own Ecore model using a tree editor made by the EMF project

The TopCased projects provides a graphical modeler in order to design Ecore models.

Generated domain objects

The generator produce a Python module. This module bring the domain classes corresponding to the Ecore model.

The Ecore attributes are transformed in the corresponding Python attributes and each relation produce a specific class handling the cardinality checks and the opposite assignments.

The pydoc is generated and show sample use of the module and of the methods.

These generated classes may be completed with user code in specific regions.

Soon the generated Python module will be deployable as a reusable .egg file

Unit Testing

The generated module brings unit tests for the unittest module.

These tests are very helpful as soon as you change the generated code, they check the cardinality or unicity constraints.

You may launch the unit tests running the module with the Python interpreter.

XMI Parser

The generator produce an XMI parser. This parser instanciate objets using the generated domain classes from an XMI file.

This still need a lot of work, soon the parser will also allow saving into XMI files.

Plan

Module status
Domain classes

80%

Relations constraints

55%

XMI Parser

15%

Unit tests

45%

.egg export

0%

Installation

The installation process is explained on the Installing a generative module page . The current module has no specific needs, it does not depend on any framework except Python standard library.

Quick start

As soon as the generator is installed, you may quickly test it's working nicely. Create a new project (an empty project or Python project if you installed the PyDev plugin).

Choose the File menu entry then New and Other....

In the Acceleo category pick Module Launcher.

The installed modules is then available. Choose the "Ecore2Python" module then click on "next". Fill in the parameter fields

Once the wizard is finished it will create a .chain file allowing you to launch the generation and it will initialize a default Ecore model.

Right-clicking on the .chain file the Launch button will kick off the generation process. You'll find the generated Python files in the folder you choosed with the wizard.

Contribute!

If you want to change or complete the generative templates you may use the a Team Project Set file. Using this file you'll be able to import the module sources right from the Subversion repository inside your Eclipse.

Team Project Set file for Ecore2Python

The getting and modifying generator module sources page explains how to use this file.

Webdesign : www.katrinet.com - Realisation : Obeo