zulip_bots setup.py: Install deps from the bots' requirements.txt files.
This makes it straightforward to add dependencies for a bot,
and works around
MODIFY
zulip_bots/setup.py
zulip_bots/setup.py
@@ -5,6 +5,8 @@ from __future__ import print_function
import os
import sys
+import glob
+import pip
if False:
from typing import Any, Dict, Optional
@@ -47,16 +49,8 @@ package_info = dict(
setuptools_info = dict(
install_requires=[
+ 'pip',
'zulip',
- 'mock>=2.0.0',
- 'html2text', # for bots/define
- 'BeautifulSoup4', # for bots/googlesearch
- 'lxml', # for bots/googlesearch
- 'requests', # for bots/link_shortener and bots/jira
- 'python-chess[engine,gaviota]', # for bots/chess
- 'wit', # for bots/witai
- 'apiai', # for bots/dialogflow
- 'simple_salesforce' # for bots/salesforce
],
)
@@ -98,5 +92,15 @@ except ImportError:
package_list.append('zulip_bots.bots.' + dir_name)
package_info['packages'] = package_list
-
setup(**package_info)
+
+# Install all requirements for all bots. get_bot_paths()
+# has requirements that must be satisfied prior to calling
+# it by setup().
+current_dir = os.path.dirname(os.path.abspath(__file__))
+bots_dir = os.path.join(current_dir, "zulip_bots", "bots")
+bots_subdirs = map(lambda d: os.path.abspath(d), glob.glob(bots_dir + '/*'))
+bot_paths = filter(lambda d: os.path.isdir(d), bots_subdirs)
+for bot_path in bot_paths:
+ req_path = os.path.join(bot_path, 'requirements.txt')
+ rcode = pip.main(['install', '-r', req_path, '--quiet'])

MODIFY
zulip_bots/zulip_bots/provision.py
zulip_bots/zulip_bots/provision.py
@@ -10,6 +10,14 @@ import glob
import pip
from typing import Iterator
+def get_bot_paths():
+ # type: () -> Iterator[str]
+ current_dir = os.path.dirname(os.path.abspath(__file__))
+ bots_dir = os.path.join(current_dir, "bots")
+ bots_subdirs = map(lambda d: os.path.abspath(d), glob.glob(bots_dir + '/*'))
+ paths = filter(lambda d: os.path.isdir(d), bots_subdirs)
+ return paths
+
def provision_bot(path_to_bot, force):
# type: (str, bool) -> None
req_path = os.path.join(path_to_bot, 'requirements.txt')
@@ -66,18 +74,13 @@ Example: ./provision.py helloworld xkcd wikipedia
def main():
# type: () -> None
- current_dir = os.path.dirname(os.path.abspath(__file__))
- bots_dir = os.path.join(current_dir, "bots")
- bots_subdirs = map(lambda d: os.path.abspath(d), glob.glob(bots_dir + '/*'))
- available_bots = filter(lambda d: os.path.isdir(d), bots_subdirs)
-
- options = parse_args(available_bots)
+ options = parse_args(available_bots=get_bot_paths())
if not options.quiet:
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
for bot in options.bots_to_provision:
- provision_bot(os.path.join(bots_dir, bot), options.force)
+ provision_bot(bot, options.force)
if __name__ == '__main__':
main()

zulip_bots setup.py: Install deps from the bots' requirements.txt files.

This makes it straightforward to add dependencies for a bot,
and works around https://github.com/pypa/pip/issues/4957.