-
-
Notifications
You must be signed in to change notification settings - Fork 377
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
Bots: Add support for running packaged bots via entrypoints #708
Conversation
The previous implementation to locate the `bot_dir` is unfortunately wrong as it doesn't work with the external custom bots.
…paths. This removes the need to have `load_module_from_file`.
6435a64
to
ad578c0
Compare
0dfc2c3
to
11f29b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PIG208 Thanks so much for working on this! This PR is looking good, I left a few minor comments/suggestions. As always, if you have any questions, please feel free to reach out. Cheers!
"packages": find_packages(), | ||
} | ||
|
||
setup(**package_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.. have we thought about if these will be installed alongside the zulip_bots
PyPI package or not? @timabbott My guess is we should keep these as separate packages? Although, that adds more release work to our process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regardless, we need to improve our automated release process if we are going to do this. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it won't be necessary. Since this package is only for demonstration and zulip_bots
hardly rely on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think it's probably fine to have this be in the same repository for now. When we write documentation for this, I think what we'll actually want is a zulip-new-bot bot_name
command that creates a directory of this form for you, so that we can have really simple steps for making a new bot.
zulip_bots/zulip_bots/run.py
Outdated
print(dep_err_msg.format(bot_name=bot_name, deps_list=deps_list)) | ||
bot_source, lib_module = finder.import_module_from_zulip_bot_registry(args.bot) | ||
except finder.DuplicateRegisteredBotName: | ||
print("ERROR: Found duplicate entries for bot name in zulip bot registry. Exiting now.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to give more information here as to how to resolve the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I think displaying the conflicting entrypoint should be fairly sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that's right.
Now we will be able to execute `zulip-run-bot` with the `-r` argument to search for and run bots from the `zulip_bots.registry` entry_point. Each entry point should have the name correspond to the bot name, and have the value be the bot module. E.g, an Python package for a bot called "packaged_bot" should have an `entry_points` setup like the following: setup( ... entry_points={ "zulip_bot.registry":[ "packaged_bot=packaged_bot.packaged_bot" ] } ... ) whose file structure may look like this: packaged_bot/ ├───packaged_bot/ | ├───packaged_bot.py # The bot module | ├───test_packaged_bot.py | ├───packaged_bot.conf | └───doc.md └───setup.py # Register the entry points here Add test case.
Amend tests to include new parameter.
Add packaged_helloworld as an example of a PyPI package setup for an external zulip bot that can be installed via pip and lanuched without the need to include it in the zulip_bots/bots directory.
I fixed a typo in one of the docstrings, and merged this. I think we will probably want to iterate further on the concept, but the best way to do this is to push on the documentation for how to create your own bot -- ideally we want it to be really simple and not involve manual copy-paste work. I posted an idea above that we could have a tool generate a template bot for you (that you can then The other option is that we offer a GitHub repository for you to fork; but the problem with that is that you'll now have a repository for |
It's great to see this merged! Thanks @PIG208 ! 🎉 |
Following support to running bots from entry points in zulip#708, we implement this `create-zulip-bot` tool to simplify the process of creating new bots. The user will be able to directly install the package with pip and run the bot with `zulip-run-bot`, or use it to quickly set up a git repository. Note that the boilerplate generated by this script does not contain `tests.py` yet. We need to figure out the right pattern for integrating unittests for such packaged bots.
Following support to running bots from entry points in zulip#708, we implement this `create-zulip-bot` tool to simplify the process of creating new bots. The user will be able to directly install the package with pip and run the bot with `zulip-run-bot`, or use it to quickly set up a git repository. Note that the boilerplate generated by this script does not contain `tests.py` yet. We need to figure out the right pattern for integrating unittests for such packaged bots.
This revives #517;
TODO:
importlib.metadata
orimportlib_metadata
instead ofentrypoints
(which doesn't seem to be actively maintained)