diff --git a/scripts/interpreter b/scripts/interpreter old mode 100644 new mode 100755 index e69de29..7064968 --- a/scripts/interpreter +++ b/scripts/interpreter @@ -0,0 +1,33 @@ +#!/usr/bin/env python +"""isort:skip_file +""" +import os +import sys; sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..")) # noqa + +import readline +from code import InteractiveConsole + +from molten.contrib.sqlalchemy import Session + +from index import create_app + +app = create_app() +resolver = app.injector.get_resolver() + + +@resolver.resolve +def get_session(session: Session): + return session + + +helpers = { + "app": app, + "resolver": resolver, + "session": get_session(), +} + +readline.parse_and_bind("tab: complete") +interpreter = InteractiveConsole(helpers) +interpreter.interact(f"""\ +Instances in scope: {", ".join(helpers)}. +""", "") \ No newline at end of file diff --git a/tasks.py b/tasks.py index d699cd1..c0a3728 100644 --- a/tasks.py +++ b/tasks.py @@ -8,11 +8,17 @@ def test(c, cov=False, verbose=False): pytest_command += ' --cov=api' if verbose: pytest_command += ' -s ' - c.run(pytest_command) + c.run(pytest_command, pty=True) @task -def start(c, log_level='info'): - gunicorn_command = 'export ENVIRONMENT=common && gunicorn --reload app:app' +def start(c, log_level='info', port=5000): + gunicorn_command = 'export ENVIRONMENT=common && export PORT={} && gunicorn --reload app:app'.format(port) gunicorn_command += ' --log-level={}'.format(log_level) - c.run(gunicorn_command) + c.run(gunicorn_command, pty=True) + + +@task +def shell(c): + command = 'export ENVIRONMENT="common" && ./scripts/interpreter' + c.run(command, pty=True)