-
-
Notifications
You must be signed in to change notification settings - Fork 396
botserver: Allow importing custom bot modules. #523
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
Conversation
This documents the feature added in zulip/python-zulip-api#523.
|
Looks reasonable; is it easy to add a test for it? |
| # Wrapper around importutil; see https://stackoverflow.com/a/67692/3909240. | ||
| spec = importlib.util.spec_from_file_location("custom_bot_module", file_path) | ||
| lib_module = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(lib_module) # type: ignore # mypy thinks the `spec` is None in Optional[Loader]. |
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 you can use assert spec is not None for this. Though what happens if the file path is invalid? We might need code for that.
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.
This function is called from inside a try-except block, and we print:
except ImportError:
error_message = ("Error: Bot \"{}\" doesn't exist. Please make sure "
"you have set up the botserverrc file correctly.\n".format(bot))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.
(A slightly related issue in mypy: python/mypy#2420)
I'm working on tests for this, that should add additional checking for our purposes.
This documents the feature added in zulip/python-zulip-api#523.
This documents the feature added in zulip/python-zulip-api#523.
We can now specify path to a bot's python file as the ini section header in the botserver's config file. For example: [~/Documents/helloworld.py] email=a@b.com key=XXXX site=https://b.com token=XXXX
ee3089c to
602c442
Compare
602c442 to
ba9d901
Compare
|
Added tests, this is ready for review along with zulip/zulip#13090. |
ba9d901 to
9a0bb61
Compare
|
Squashed and merged, thanks @aero31aero! |
This documents the feature added in zulip/python-zulip-api#523.
This documents the feature added in zulip/python-zulip-api#523.
This documents the feature added in zulip/python-zulip-api#523.
We can now specify path to a bot's python file as the ini section
header in the botserver's config file. For example: