LiquidBT plugins are classes that extend or modify functionality of LiquidBT.
Use a Plugin¶
To use a plugin, you need to:
- Import it at the top of your LiquidBT configuration file.
- Create an instance of the plugin's class in the
pluginslist that you pass to
- The plugin will be loaded!
Make a Plugin¶
Making a plugin is simple.
- Create a new Python package following the naming scheme
- In your
__init__.py, add this import:
from liquidbt.plugins import Plugin
- Add a
classwith the name of your plugin that extends the forementioned
Pluginclass. In this class, you can override any of the mentioned fields in the up-to-date API reference.
- Instruct your users to import and use your plugin. Easy as that.
A transformer plugin is a plugin that can change the code (not the source, the code that is compiled by setuptools).
To make a transformer, you need to set your plugin up like this:
from liquidbt.plugins import Plugin class MyPlugin(Plugin): def transform(code): # code will be a multiline string of the source code # the string returned will be given to setuptools return code def load(ctx): self.ctx = ctx self.ctx.register_transformer(self.transform)
To change the code, you will need to add the
process_code(code: str) -> str method to the class. This method accepts the parameter
code, which is a multiline string of the current file being evaluated's contents. It must return the changed version of the code (also a multiline string).
If you don't need to modify the file's contents, (for example if you make a plugin that comments out all code (bear with me here), and you want to skip certain files) you can just return the
code parameter, which will ensure that your plugin doesn't change anything.