Skip to content

uOttawaCapstone2023Issue1994 Documentation

FredWei-Git edited this page Dec 29, 2023 · 18 revisions

T43 Python Concurrency and Timing from Umple Documentation

Steps for generating Python from Umple

The approach for any of the features we are working on in the Umple Python generator. Based on the current features we have set up and working at Umple. We follow the following steps to develop and test Python generation:

  1. Create Umple file: Create an Umple file with the features that you want to translate into Python.
    Create an .ump file. You can find umple examples on https://cruise.umple.org/umpleonline/ and https://cruise.umple.org/umple/GettingStarted.html. You can also use umple files that are used for implementation tests at umple\cruise.umple\test\cruise\umple\implementation.
  2. Generate Java file from Umple file: look through the Java code that has been generated from the Umple file.
    Put the .ump file in the /dist folder in umple directory. In the dist folder, run the command java -jar ./umple.jar umplefile.ump where "umple.jar" is the umple jar file generated when you build umple and "umple.ump" is the name of the Umple file you want to generate the java of. In my dist folder, I would run the command java -jar ./umple-1.32.1.6535.66c005ced.jar Test.ump.
  3. Generate Python file from Umple file: look through the Python code that has been generated. If Python code has not been generated, it means that there is an error with generating the Python file. (Note: just because a Python file is created, does not mean it is correct. You should always test the Python code).
    To generate the python file of the umple file, run java -jar ./umple-1.32.1.6535.66c005ced.jar Test.ump -g python. It is exactly the same as the command for generating Java but you are adding "-g python" to the end.
  4. Create a Python equivalent of the Java file: Write a Python equivalent of a Java file generated from Umple that has the correct features to be generated so that you know what you need to change for the Python generated file.

You can also set-up a local version of umple online and generate Python from there.

Commands

Commands for generating Java and Python files in umple/dist folder:

java -jar ./umple-1.32.1.6535.66c005ced.jar -h

java -jar ./umple-1.32.1.6535.66c005ced.jar Test.ump

java -jar ./umple-1.32.1.6535.66c005ced.jar Test.ump -g python

(Note: replace "umple-1.32.1.6535.66c005ced.jar" with the name of the umple.jar file in your /dist folder)
TXL commands:

txl ./dist/Test.java ./UmpleToPython/txl/umpleJavaToPython.txl

TXL

TXL is the programming language used for translating Java to Python. Visit the TXL homepage: https://www.txl.ca/ for documentation, tutorials, and downloads. The umple\UmpleToPython\txl directory is where all the TXL grammar and rules used for translating Java to Python in Umple. In this folder, you have the umpleJavaToPython.ctxl file (ctxl file) which is updated everytime you do a full build or a quick build in umple. IMPORTANT: To have the updated TXL, copy the ctxl file from umple\UmpleToPython\txl and replace the ctxl file in umple\dist\txl (if you are generating Python in dist) and umple\umpleonline\scripts\txl (if you are generating Python in umpleonline)

Python Generator

View https://github.com/umple/umple/wiki/Working-on-the-Python-Generator. The Python generator is built on top of the Java generator, some additional files are made for modifying Python generation without affecting the Java generation. umple\UmpleToJava\UmpleTLTemplates\PythonDoActivities modifies the Python generation for active block and do activities.

Implementation Tests

Implementation tests are unit tests created for Python generation in umple\cruise.umple\test\cruise\umple\implementation\py and umple\cruise.umple\test\cruise\umple\statemachine\implementation\py (statemachine tests). Here you can have the test suites for Python generation. If you make any changes to the backend, you can run a quick build then run the tumple command (ant -f build.umple.xml template.test). You can see the results of the implementation tests in umple\dist\qa\cruise.umple.

Next Steps

As of December 2023, there are a lot of ignored tests in the PythonStateMachineTest test suite (located in umple\cruise.umple\test\cruise\umple\statemachine\implementation\py). Some of the features that still need to be worked on in the state machine are:

  • entry and exit actions
  • auto transition
  • queued sm (synchronized)
  • pooled keyword

The synchronized keyword has some incomplete use-cases that are preventing it from being deployed (see issue #2071).

  • If possible, rework the "TXL UGM" tag (wrapper allows for Python code to not be translated by TXL) in Java.Grm so that it doesn't have to wrap around the whole code block in a method. This would make working on the Python generation for state machines much easier.
Clone this wiki locally