Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add get providers from entry points #469

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

loonghao
Copy link

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"],
    },
)

@loonghao
Copy link
Author

@liiight Please have a look at this PR and let me know what you think.

@loonghao loonghao force-pushed the get_providers_from_entry_points branch from 6653786 to 5228ee4 Compare April 18, 2024 08:40
@liiight
Copy link
Owner

liiight commented Apr 29, 2024

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:

  1. Why is that usefull?
  2. 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")

@loonghao
Copy link
Author

@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.

@liiight
Copy link
Owner

liiight commented Apr 30, 2024

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?

@loonghao
Copy link
Author

@liiight Added a sample docs for that.

source/usage.rst Outdated Show resolved Hide resolved
@loonghao loonghao force-pushed the get_providers_from_entry_points branch from 82ca163 to 2a7d54b Compare May 3, 2024 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants