Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-david committed Jan 17, 2022
1 parent c1d202f commit 57aaa36
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
60 changes: 55 additions & 5 deletions docs/documentation/custom_modules/add_plugin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,60 @@ 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
:code:`custom_modules` field accordingly in their :ref:`configuration-file`.
- Packaging your code as a FAST-OAD plugin and have them install it through :code:`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 :code:`fastoad_model` as plugin group name.
or equivalent. This is the subject of current chapter.

A FAST-OAD plugin can provide additional FAST-OAD modules, Jupyter notebooks and configuration files:

- plugin-provided FAST-OAD modules are usable in :ref:`configuration files <configuration-file>`
and can be listed ans used in the same way as native modules (see :ref:`get-module-list`).
- plugin-provided notebooks can be accessed using :ref:`dedicated command<python-usage>`.
- plugin-provided configuration files can be used with :ref:`dedicated command<generate-conf-file>`.

Plugin structure
################
In your source folder, a typical plugin structure would be like this::

my_package/
├── __init__.py
├── configurations/
│ ├── __init__.py
│ ├── configuration_1.yaml
│ └── configuration_2.yaml
├── models/
│ ├── __init__.py
│ ├── my_model.py
│ └── some_subpackage/
│ ├── __init__.py
│ └── some_more_code.py
└── notebooks/
├── __init__.py
├── any_data/
│ ├── __init__.py
│ └── some_data.xml
├── awesome_notebook.ipynb
└── good_notebook.ipynb

As shown above, the expected structure is composed of Python **packages**, i.e. every folder should
contain a :code:`__init__.py` file.
The root folder can be anywhere in your project structure, since plugin declaration will point to
its location.
Also, expected folders in a plugin package are:

- :code:`models`: contains Python code where FAST-OAD modules are :ref:`registered<add-modules>`.
- :code:`configurations`: contains only configuration files in YAML format. No sub-folder is
allowed. These configuration files will be usable through :ref:`command line<generate-conf-file>`
or API method :meth:`~fastoad.cmd.api.generate_configuration_file`.
- :code:`notebooks`: contains any number of Jupyter notebooks and associated data, that will
be made available to users through :ref:`command line<python-usage>`.

Any of these folders is optional.


Plugin packaging
################

To declare your package as a FAST-OAD plugin, you have to package it the usual way
and declare it as a plugin with :code:`fastoad.plugins` as plugin group name.

This can be done classically with `setuptools <https://packaging.python.org/guides/creating-and-discovering-plugins/#using-package-metadata>`_.
It can also be done with `Poetry <https://python-poetry.org>`_, which is the way described below:
Expand All @@ -22,11 +72,11 @@ It can also be done with `Poetry <https://python-poetry.org>`_, which is the way
:local:
:depth: 1


******************************
Plugin declaration
******************************


Assuming you project contains the package :code:`start_trek.drives` that contains
models you want to share, you can declare your plugin in your :code:`pyproject.toml`
file with:
Expand Down
17 changes: 9 additions & 8 deletions docs/documentation/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,22 @@ FAST-OAD can provide a ready-to use configuration.
$ fastoad gen_conf my_conf.yml --from_package my_plugin_package --source sample_configuration_1.yml
This copies the file `sample_configuration_1.yml` provided by installed package `my_plugin_package`
to file `my_conf.yml`.
This copies the file :code:`sample_configuration_1.yml`provided by installed package
:code:`my_plugin_package` to file :code:`my_conf.yml`.

See :ref:`how to get plugin information<pluging-info>`for listing the values you can put for
options `--from_package` and `--source`.
See :ref:`how to get plugin information<plugin-info>` for listing the values you can put for
options :code:`--from_package` and :code:`--source`.

If only one package is available, option `--from_package` may be omitted.
If the selected package provides only one configuration file, option `--source` may be omitted.
If only one package is available, option :code:`--from_package` may be omitted.
If the selected package provides only one configuration file, option :code:`--source` may be omitted.

Hence with FAST-OAD installed (version below 2.0) without additional plugin, the command can be:

.. code:: shell-session
$ fastoad gen_conf my_conf.yml
.. _get-module-list:
.. _`get-module-list`:

How to get list of registered modules
=====================================
Expand Down Expand Up @@ -503,4 +505,3 @@ To do so, type this command **in your terminal**:
$ fastoad notebooks
Then run the Jupyter server as indicated in the obtained message.

File renamed without changes.

0 comments on commit 57aaa36

Please sign in to comment.