How to add custom OpenMDAO modules to FAST-OAD as a plugin¶
Once you have created your custom modules for FAST-OAD (see How to add custom OpenMDAO modules to FAST-OAD), you may want to share them with other users, which can be done in two ways:
Providing your code so they can copy it on their computer and have them set their
custom_modules
field accordingly in their FAST-OAD configuration file.Packaging your code as a FAST-OAD plugin and have them install it through
pip
or equivalent.
To declare your custom modules as a FAST-OAD plugin, you have to package them the usual way
and declare them as a plugin with fastoad_model
as plugin group name.
This can be done classically with setuptools. It can also be done with Poetry, which is the way described below:
Plugin declaration¶
Assuming you project contains the package start_trek.drives
that contains
models you want to share, you can declare your plugin in your pyproject.toml
file with:
...
[tool.poetry.plugins."fastoad_model"]
"internal_models" = "start_trek.drives"
...
Once your pyproject.toml
is set, you can do poetry install
. Besides
installing your project dependencies, it will make your models locally available (i.e.
you could use their identifiers in your FAST-OAD configuration file without setting
the custom_modules
field)
Building¶
You can build your package with the command line poetry build
.
Let’s assume your pyproject.toml
file is configured so that your project name is
STST_drive_models
, as below:
...
[tool.poetry]
name = "ST_drive_models"
version = "1.0.0"
...
It will create a dist
folder with two files: ST_drive_models-1.0.0.tar.gz
and ST_drive_models-1.0.0-py3-none-any.whl
(or something like this).
You may then have sent any of those two files to another user, who may then install your models
using pip
with:
$ pip install ST_drive_models-1.0.0-py3-none-any.whl # or ST_drive_models-1.0.0.tar.gz
Publishing¶
Once you have built your package, you may publish it on a a package repository.
poetry publish
will publish your package on PyPI,
provided that you have correctly set your account.
Poetry can also publish to another destination.
Please see here for detailed information.