Python Code Generation
NB The python code generation should currently be regarded as alpha quality in that it does not serialize model instances to something that is interoperable with the Java generated code. Indeed it is not yet guaranteed to be representing the VO-DML model fully.
Using
The command
gradle vodmlPythonGenerate
./build/generated/sources/vodml/python
directory by default (changeable with the outputPythonDir
vodml setting).
The code uses xsdata for XML and JSON serialization and SQLAlchemy for the RDB serialization.
environment
Although the code generation itself does not need python, to run any tests in the project relies on (https://github.com/xvik/gradle-use-python-plugin) to manage python virtualenv (i.e. https://virtualenv.pypa.io/en/latest/index.html - not all the other ones). This creates the virtualenv in venv directory at top level - it does not seem to do that properly, so it is best to do that manually beforehand...
gradle pipInstall
Depends on python 3.10+
testing
The project is set up with a single python test at the moment that can be run with
gradle pytest
notes
- difficult to make xsdata and SQlAlchemy work together as they both want to use the same typing style - the generated code is using SQLAlchemy legacy style to allow both libraries to work simultaneously with the same dataclasses.
- VO-DML dataTypes -> composites? https://docs.sqlalchemy.org/en/20/orm/composites.html#nesting-composites
- with Dataclasses kw_only attributes seem the only practical route when there is inheritance, otherwise ordering the kw arguments after the others is painful in the code...