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.
This commit is contained in:
parent
56a9cbe5af
commit
0893a5f61e
|
@ -5,6 +5,8 @@ from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import glob
|
||||||
|
import pip
|
||||||
if False:
|
if False:
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
|
@ -47,16 +49,8 @@ package_info = dict(
|
||||||
|
|
||||||
setuptools_info = dict(
|
setuptools_info = dict(
|
||||||
install_requires=[
|
install_requires=[
|
||||||
|
'pip',
|
||||||
'zulip',
|
'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_list.append('zulip_bots.bots.' + dir_name)
|
||||||
package_info['packages'] = package_list
|
package_info['packages'] = package_list
|
||||||
|
|
||||||
|
|
||||||
setup(**package_info)
|
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'])
|
||||||
|
|
|
@ -10,6 +10,14 @@ import glob
|
||||||
import pip
|
import pip
|
||||||
from typing import Iterator
|
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):
|
def provision_bot(path_to_bot, force):
|
||||||
# type: (str, bool) -> None
|
# type: (str, bool) -> None
|
||||||
req_path = os.path.join(path_to_bot, 'requirements.txt')
|
req_path = os.path.join(path_to_bot, 'requirements.txt')
|
||||||
|
@ -66,18 +74,13 @@ Example: ./provision.py helloworld xkcd wikipedia
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
options = parse_args(available_bots=get_bot_paths())
|
||||||
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)
|
|
||||||
|
|
||||||
if not options.quiet:
|
if not options.quiet:
|
||||||
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
|
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
|
||||||
|
|
||||||
for bot in options.bots_to_provision:
|
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__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue