Python generator

The Python code generator is a plug-out directly written in C++.

The generated sources follows the definition made in BOUML at the artifact / class / operation / relation / attribute / extra member levels.

When the code generation is applied on a artifact associated to several classes, the code generation is made for all these classes. Nevertheless the Python code generator produce first the code in memory and update the appropriate files only when it is necessary, to not change the last write date of the files for nothing. Depending on the toggle verbose code generation of the global menu Languages the code generator is verbose or not.

The Python code generator plug-out may be called on :

When the Python code generator is ask through the Tools menu, it is applied on the project, then on all the artifacts.

The name of the generated files depend on the artifact name, the extension depend on the language and is fixed for each by the generations settings (see below), the directory where the files are generated may be set in each package containing directly or indirectly the artifact (see generation directory).

The generator change automatically the indentation, adding/removing when necessary the indentation step specified through the generations settings (see dialog screen below) At least the first line of an operation's body must not be indented when you enter it through the operation dialog (except if you ask for non contextual indent), but of course you have to manage yourself the indentation change due to control statement for instance.

artifact

The Python definition of a artifact is set through the Python source tabs of the artifact dialog.

The code generation depend on the stereotype of the artifact :

The generated file name is the artifact's name with the extension specified in the first Python tab of the generations settings :

In BOUML the generated code is obtained by the substitution of macros in a text, the macros known by the Python code generator are :

Class

Bouml allows to define class for any releases of Python, to help for Python 2.2 classes generation a toggle Python 2.2 is defined in each class, its default value is set through the generation settings. When Python 2.2 is set and a class doesn't inherit in the model, the inheritance or object is automatically added.

The Python definition of a class is set through the Uml and Python tabs of the class dialog.

A Python type definition may be a class, or an enum defined through a class, depending on the stereotype and its translation in Python (see generation settings).

In BOUML the generated code is obtained by the substitution of macros in a text, the macros known by the Python code generator are :

In the special case where the class is declared external, its Python type declaration must contains a line indicating how the name of the class is generated, and followed by an optional line giving the needed import forms. By default the specification of the name is ${name} meaning that the name is produced unchanged, the only allowed keywords are ${name}, ${Name} and ${NAME}.

Operation

The Python definition of an operation is set through the Uml and Python tabs of the operation dialog.

In BOUML the generated code is obtained by the substitution of macros in a text, the macros known by the Python code generator are :

Notes :

Attribute

The Python definition of an attribute is set through the Uml and Python tabs of the attribute dialog.

An attribute may be a standard attribute or the item of an enumeration defined through a class.

The static attributes are produced in order directly in the class definition. The instance attributes are produced at the beginning of the operation __init__ when its definition contains ${body}. The operation __init__ is automatically added by the code generation, even if they are no instance attribute or relation.

Attribute corresponding to variable

In BOUML the generated code is obtained by the substitution of macros in a text, the macros known by the Python code generator are :

Relation

The Python definition of a relation is set through the Uml and Python tabs of the relation dialog.

The static relations corresponding to variables are produced in order directly in the class definition. The instance relations corresponding to variables are produced at the beginning of the operation __init__ when its definition contains ${body}. The operation __init__ is automatically added by the code generation, even if they are no instance attribute or relation.

Relation corresponding to variable

In BOUML the generated code is obtained by the substitution of macros in a text, the macros known by the Python code generator are :

Inheritance

The class inheritance are managed at the class level.

An inheritance implicitly produces an import form in the artifact if needed.

Dependencies

The dependencies allows to add import forms in the artifact, refer to ${import} description

Extra member

The Python definition of an extra member is set through the Python tabs of the extra member dialog.

The definition of the extra members are produced without any modification, this means you are also responsible to the indent

No macros.


Previous : Php roundtrip

Next : Python reverse