Skip to content

Local Development

Niyada edited this page Jul 7, 2024 · 9 revisions

Prerequisites

Software

To develop locally you will need to install the following software

Python & Dependencies

Python The transformer is written in Python 3.12.0.

Creating a conda environment with pip and python installed using:
conda create -n GCF-BPMN-PNML-transformer python=3.12.0 pip

Dependencies All dependencies needed for the project are listed in the requirements.txt file. For local development you can directly install the dependencies from the requirements.txt file into your created conda environment. Do not forget to activate your environment beforehand.

Installing Dependencies from requirements.txt:
pip install -r requirements.txt

IDE

For local development we suggest the following IDE:

Then perform the following action in VS Code:

  • Set the correct code Interpreter

    Hit CTRL + shift + P and type Pthon: select interpreter and choose the created conda environmentGCF-BPMN-PNML-transformer

  • Install the suggested Extensions

    Ruff, GitHub Actions

  • Configure the testing environment

    Go to the Testing Tab within VS Code and hit Configure Python Tests, then select pytest and the the /test directory.


Running Cloud Functions Locally

External Docs

Commands

The following table contains the commands needed for executing the corresponding cloud function.

Function Name Command
health functions-framework --target "get_health" --source "src/health/main.py" --signature-type "http" --port 8888
transform functions-framework --target "post_transform" --source "src/transform/main.py" --signature-type "http" --port 8888
checkTokens functions-framework --target "check_tokens" --source "src/checkTokens/main.py" --signature-type "http" --port 8888

Debugging

To Debug the local cloud function in the suggested IDE (MS VS Code) you will have to create a launch configuration. Do this by creating a launch.json file in the .vscode directory. The use the following template create you required launch / debug configs:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "<DISPLAY_NAME_OF_YOUR_CONFIG>", // display name of launch config
            "type": "python",
            "request": "launch",
            "python": "/Users/name/miniconda3/envs/GCF-BPMN-PNML-transformer/bin/python",               // path to python installation (of conda environment)
            "program": "/Users/name/miniconda3/envs/GCF-BPMN-PNML-transformer/bin/functions-framework", // path to functions framework installtion (of conda environment)
            "args": [
                "--target", "get_health",           // name of function
                "--source", "src/health/main.py",   // path to main.py file of cloud function
                "--signature-type", "http",
                "--port", "8888"
            ],
            "console": "integratedTerminal",
            "justMyCode": true,
            "env": { // Automatically set env for selecting the safe xml library on start
                "FORCE_STD_XML": "true"
            }
        },
    ]
}

Set your breakpoints and run the desired function by going to the `Run and debug` view, selecting the corresponding launch config in the top left corner and hitting the small green play button next to it.

Working with Docker

The transformer is also beeing deployed to the DHBW server as a docker container. Therefore a Dockerfile exists on the root level of the project that is used to build the corresponding image.

To build the image locally use the following command:

docker build  -t converter:latest .

To run and test the container from this image use:

docker run --rm -p 8080:8080 -e PORT=8080 converter:latest

Clone this wiki locally