Skip to content

Commit

Permalink
zulip_bots setup.py: Install deps from the bots' requirements.txt files.
Browse files Browse the repository at this point in the history
This makes it straightforward to add dependencies for a bot,
and works around pypa/pip#4957.
  • Loading branch information
roberthoenig committed Jan 6, 2018
1 parent 691882b commit 23bd192
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
24 changes: 14 additions & 10 deletions zulip_bots/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import os
import sys
import glob
import pip
if False:
from typing import Any, Dict, Optional

Expand Down Expand Up @@ -47,16 +49,8 @@

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

Expand Down Expand Up @@ -98,5 +92,15 @@ def check_dependency_manually(module_name, version=None):
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'])
17 changes: 10 additions & 7 deletions zulip_bots/zulip_bots/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
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')
Expand Down Expand Up @@ -66,18 +74,13 @@ def parse_args(available_bots):

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()

0 comments on commit 23bd192

Please sign in to comment.