From 82ca1630d48ba0cb8fdee4497f75ad9dfe9dba5f Mon Sep 17 00:00:00 2001 From: loonghao Date: Tue, 30 Apr 2024 17:12:18 +0800 Subject: [PATCH] docs: Add usage.rst for get providers from entry points --- source/usage.rst | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/source/usage.rst b/source/usage.rst index 66b35008..07907695 100644 --- a/source/usage.rst +++ b/source/usage.rst @@ -207,3 +207,32 @@ You can also use the ``ok`` property: ['application token is invalid'] +Writing your own providers +----------------- +Making your provider installable by others +If you want to make your provider externally available, +you may define a so-called entry point for your distribution so that notifiers finds your provider module. +Entry points are a feature that is provided by Documentation. +notifiers looks up the `notifiers` entrypoint to discover its providers and you can thus make your provider available +by defining it in your setuptools-invocation: + +.. code:: python + + >>> # sample ./setup.py file + >>> from setuptools import setup + + >>> setup( + >>> name="myproject", + >>> packages=["myproject"], + >>> # the following makes a plugin available to notifiers + >>> entry_points={"notifiers": ["name_of_provider = myproject.provider"]}, + >>> ) + +If a package is installed this way, pytest will load myproject.provider as a provider for notifiers. + +.. code:: python + + >>> from notifiers import get_notifier + >>> notifier = get_notifier('name_of_provider') + >>> notifier.notify(msgtype='text', api_key='1234', message='test') +