Guides

API

Data integrations

Streaming pipelines

IO classes

Style guide

Linter

Install flake8 in your IDE to lint the Python code.

To run the linter locally, execute this script:

./scripts/server/lint.sh

Testing

Unit tests

Add unit tests for the feature in mage_ai/tests directory.

To run the tests locally, execute this script:

./scripts/server/test.sh

It is also possible to run unit tests directly in a live docker instance, as given in the following steps.

  1. Find out the backend server container name, with the command docker container ls in a terminal:
 % docker container ls

CONTAINER ID   IMAGE       COMMAND                  CREATED      STATUS          PORTS                    NAMES
8dbcfbe41755   mage/data   "./scripts/install_a…"   5 days ago   Up 38 minutes   0.0.0.0:3000->3000/tcp   mage-ai-app-1
b9d811e1e3e8   mage/data   "python mage_ai/serv…"   5 days ago   Up 38 minutes   0.0.0.0:6789->6789/tcp   mage-ai-server-1
  1. Start an interactive bash session with the backend server container:
% docker exec -it mage-ai-server-1 /bin/bash
  1. Run unit tests with the following command:
root@b9d811e1e3e8:/home/src# python3 -m unittest discover -s mage_ai.tests --failfast

Debugging

Instead of using breakpoint(), add the following line to your code where you want a debug:

import pdb; pdb.set_trace()

Attach to running container to use debugger. To get the container ID, run docker ps and look in the NAMES column.

docker attach [container_id]

Snippets

print(self.__dict__, locals()