diff --git a/ircbot/plugin/webserver.py b/ircbot/plugin/webserver.py index 215878c..3823c46 100644 --- a/ircbot/plugin/webserver.py +++ b/ircbot/plugin/webserver.py @@ -6,19 +6,24 @@ from types import ModuleType from typing import DefaultDict from typing import List +from typing import Optional from typing import Set from typing import Tuple from typing import TYPE_CHECKING +import cheroot.wsgi +from flask import abort from flask import Flask from flask import render_template if TYPE_CHECKING: + from ircbot.ircbot import CreateBot from ircbot.ircbot import Listener app = Flask(__name__) # Bot plugins, needed for the / route +create_bot: Optional[CreateBot] = None bot_plugins: List[Tuple[ModuleType, Set[Listener]]] = [] @@ -31,10 +36,17 @@ def route_base(): global bot_plugins if not bot_plugins: + # Shouldn't happen, the server is started after bot is set + if create_bot is None: + abort(500) + + # Satisfy mypy + bot: CreateBot = create_bot + # Compute and cache the bot's plugins bot_plugin_set: DefaultDict[ModuleType, Set[Listener]] = collections.defaultdict(set) - for listener in app.bot.listeners: - bot_plugin_set[app.bot.plugins[listener.plugin_name]].add(listener) + for listener in bot.listeners: + bot_plugin_set[bot.plugins[listener.plugin_name]].add(listener) bot_plugins = sorted(bot_plugin_set.items(), key=lambda p: p[0].__name__) @@ -53,6 +65,9 @@ def route_macros(): def start_server(bot): - port = os.getenv('HTTP_PORT', 8888) - app.bot = bot - app.run(host='0.0.0.0', port=int(port)) + global create_bot + port = int(os.getenv('HTTP_PORT', 8888)) + create_bot = bot + d = cheroot.wsgi.PathInfoDispatcher({'/': app}) + server = cheroot.wsgi.WSGIServer(('0.0.0.0', port), d) + server.start() diff --git a/requirements-dev.txt b/requirements-dev.txt index e2973b6..9707809 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,16 +1,18 @@ -aspy.yaml==1.2.0 -atomicwrites==1.3.0 -cfgv==1.6.0 -identify==1.4.3 -mypy==0.711 -mypy-extensions==0.4.1 +aspy.yaml==1.3.0 +cfgv==2.0.1 +identify==1.4.8 +mypy==0.750 +mypy-extensions==0.4.3 nodeenv==1.3.3 -pluggy==0.11.0 -pre-commit==1.16.1 +packaging==19.2 +pluggy==0.13.1 +pre-commit==1.20.0 py==1.8.0 -pytest==4.5.0 +pyparsing==2.4.5 +pytest==5.3.2 requirements-tools==1.2.1 -setuptools==41.0.1 toml==0.10.0 -virtualenv==16.6.0 +typed-ast==1.4.0 +typing-extensions==3.7.4.1 +virtualenv==16.7.8 wcwidth==0.1.7 diff --git a/requirements-minimal.txt b/requirements-minimal.txt index 162f45a..ec36d7d 100644 --- a/requirements-minimal.txt +++ b/requirements-minimal.txt @@ -1,4 +1,5 @@ celery[redis] +cheroot ckuehl-upsidedown flask github3.py diff --git a/requirements.txt b/requirements.txt index c1a25d9..c97d15f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,60 +1,60 @@ -amqp==2.4.2 -asn1crypto==0.24.0 -attrs==19.1.0 -billiard==3.6.0.0 +amqp==2.5.2 +attrs==19.3.0 +billiard==3.6.1.0 cached-property==1.5.1 celery==4.3.0 -certifi==2019.3.9 -cffi==1.12.3 +certifi==2019.11.28 +cffi==1.13.2 chardet==3.0.4 +cheroot==8.2.1 ckuehl-upsidedown==0.4 Click==7.0 cracklib==2.9.3 -cryptography==2.6.1 +cryptography==2.8 dnspython==1.16.0 -Flask==1.0.3 +Flask==1.1.1 github3.py==1.3.0 idna==2.8 -importlib-metadata==0.13 -inflect==2.1.0 +importlib-metadata==1.3.0 +inflect==3.0.2 irc==17.1 itsdangerous==1.1.0 jaraco.classes==2.0 -jaraco.collections==2.0 +jaraco.collections==2.1 jaraco.functools==2.0 jaraco.itertools==4.4.2 jaraco.logging==2.0 -jaraco.stream==2.0 -jaraco.text==3.0 -Jinja2==2.10.1 +jaraco.stream==3.0.0 +jaraco.text==3.2.0 +Jinja2==2.10.3 jwcrypto==0.6.0 -kombu==4.5.0 -ldap3==2.6 -markovify==0.7.1 +kombu==4.6.7 +ldap3==2.6.1 +markovify==0.7.2 MarkupSafe==1.1.1 -more-itertools==7.0.0 -ocflib +more-itertools==8.0.2 +ocflib==2019.11.12.16.30 pexpect==4.7.0 ply==3.11 ptyprocess==0.6.0 -pyasn1==0.4.5 +pyasn1==0.4.8 pycparser==2.19 -pycryptodome==3.8.1 -pycryptodomex==3.8.1 +pycryptodome==3.9.4 +pycryptodomex==3.9.4 PyMySQL==0.9.3 pysmi==0.3.4 -pysnmp==4.4.9 -python-dateutil==2.8.0 -pytz==2019.1 -PyYAML==5.1 -redis==3.2.1 +pysnmp==4.4.12 +python-dateutil==2.8.1 +pytz==2019.3 +PyYAML==5.2 +redis==3.3.11 requests==2.22.0 -six==1.12.0 -SQLAlchemy==1.3.3 +six==1.13.0 +SQLAlchemy==1.3.11 tempora==1.14.1 -Unidecode==1.0.23 +Unidecode==1.1.1 uritemplate==3.0.0 -urllib3==1.25.2 +urllib3==1.25.7 vine==1.3.0 -Werkzeug==0.15.4 -zipp==0.5.1 +Werkzeug==0.16.0 +zipp==0.6.0