Template

We will start by creating a new repository for this Python package, using the template that is available here.

alternate text

Screenshot of the EAGERx template package on Github.

As you can see, this template repository already contains some folders and files. The main benefit of using this template, is that it facilitates to perform continuous integration and provides a clear code structure. Since the package is just a Python package in the end, any other Python package structure could be used.

In our case, we create a new repository called eagerx_ode using this template. Since we want to create a package named eagerx_ode and not eagerx_template, we do the following:

  • Rename the folder eagerx_template to eagerx_ode.

  • Update the PACKAGE_NAME variable in Makefile to be eagerx_ode instead of eagerx_template.

Poetry

Next we will create a Python package using Poetry. If you are not familiar with Poetry, we recommend to check out this article. It is a very convenient tool for package management. In the remainder of this section it is assumed that Poetry is installed.

Next, we modify the pyproject.toml file to specify dependencies, add a short description, state the authors of the package etc. . Here we specify scipy as dependencies, since we will be using scipy to perform the integration of the ODEs. This results following pyproject.toml.

Now we are ready to start coding! Note that you can always add or update dependencies later using Poetry.

After adding the source code, installing the package is simple (from the root of the repository):

poetry install

Note

This will install the package and its dependencies in a virtual environment, see https://python-poetry.org/docs/basic-usage/#using-your-virtual-environment.

Black

In the eagerx_template, we also make use of black. According to their docs:

“By using Black, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.”

It allows to automatically format your code such that it satisfies the Black code style requirements and allows to check these. In the eagerx_template this can be done as follows. First, we install the package using Poetry:

poetry install

Next, we activate the poetry environment that is created during installation:

poetry shell

Now we can format the code using black:

make codestyle

Also, we can check the code style:

make check-codestyle

Note

A number of Github workflows are present within the eagerx_template. One of them checks for code style using Black. Therefore, when using this template for a public Github repository, don’t forget to run: make codestyle before pushing your code.

pytest

Also, the eagerx_template allows to easily add tests using pytest. You can add your own tests to the tests folder. Only a dummy test is currently present here. You can run the test as follows (from the root of the repository):

First, we install the package using Poetry (if you haven’t done so yet):

poetry install

Next, we activate the poetry environment that is created during installation:

poetry shell

Now we run the tests:

make pytest

Note

A number of Github workflows are present within the eagerx_template. One of them checks if the tests are passing. So before pushing your code, you can check whether the tests are passing locally by running make pytest.

Note

Be aware that in order to use a Node, EngineNode or any other enitity from eagerx.core.entities you have created, that they should be imported before making them using make() with the corresponding ID. Therefore, we advice to import these in the __init__.py as is done for example here.