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 5, 2018
1 parent b9bab15 commit 8f758f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
15 changes: 6 additions & 9 deletions zulip_bots/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import generate_manifest

from zulip_bots import provision

ZULIP_BOTS_VERSION = "0.3.9"
IS_PYPA_PACKAGE = False

Expand Down Expand Up @@ -48,15 +50,6 @@
setuptools_info = dict(
install_requires=[
'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 +91,9 @@ def check_dependency_manually(module_name, version=None):
package_list.append('zulip_bots.bots.' + dir_name)
package_info['packages'] = package_list

# Install all requirements for all bots.
bot_paths = provision.get_bot_paths()
for bot_path in bot_paths:
provision.provision_bot(path_to_bot=bot_path, force=False)

setup(**package_info)
14 changes: 8 additions & 6 deletions zulip_bots/zulip_bots/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
import pip
from typing import Iterator

def get_bot_paths():
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,12 +73,7 @@ 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)
Expand Down

0 comments on commit 8f758f1

Please sign in to comment.