Third party plugin

Description

Third-party plugins are non-program subdirectories, local modules from installations such as pip or easy_install.

The third-party plugin is easy to use, the program can not put the plugin code into the subdirectory, just use pip install to install to the local machine, and then pass the plugin_packages parameter when the PluginManager is initialized.

This means that anyone can write a package and publish it to pypi, and the user writes requirements.txt and installs the dependent plugin, which is called in the initialization, and almost no need to worry about subsequent third-party plugin upgrades.

Added in version 3.10.0: In this version, you can automatically install third-party packages in the install_packages parameter.

Format reference:

{"pkgs": ["PyPi-Project", "VCS-URL@branch#egg=package-name", "required"], "index":"pypi or mirror(optional)"}

Tip

The pkgs field is a list of packages, which can be PyPi packages, VCS URLs, or other package formats supported by pip.

If install with VCS URL, recommend carrying #egg=package-name to check if it has been installed and avoid duplicate installations.

If you want to install from a specific index, you can specify the index field, which defaults to empty.

To persist third-party plugins in a dedicated directory, set the application configuration item PLUGINKIT_PIP_TARGET_DIR; it is used as the pip target_dir both when auto-installing here and when installing from the web manager, so plugins survive virtualenv re-creation.

Changed in version 3.12.0: When publishing a plugin to the official hub (https://hub.saintic.com), you may add an optional module field next to name/pypi/github, holding the python module that can be imported directly (e.g. flask_pluginkit_demo).

Changed in version 3.12.0: In the web manager, plugin cards show whether the plugin is already installed and its installed version (resolved via flask_pluginkit.utils.pip_list, matching the PyPI package name, the importable module or the plugin name). Clicking Install on a community or official plugin opens a confirmation dialog showing the plugin name, version and the installation source (PyPI package name or git+https URL) before the task is actually submitted.

Changed in version 3.12.0: Plugin cards additionally show the latest available version: the PyPI version for packages published on PyPI, otherwise the latest release tag fetched from the GitHub Releases API (/repos/{full_name}/releases/latest). When a newer version than the installed one exists, the card shows an upgrade hint and the footer offers an Upgrade action that reuses the same confirmation dialog.

Local Plugin

It’s a package under the web application, which is part of the web application, and the plugin developer is the user, more see Plugin Structure.

How to develop plugins?

The local plugin only needs the first step, and the third party plugin needs to write setup.py, which requires the next few steps.

  1. First create a package, the metadata and register functions should be written in __init__.py, the core code can also be written in this file, of course, the recommended approach is to separate the module.

  2. The first step is actually the process of writing local plugins. In this step, you need to write setup.py, so that local plugins can be (published in pypi, optionally) used by others through pip:

from setuptools import setup
setup(
    name='flask_pluginkit_demo',
    packages=['flask_pluginkit_demo',],
    include_package_data=True,
    ..
)
  1. If your plugin contains template directory or static directory, you need to write an additional manifest file MANIFEST.in:

recursive-include flask_pluginkit_demo/templates *
recursive-include flask_pluginkit_demo/static *
  1. Testing, Release

The modules required by the following commands can be installed like this:

$ pip install -U pip twine wheel setuptools

4.1 Use pip install . to install to the local environment and test the plugin functionality.

4.2 If the plugin is as expected, it can be packaged and the command is: python setup.py sdist bdist_wheel, more parameters to adjust themselves.

4.3 Before the official release, you can post to test.pypi.org, which is the official pypi test site. The package inside will not be used easily. The command is: twine upload --repository-url https://test.pypi.org/legacy/ dist/*

4.4 The test station can look at the interface description and so on whether it meets the requirements of the heart, and publish it to the official station without problems, pypi.org, the command is: twine upload dist/*

  1. Third-party example