Skip to main content

Model driven genration - from UML to Code & Docs

Project description

Test PyPI Documentation Status

pyMDG

Overview

The problem with most model driven generation is that tools force the modeller to effectively "code up" the output representation of the artifact being generated in an output specific, non-reusable model. It always ends up being simpler just to actually code up the end result.

pyMDGs goal is to use a logical model as the source, then combine with business rules to output physical level artifacts (code, schema, documentation etc). Current version supports Sparx DB (including sqlite which is the '.qea' native file format for Sparx v16+) or diagrams.net XML.

A single logical model is rich enough to generate API schemas, DB schemas, POJOs, Python Data classes etc.

The tool parses your models into generic UML classes (see metamodel below) which are then passed to jinja2 templates for generation.

My current favorite generation recipie is Hasura for a GraphQL API and generating DB migrations via Django. See the tutorial here: HasuraTutorial and check the example config in sample_recipies/sparxdb/config-sparxdb-graphql.yaml

Quickstart and docs can be found here: readthedocs

Test

Testing (powershell):

.\test.ps1

Testing (unittest):

python -m unittest

Generate

To generate code call the generate script and pass in the recipe folder. A sample recipe folder is provided in the github repo:

python mdg-tool.py generate ./sample_recipe/drawio/config-drawio-django.yaml

Or once installed into site-packages execute:

mdg-tool generate <my/config.yaml>

See the sample_recipe configs for examples

Limitations

Most templates have a limit of single inheritance and no chained inheritance (a is a specialisation of b which is a specialisation of c). The results of this are unknown.

Sparx EA XMI (versions earlier than V16) Export Process

The UML parser expects a specific package hierarchy, please see the sample EA file.

  • In Sparx select the domain root node (e.g. Model/Sample )
  • Select the publish tab at the top
  • Select Publish As... from top menu
  • Set export type as XMI 2.1
  • Optionally select 'Export Diagrams', 'Generate Diagram Images' and PNG format
  • Export to folder where you want to generate from

Note: Sparx V16+ does not need to be exported. The parser uses native SQLite file format which is the same schema as database repositories.

Draw.io Export Process

The UML parser expects a specific package layout which mimics the Sparx hierarchy, please see the sample files.

  • In the web editor select Export As -> XML
  • Uncheck 'Compressed'

Wiki documentation upload

If your generation recipe has created a file for your wiki (Confluence) then an uploader utilitity can be used. This assumes that you have done the XMI export from Sparx EA with export diagrams and generate diagram images. To generate a confluence token please see: https://confluence.atlassian.com/cloud/api-tokens-938839638.html

python mdg/confluence.py {your email} {your confluence token} {confluence page id} {path to images} {doc filename}

Nomenclature:

This diagram shows all the features and how to model in UML Nomenclature

Sample model

Sample model

Metamodel

This diagram shows the internal classes which are passed to the templates during generation. Metamodel

Build the docs

Install sphinx

 > cd pyMDG
 > sphinx-apidoc -o docs\source mdg
 > cd docs
 > make html

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

pymdg-1.2.5.tar.gz (76.0 kB view details)

Uploaded Source

Built Distribution

pymdg-1.2.5-py3-none-any.whl (93.0 kB view details)

Uploaded Python 3

File details

Details for the file pymdg-1.2.5.tar.gz.

File metadata

  • Download URL: pymdg-1.2.5.tar.gz
  • Upload date:
  • Size: 76.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pymdg-1.2.5.tar.gz
Algorithm Hash digest
SHA256 32d8bae91f7a6708127b17169128bb8780dcf22228418f6fc44c39c26c02fb17
MD5 edfd8d91f8222dd42d7d5819837c148d
BLAKE2b-256 03f0c3141cd399e1588a87c8f4ca530c1f9f1a27f19ca917f549068ec60e6214

See more details on using hashes here.

File details

Details for the file pymdg-1.2.5-py3-none-any.whl.

File metadata

  • Download URL: pymdg-1.2.5-py3-none-any.whl
  • Upload date:
  • Size: 93.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pymdg-1.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 737997595da09b930bb6c5a2ff65c763c7cd11a59bb12a745c4b42fac4d9a433
MD5 d2dfe8b1c5567250e9257fae382b8cac
BLAKE2b-256 d1268b9f4cdd4a8ffc4fb91e18168b091a5956c3733009ee9eec5701148f3716

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