Code Monkey home page Code Monkey logo

pygeppetto's Introduction

pygeppetto

Home of the Geeppetto Python API. The API allows to create a Geppetto Model from Python.

## Installation

Until pygeppetto is still in development, it is highly recommended to use a virtualenv in order to deploy it. Once you have a dedicated virtualenv, you can simply install pygeppetto:

$ python setup.py install

Pygeppetto API Basic Usage

First, import the pygeppetto API:

import model as pygeppetto

This will load the pygeppetto API and name it pygeppetto. Then, you can create instances and handle them:

root = pygeppetto.GeppettoModel()  # We create a GeppettoModel instance
root.name = 'MyGeppettoModel'  # We set a name
flib = pygeppetto.GeppettoLibrary()  # We create a new lib
flib.name = 'mylib'
root.libraries.append(flib)  # We add the new lib to the created root

If you wan to open an existing XMI, you need to register first all the EPackages from the pygeppetto API:

# We import the class that will be used to read the XMI from PyEcore
from pyecore.resources import ResourceSet, URI

# We create a new resource set (not required, but better)
rset = ResourceSet()

# Register all the EPackages of pygeppetto inside the ResourceSet
rset.metamodel_registry[pygeppetto.nsURI] = pygeppetto
for subpack in pygeppetto.eSubpackages:
    rset.metamodel_registry[subpack.nsURI] = subpack

Then, we are able to read Geppetto XMI:

model_url = URI('tests/xmi-data/MediumNet.net.nml.xmi')  # The model URI
resource = rset.get_resource(model_url)  # We load the model
geppettomodel = resource.contents[0]  # We get the root

At the end of this script, geppettomodel contains the model root.

In order to serialize a new version of the modified model, there is two options. The first one is to serialize onto the existing resource (i.e: in the same file), or to serialize in a new one:

# Using the first option
resource.save()

# Using the second option
resource.save(output=URI('my_new_file.xmi'))

Dependencies

  • Python >= 3.3
  • pyecore >= 0.1.2

Contributions

If the geppettoModel.ecore evolves, the static metamodel must be regenerated. The process of adding a new version is the following:

  1. Copy the of the new geppettoModel.ecore inside ecore/ (in order to keep a version from which the static metamodel is generated).
  2. Generate the new version of the static metamodel.
  3. Manually merge modifications between the current and the new version (if there is manual modifications in the current version).
  4. Run the tests

### How to Generate a New Version

The pygeppetto API is generated from the geppettoModel.ecore using the PyEcore Acceleo generator (ecore2pyecore.mtl). The .ecore is a copy of the geppettoModel.ecore from org.geppetto.model (development branch). The script can be directly used in Eclipse as a simple Acceleo generator. The generated code had been directly placed inside the repository without manual modification.

If manual modifications have been introduced in the version of the static Geppetto metamodel (e.g: implementation of some methods or technical method additions), this version must be manually merged with the new generated one (e.g: using meld or other tool).

Run the Tests

Tests are written using pytest and are run using tox. To launch all the tests the following command is enough:

$ tox

Currently, the tests are only related to the ability to read/write tests models.

pygeppetto's People

Contributors

adrianq avatar tarelli avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.