zivid / zivid-python

Official Python package for Zivid 3D cameras
BSD 3-Clause "New" or "Revised" License
40 stars 14 forks source link

Automatically generate front-end modules for datamodels #146

Closed eskaur closed 2 years ago

eskaur commented 2 years ago

While the Pybind11 equivalents of Zivid C++ data-models are automatically generated in the "_zivid" back-end module, it has been necessary to manually write/update the front-ends in the public "zivid" module. This means that unnecessary manual work has been needed every time the C++ data-models have been updated, and as a consequence of that not always being prioritized this has lead to lack of support for the most recent additions.

This improvement automatically adds support for the following settings that already existed in the back-end, but had not been added to the front-end:

This commit adds the following scripts:

datamodel_frontend_generator.py --dest-dir <destination>: Core implementation that generates source code for a hard-coded list of data models into a target directory.

generate_datamodels.sh: Script for installing dependencies and generating code in modules/zivid/

docker_generate_datamodels.sh: Script for running generate_datamodels.sh in Docker, to enable consistent results on any platform.

check_datamodels_up_to_date.py: Script to check that the source code in modules/zivid is up to date with the code that can be generated by datamodel_frontend_generator.py.

There are two reasons why the modules are committed and not generated as part of the build step:

The script check_datamodels_up_to_date.py is run as part of lint.sh to ensure that the committed data models are up to date. If the committed datamodels are out of date, the linting job will fail with the following type of message:

Comparing /host/modules/zivid/settings.py  <-->  /tmp/tmp21nhjawn/settings.py
...
RuntimeError:
Found difference in settings.py.
Please run './continuous-integration/code-generation/docker_generate_datamodels.sh' to regenerate data models.
trym-b commented 2 years ago

Let's merge https://github.com/zivid/zivid-python/pull/148#pullrequestreview-778220737 first whenever github actions begin operating normally again.