notifiers
notifiers copied to clipboard
feat: Add get providers from entry points
This PR is add a new function to allow get providers from entry points.
# setup.py
setup(
name="notfiers_xxx_provider",
package_dir={"": "."},
packages=find_packages("."),
entry_points={
"notfiers":
["provider1= notfiers_xxx_provider.Pushover2"],
["provider2= notfiers_xxx_provider.Pushover2"],
},
)
@liiight Please have a look at this PR and let me know what you think.
Could you elaborate on the use case for this please? If I understand correclty, this will allow a custom installation of notifiers with a specific provider as an entry point? If so, then:
- Why is that usefull?
- You can just use the regular CLI entry point and use an alias to create a command to a specific notifier (
alias foo="notifiers notify foo"
)
@liiight Thank you for your reply.
The recent modifications allow future providers to exist as plugins or extensions for notifiers.
Custom logic can be separated from the core code,
allowing other developers to develop their own providers and expose them to notifiers through entry_points
, which is more conducive to the expansion of notifiers' functionality.
For example, we have created a new repository called xxx_provider
. In the setup.py
file, we define:
setup(
name="xxx_provider",
package_dir={"": "."},
packages=find_packages("."),
entry_points={
"notifiers": [
"xxx_provider1= xxx_provider.main1",
"xxx_provider2= xxx_provider.main1",
],
},
)
Then, by installing notifiers and our custom-written xxx_provider using pip, we can use notifiers through a unified interface like this:
from notifiers import get_notifier
notifier = get_notifier('xxx_provider1')
notifier.notify(msgtype='text', api_key='1234', message='test')
Another reason is that sometimes we encounter some niche or internal applications that want to use the features of notifiers. With the new updates, relevant developers can extend notifiers without modifying the source code.
Oh, sort of like pytest enables its plugins to be loaded via the pytest11
name. Nice.
Can you please add an example for using this in the docs as well?
@liiight Added a sample docs for that.