{"id":18420584,"url":"https://github.com/openworm/pygeppetto","last_synced_at":"2025-07-14T01:04:25.345Z","repository":{"id":62580581,"uuid":"65975231","full_name":"openworm/pygeppetto","owner":"openworm","description":"Python Library to create, load, edit and save a Geppetto Model","archived":false,"fork":false,"pushed_at":"2023-05-22T23:20:15.000Z","size":855,"stargazers_count":14,"open_issues_count":5,"forks_count":3,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-05-23T04:50:31.117Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://geppetto.org","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openworm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-08-18T07:26:48.000Z","updated_at":"2023-07-04T06:42:15.000Z","dependencies_parsed_at":"2022-11-03T21:01:19.773Z","dependency_job_id":"5fe9a31a-3884-4a2d-b7d7-ac72c4ae4fa7","html_url":"https://github.com/openworm/pygeppetto","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/openworm/pygeppetto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openworm%2Fpygeppetto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openworm%2Fpygeppetto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openworm%2Fpygeppetto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openworm%2Fpygeppetto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openworm","download_url":"https://codeload.github.com/openworm/pygeppetto/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openworm%2Fpygeppetto/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265228877,"owners_count":23731086,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T04:22:18.433Z","updated_at":"2025-07-14T01:04:25.313Z","avatar_url":"https://github.com/openworm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pygeppetto\n\nHome of the Geeppetto Python API.\nThe API allows to create a Geppetto Model from Python.\n\n## Installation\n\nUntil pygeppetto is still in development, it is highly recommended to use a\nvirtualenv in order to deploy it. Once you have a dedicated virtualenv, you can\nsimply install pygeppetto:\n\n```bash\n$ python setup.py install\n```\n\n## Pygeppetto API Basic Usage\n\nFirst, import the pygeppetto API:\n\n```Python\nimport pygeppetto\n```\n\nThis will load the pygeppetto API and name it `pygeppetto`. Then, you can create\ninstances and handle them:\n\n```Python\n# We create a new lib\nflib = pygeppetto.GeppettoLibrary(name='mylib')\n# We create a GeppettoModel instance and we set a name a assign a lib\nroot = pygeppetto.GeppettoModel(name='MyGeppettoModel', libraries=[flib])\n```\n\nThe pygeppetto API also allows you to set all attributes in a \"classical\"\nfashion:\n\n```Python\nroot = pygeppetto.GeppettoModel()  # We create a GeppettoModel instance\nroot.name = 'MyGeppettoModel'  # We set a name\nflib = pygeppetto.GeppettoLibrary()  # We create a new lib\nflib.name = 'mylib'\nroot.libraries.append(flib)  # We add the new lib to the created root\n```\n\nIf you wan to open an existing XMI, you need to use a ``ResourceSet`` (not\nrequired, but prefered).\n\n```Python\n# We import the class that will be used to read the XMI from PyEcore\nfrom pyecore.resources import ResourceSet, URI\n\n# We create a new resource set (not required, but better)\nrset = ResourceSet()\n```\n\nUsing this ``ResourceSet``, we are able to read the Geppetto XMI:\n\n```Python\nmodel_url = URI('tests/xmi-data/MediumNet.net.nml.xmi')  # The model URI\nresource = rset.get_resource(model_url)  # We load the model\ngeppettomodel = resource.contents[0]  # We get the root\n```\n\nAt the end of this script, `geppettomodel` contains the model root.\n\nIn order to serialize a new version of the modified model, there is two options.\nThe first one is to serialize onto the existing resource (_i.e_: in the same\nfile), or to serialize in a new one:\n\n```Python\n# Using the first option\nresource.save()\n\n# Using the second option\nresource.save(output=URI('my_new_file.xmi'))\n```\n\n## Dependencies\n\n*  Python \u003e= 3.5\n* `pyecore`\n\n## Contributions\n\nIf the `geppettoModel.ecore` evolves, the static metamodel must be regenerated.\nThe process of adding a new version is the following:\n\n1. Copy the of the new `geppettoModel.ecore` inside `ecore/` (in order to keep a\nversion from which the static metamodel is generated).\n1. Generate the new version of the static metamodel.\n1. Manually merge modifications between the current and the new version (if\nthere is manual modifications in the current version).\n1. Run the tests\n\n\n### How to Generate a New Version\n\nThe pygeppetto API is generated from the\n[`geppettoModel.ecore`](https://github.com/openworm/org.geppetto.model/blob/development/src/main/resources/geppettoModel.ecore)\nusing the PyEcore Acceleo generator\n([`ecore2pyecore.mtl`](https://github.com/pyecore/pyecore/blob/master/generator/ecore2pyecore.mtl)).\nThe `.ecore` is a copy of the `geppettoModel.ecore` from\n[org.geppetto.model](https://github.com/openworm/org.geppetto.model/blob/development/src/main/resources/geppettoModel.ecore)\n(`development` branch). \n\n#### Generate the code with pyecoregen (suggested)\n\nInstall pyecoregen\n```bash\npip install pyecoregen\n```\n\nRun the following script:\n\n```python\nfrom pyecore.resources import ResourceSet\nfrom pyecoregen.ecore import EcoreGenerator\nimport pyecore.type  # We register the XML types (generated by pyecoregen)\n\n# We open the metamodel\nrset = ResourceSet()\nmm_root = rset.get_resource('pygeppetto/ecore/geppettoModel.ecore').contents[0]\n\n# We generate the code using the EcoreGenerator\nEcoreGenerator(auto_register_package=True).generate(mm_root, outfolder='pygeppetto')\n```\n\nThen do the following fix replacements: \n* `from model` -\u003e `from pygeppetto.model`\n* `from type`  -\u003e `from pyecore.type`\n\n#### Generate the code with Eclipse\nThe `ecore2pyecore.mtl` script can be directly used in Eclipse as a \n[Acceleo](https://wiki.eclipse.org/Acceleo/Getting_Started) generator.\n1. Install the [Acceleo plugin](https://marketplace.eclipse.org/content/acceleo) into eclipse\n1. Create a new Acceleo project\n1. Add the file `ecore2pyecore.mtl` to the project main package\n1. run `ecore2pyecore.mtl` as an acceleo project. The run configuration will popup: specify the `geppettoModel.ecore` \nfile to use and the generation path. Generate the code in a path different from pygeppetto and merge the code\n\n#### Patches and Overrides\nThe model generated from the ecore file contains some code stubs that are implemented manually on Python.\nThe place to make those implementations is not the files themselves though but the `overrides.py` file.\nWriting the overrides there keeps the regeneration process easier as the written code does not actually\nneed to be merged.\n\n#### Merge conflicts\nManual modifications may have been introduced in the version of the static\nGeppetto metamodel (_e.g_: implementation of some methods or technical method\nadditions). The generated version must be manually merged with the new generated one\n(_e.g_: using meld or other tool).\n\nAn easy way to do that is by using git.\n\n1 - Generate the code in a in a directory reproducing the pygeppetto structure, say `pygeppetto_new/pygeppetto/model`\n\n2 - Initialize a new git local repo inside our new pygeppetto\n```bash\ncd pygeppetto_new\ngit init\n```\n3 - Add the remote for pygeppetto\n```bash\ngit remote add origin https://github.com/openworm/pygeppetto.git\n```\n4 - Merge with actual geppetto branch\n```bash\ngit merge --allow-unrelated-histories origin/development\n```\n5 - Resolve conflicts: use incoming changes for clear overrides and implemented methods\n\n\n\n### Run the Tests\n\nTests are written using `pytest` and are run using `tox`. To launch all the\ntests the following command is enough:\n\n```bash\n$ tox\n```\n\nOr, if you want to avoid using `tox`, you can just:\n\n```bash\n$ python -m pytest tests/\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenworm%2Fpygeppetto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenworm%2Fpygeppetto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenworm%2Fpygeppetto/lists"}