DEV Community

kAZUYA tAKEI
kAZUYA tAKEI

Posted on

Create Errbot backend/storage plugin as PyPI package

In develoving some Errbot plugins, I am thinking that storage and backend plugins have better managed as package (if possible, should be register at PyPI)

1. In bootstrapping, Errbot does not install dependencies of backend and backend.

To run bot, I call errbot command. In this command, load plugins in order of storage, backend and bot-plugins.
When bootstrap load storage and backend plugin, it does not check dependencies.

Actually some plugins let to install dependencies by command-line.

ex:

If plugins have dependencies and need to install manually these, I think better to define as module and package.

2. In running, Errbot does not change dynamically storage and backend.

Errbot is running as daemon generally. for that reason, storage and backend plugin will not almost be changed in running.

Therefore, these can be managed as requirements together with Errbot core.
If this, pip install -r requirements.txt in your local repository can install all dependencies.

ex: (these plugins are not registered in PyPI)

errbot
errbot-backend-gitter
errbot-storage-firebase

Create as project

List of files

Project structure is same to standard python package.

  • setup.py
  • setup.cfg
  • README.rst
  • MANIFEST.in
  • errbot_backend_demo
    • __init__.py
    • demo.py
    • demo.plug

Writings

setup.py

It can write simply.

#!/usr/bin/env python
from setuptools import setup

setup()

setup.cfg

Currently, all metadata can write in setup.cfg.
Please define options.package_data section and include_package_data key to include .plug file as installation resource.

[metadata]
name = errbot-backend-demo
version = attr:errbot_backend_demo.__version__
author = Kazuya Takei
author_email = attakei@example.com
description = Demo backend plugin for Errbot
long_description = file:README.rst

[options]
install_requires = YOUR_DEPENDENCIES
packages = find:
include_package_data = True

[options.package_data]
errbot_backend_demo = *.plug

LICENSE.rst

Write normally.

MANIFEST.in

As same as setup.cfg, define .plug as include file.

include errbot_backend_demo/*.plug

__init__.py

Define version of package here. And define function to return path of installation path.

from pathlib import Path


__version__ = '0.0.1-alpha.1'


def get_plugin_dir() -> str:
    module_dir = Path(__file__).parent
    return str(module_dir)

demo.py and demo.plug

Write normally as plugin.

Use in Errbot config.py

If plugin define as package by these, you can write config.py to use plugin.

import errbot_backend_demo

BOT_EXTRA_BACKEND_DIR = errbot_backend_demo.get_plugin_dir()
BACKEND = 'Demo'

Top comments (0)