itwinai-plugin-template
Template for itwinai plugin, useful for use cases code to be included in the main library
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.5%) to scientific vocabulary
Repository
Template for itwinai plugin, useful for use cases code to be included in the main library
Basic Info
- Host: GitHub
- Owner: interTwin-eu
- License: apache-2.0
- Language: Python
- Default Branch: main
- Size: 229 KB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
- Releases: 2
Metadata Files
README.md
Writing plugins for itwinai
It would be beneficial to integrate the interTwin use case code directly into itwinai, providing an easy way to distribute and compare AI methods used by various researchers.
However, requiring all researchers to maintain their code within the itwinai repository can be complicated and may create an unnecessary barrier for newcomers interested in joining this ecosystem. Researchers and use case developers often prefer the flexibility of developing their code in a separate repository. This allows them to independently manage the packaging and publishing of their software, for instance, by releasing it to PyPI when it best suits their needs.
To address this challenge, itwinai implements a plugin architecture, allowing the community to independently develop sub-packages for itwinai. These sub-packages can later be installed from PyPI and imported into Python code as if they were part of itwinai. This is made possible by namespace packages.
Itwinai plugins are developed by assuming that the plugin logic,
once installed alongside itwinai, will be accessible under
the itwinai.plugins.* namespace. Example:
```python from itwinai.plugins.myawesomeplugin import awesome_module
Call a function implemented by the plugin
awesomemodule.awesomefunction(some=1, argument='foo')
Instantiate a class implemented by the plugin
myobj = awesomemodule.AwesomeClass(another='bar', arg=False) ```
Similarly, you can import modules from plugin's subfolders. In this case:
```python from itwinai.plugins.myawesomeplugin.pluginsubfolder import anothermodule
Call some function
anothermodule.anotherfunction()
from itwinai.plugins.myawesomeplugin.anotherpluginsubfolder import yetanothermodule
Call some function
yetanothermodule.yetanotherfunction() ```
How to write a new plugin
To write a new plugin, you can take inspiration from this repository, and you can also use it as a template when creating a new repository in GitHub.
[!NOTE] Do NOT contribute directly to the plugin template repository, rather use it as a GitHub repository template, or fork it, or copy it.
The plugin template repository describes a python project using
a pyproject.toml, where the following configuration declares
that the Python package implemented by the plugin belongs under
the itwinai.plugins.* namespace:
```toml [tool.setuptools.packages.find]
Declare this package as part of the itwinai.plugins namespace
where = ["src"]
List plugin folders and subfolders
include = [ "itwinai.plugins.myawesomeplugin", "itwinai.plugins.myawesomeplugin.pluginsubfolder", "itwinai.plugins.myawesomeplugin.anotherplugin_subfolder", ] ```
[!CAUTION] Make sure to list all the plugin subfolders in the
includefield of thepyproject.tomlfile, otherwise the plugin may not be installed correctly and plugin sub-packages may not be visble!
As a plugin developer, all you have to do is maintaining your Python
packages and modules under src/itwinai/plugins.
[!WARNING] It is important to use an original name for the root package of your plugin (
my_awesome_pluginin the example above). Avoid reusing existing plugin names, otherwise your plugin may be overridden by another one when installed at the same time!
Also, be minful of the Python packaging rules!
[!IMPORTANT]
Since your plugin is a Python library, remember that each package and sub-package (i.e., folder and sub-folder) must contain at least one__init__.pyfile, even if empty. Otherwise it will not be possible to correctly import the modules from the plugin.
Alternatively, instead of a pyproject.toml, you can as well use the
legacy setup.py to describe your plugin package. In that case, remember
to add the following arguments to the setup function, to ensure the correct
installation of the plugin under the itwinai.plugins namespace:
```python from setuptools import setup, findnamespacepackages
setup(
name='itwinai-awesome-plugin',
...
packages=findnamespacepackages(where='src/', include=['itwinai.plugins.myawesomeplugin']),
packagedir={'': 'src'},
installrequires=['itwinai'], # Ensure itwinai is installed
...
)
```
Docker containers
In this template repository you can already find two sample Dockerfiles as
example to build your containers under env-files using the itwinai container
images as a base.
Dockerfileprovides an example of recipe that you would like to use to define a general purpose container, to be executed on cloud or on HPC.jupyter.Dockerfileis an example of JupyterLab container based on the itwinai one.
In this repository you can also find a .dockerignore file, which lists all the
files and directories to be ignored by docker build. Make sure to customize it
to your needs!
Writing unit and integration tests
It is good practice to write tests for your code, and the itwinai plugins are not
an exception! Find some examples of unit tests under tests/, which can be
launched with pytest from the root of the repository with:
bash
pytest -v tests/
Learn more about pytest here.
Notice that the tests will be executed automatically in the GitHub Actions space
every time you push to the main branch. You can change this behavior editing the
file at .github/workflows/pytest.yaml.
Installing a plugin
An end user can install a plugin directly from its repository or from PyPI (if available).
To use a plugin in your code, install it alongside itwinai:
```bash
Install itwinai
pip install itwinai
Now, install one or more plugins
pip install itwinai-awesome-plugin
Or directly from the plugin's repository
pip install itwinai-awesome-plugin@git+https://github.com/USER/PROJECT@BRANCH ```
Conversely, a plugin developer may be interested in installing the plugin in editable mode from the project directory:
```bash git clone git@github.com:USER/REPOSITORY.git && cd REPOSITORY
After having installed itwinai with its dependencies,
install the plugin from source in editable mode.
pip install --editable . ```
Beware of installations in editable mode
When a package is installed in editable mode, it creates a symlink to the source directory, which works differently from how non-editable packages are installed. Namespace packages can behave inconsistently when some parts are installed in editable mode and others are not.
To check whether a package was installed in editable mode you can use
pip show PACKAGE_NAME. Editable packages show an "Editable" path
in the output of the command.
[!WARNING] When itwinai, the core library, is installed in editable mode also the plugin must be installed in editable mode. Otherwise, the plugin may not be visible when imported.
From empirical experience, the following installation configurations seem to be working:
- itwinai: editable, plugin: editable
- itwinai: non-editable, plugin: non-editable
- itwinai: non-editable, plugin: editable
Owner
- Name: interTwin Community
- Login: interTwin-eu
- Kind: organization
- Email: info@intertwin.eu
- Website: https://www.intertwin.eu/
- Twitter: interTwin_EU
- Repositories: 1
- Profile: https://github.com/interTwin-eu
Co-designing and prototyping an interdisciplinary Digital Twin Engine.
Citation (CITATION.cff)
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!
cff-version: 1.2.0
title: itwinai-plugin-template
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- given-names: Matteo
family-names: Bunino
email: matteo.bunino@cern.ch
affiliation: CERN
orcid: 'https://orcid.org/0009-0008-5100-9300'
repository-code: 'https://github.com/interTwin-eu/itwinai-plugin-template'
url: 'https://itwinai.readthedocs.io/'
abstract: AI on cloud and HPC made simple for science
keywords:
- Artificial intelligence
- Machine learning
- Digital twins
- Climate research
- Physics research
license: Apache-2.0
GitHub Events
Total
- Create event: 5
- Release event: 2
- Issues event: 1
- Delete event: 6
- Push event: 40
- Pull request review event: 2
- Pull request review comment event: 3
- Pull request event: 10
- Fork event: 2
Last Year
- Create event: 5
- Release event: 2
- Issues event: 1
- Delete event: 6
- Push event: 40
- Pull request review event: 2
- Pull request review comment event: 3
- Pull request event: 10
- Fork event: 2
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 1
- Total pull requests: 7
- Average time to close issues: 5 months
- Average time to close pull requests: 2 days
- Total issue authors: 1
- Total pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 0.0
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 2
Past Year
- Issues: 1
- Pull requests: 7
- Average time to close issues: 5 months
- Average time to close pull requests: 2 days
- Issue authors: 1
- Pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 0.0
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 2
Top Authors
Issue Authors
- matbun (1)
Pull Request Authors
- matbun (5)
- dependabot[bot] (2)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout v4 composite
- gaurav-nelson/github-action-markdown-link-check v1 composite
- actions/checkout v4 composite
- docker://ghcr.io/github/super-linter slim-v4 composite
- itwinai *