diff --git a/zulip_botserver/README.md b/zulip_botserver/README.md new file mode 100644 index 0000000..30317e2 --- /dev/null +++ b/zulip_botserver/README.md @@ -0,0 +1,16 @@ +``` +zulip-bot-server --config-file --hostname
--port + +``` + +Example: `zulip-bot-server --config-file ~/flaskbotrc` + +This program loads the bot configurations from the +config file (flaskbotrc here) and loads the bot modules. +It then starts the server and fetches the requests to the +above loaded modules and returns the success/failure result. + +Please make sure you have a current flaskbotrc file with the +configurations of the required bots. +Hostname and Port are optional arguments. Default hostname is +127.0.0.1 and default port is 5002. diff --git a/zulip_botserver/setup.py b/zulip_botserver/setup.py new file mode 100755 index 0000000..34ac646 --- /dev/null +++ b/zulip_botserver/setup.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from __future__ import print_function + +import sys + +# We should be installable with either setuptools or distutils. +package_info = dict( + name='zulip_botserver', + version='0.3.1', + description='Zulip\'s Flask server for running bots', + author='Zulip Open Source Project', + author_email='zulip-devel@googlegroups.com', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Web Environment', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Topic :: Communications :: Chat', + ], + url='https://www.zulip.org/', + entry_points={ + 'console_scripts': [ + 'zulip-bot-server=zulip_botserver.server:main', + ], + }, + test_suite='tests', +) # type: Dict[str, Any] + +setuptools_info = dict( + install_requires=[ + 'zulip>=0.3.1', + 'zulip_bots>=0.3.1', + 'flask>=0.12.2', + ], +) + +try: + from setuptools import setup, find_packages + package_info.update(setuptools_info) + package_info['packages'] = find_packages(exclude=['tests']) + +except ImportError: + from distutils.core import setup + from distutils.version import LooseVersion + from importlib import import_module + + # Manual dependency check + def check_dependency_manually(module_name, version=None): + try: + module = import_module(module_name) + if version is not None: + assert(LooseVersion(module.__version__) >= LooseVersion(version)) + except (ImportError, AssertionError): + if version is not None: + print("{name}>={version} is not installed.".format( + req=req, version=version), file=sys.stderr) + else: + print("{name} is not installed.".format(name=module_name), file=sys.stderr) + sys.exit(1) + + check_dependency_manually('zulip', '0.3.1') + check_dependency_manually('zulip_bots', '0.3.1') + check_dependency_manually('flask', '0.12.2') + + package_info['packages'] = ['zulip_botserver'] + + +setup(**package_info) diff --git a/tests/__init__.py b/zulip_botserver/tests/__init__.py similarity index 100% rename from tests/__init__.py rename to zulip_botserver/tests/__init__.py diff --git a/tests/bot_server_test_lib.py b/zulip_botserver/tests/server_test_lib.py similarity index 76% rename from tests/bot_server_test_lib.py rename to zulip_botserver/tests/server_test_lib.py index 4e8ce90..e6878fb 100644 --- a/tests/bot_server_test_lib.py +++ b/zulip_botserver/tests/server_test_lib.py @@ -1,5 +1,5 @@ from unittest import TestCase -import zulip.bot_server +import zulip_botserver.server import json from typing import Any, List, Dict, Mapping @@ -7,8 +7,8 @@ class BotServerTestCase(TestCase): def setUp(self): # type: () -> None - zulip.bot_server.app.testing = True - self.app = zulip.bot_server.app.test_client() + zulip_botserver.server.app.testing = True + self.app = zulip_botserver.server.app.test_client() def assert_bot_server_response(self, available_bots=None, @@ -21,13 +21,13 @@ class BotServerTestCase(TestCase): # type: (List[str], Dict[str, Any], Dict[str, Any], str, Dict[str, Dict[str, Any]], bool) -> None if available_bots is not None: - zulip.bot_server.available_bots = available_bots + zulip_botserver.server.available_bots = available_bots if bots_config is not None: - zulip.bot_server.bots_config = bots_config + zulip_botserver.server.bots_config = bots_config if bots_lib_module is not None: - zulip.bot_server.bots_lib_module = bots_lib_module + zulip_botserver.server.bots_lib_module = bots_lib_module response = self.app.post(payload_url, data=json.dumps(message)) diff --git a/tests/test_bot_server.py b/zulip_botserver/tests/test_server.py similarity index 95% rename from tests/test_bot_server.py rename to zulip_botserver/tests/test_server.py index d0011d5..7aea135 100644 --- a/tests/test_bot_server.py +++ b/zulip_botserver/tests/test_server.py @@ -2,7 +2,7 @@ from __future__ import absolute_import import mock import unittest from typing import Any -from .bot_server_test_lib import BotServerTestCase +from .server_test_lib import BotServerTestCase class BotServerTests(BotServerTestCase): class MockMessageHandler(object): @@ -15,7 +15,7 @@ class BotServerTests(BotServerTestCase): # type: () -> Any return BotServerTests.MockMessageHandler() - @mock.patch('zulip.bot_server.ExternalBotHandler') + @mock.patch('zulip_botserver.server.ExternalBotHandler') def test_successful_request(self, mock_ExternalBotHandler): # type: (mock.Mock) -> None available_bots = ['testbot'] diff --git a/zulip_botserver/zulip_botserver/__init__.py b/zulip_botserver/zulip_botserver/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/zulip/bot_server.py b/zulip_botserver/zulip_botserver/server.py similarity index 97% rename from zulip/bot_server.py rename to zulip_botserver/zulip_botserver/server.py index de41659..555845e 100644 --- a/zulip/bot_server.py +++ b/zulip_botserver/zulip_botserver/server.py @@ -11,7 +11,7 @@ from werkzeug.exceptions import BadRequest from six.moves.configparser import SafeConfigParser from zulip import Client -from bots_api.bot_lib import ExternalBotHandler, StateHandler +from zulip_bots.lib import ExternalBotHandler, StateHandler bots_config = {} # type: Dict[str, Mapping[str, str]] available_bots = [] # type: List[str] @@ -33,7 +33,7 @@ def load_lib_modules(): # type: () -> None for bot in available_bots: try: - module_name = 'bots.{bot}.{bot}'.format(bot=bot) + module_name = 'zulip_bots.{bot}.{bot}'.format(bot=bot) bots_lib_module[bot] = import_module(module_name) except ImportError: print("\n Import Error: Bot \"{}\" doesn't exists. Please make sure you have set up the flaskbotrc "