mirror of https://codeberg.org/dribdat/dribdat.git
Switch from Flask-Script to Click
This commit is contained in:
parent
304f43d14e
commit
7a39b2fa04
2
Procfile
2
Procfile
|
@ -1,4 +1,4 @@
|
||||||
web: gunicorn dribdat.app:create_app\(\) -b 0.0.0.0:$PORT -w 3 --log-file=-
|
web: gunicorn dribdat.app:init_app\(\) -b 0.0.0.0:$PORT -w 3 --log-file=-
|
||||||
init: python manage.py db init
|
init: python manage.py db init
|
||||||
migrate: python manage.py db migrate
|
migrate: python manage.py db migrate
|
||||||
upgrade: python manage.py db upgrade
|
upgrade: python manage.py db upgrade
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
"""Create an application instance."""
|
"""Create an application instance."""
|
||||||
from flask.helpers import get_debug_flag
|
from flask.helpers import get_debug_flag
|
||||||
|
|
||||||
from dribdat.app import create_app
|
from dribdat.app import init_app
|
||||||
from dribdat.settings import DevConfig, ProdConfig
|
from dribdat.settings import DevConfig, ProdConfig
|
||||||
|
|
||||||
CONFIG = DevConfig if get_debug_flag() else ProdConfig
|
CONFIG = DevConfig if get_debug_flag() else ProdConfig
|
||||||
|
|
||||||
app = create_app(CONFIG)
|
app = init_app(CONFIG)
|
||||||
|
|
|
@ -17,7 +17,7 @@ from dribdat.settings import ProdConfig
|
||||||
from dribdat.utils import timesince
|
from dribdat.utils import timesince
|
||||||
from flask_misaka import Misaka
|
from flask_misaka import Misaka
|
||||||
|
|
||||||
def create_app(config_object=ProdConfig):
|
def init_app(config_object=ProdConfig):
|
||||||
"""An application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/.
|
"""An application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/.
|
||||||
|
|
||||||
:param config_object: The configuration object to use.
|
:param config_object: The configuration object to use.
|
||||||
|
|
43
manage.py
43
manage.py
|
@ -1,46 +1,43 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from flask_script import Manager, Shell, Server
|
|
||||||
from flask_script.commands import Clean, ShowUrls
|
from flask import Flask
|
||||||
|
from flask.cli import FlaskGroup
|
||||||
from flask_migrate import MigrateCommand
|
from flask_migrate import MigrateCommand
|
||||||
|
|
||||||
from dribdat.app import create_app
|
from dribdat.app import init_app
|
||||||
from dribdat.user.models import User
|
from dribdat.user.models import User
|
||||||
from dribdat.settings import DevConfig, ProdConfig
|
from dribdat.settings import DevConfig, ProdConfig
|
||||||
from dribdat.database import db
|
from dribdat.database import db
|
||||||
|
|
||||||
if os.environ.get("DRIBDAT_ENV") == 'prod':
|
|
||||||
app = create_app(ProdConfig)
|
|
||||||
else:
|
|
||||||
app = create_app(DevConfig)
|
|
||||||
|
|
||||||
HERE = os.path.abspath(os.path.dirname(__file__))
|
HERE = os.path.abspath(os.path.dirname(__file__))
|
||||||
TEST_PATH = os.path.join(HERE, 'tests')
|
TEST_PATH = os.path.join(HERE, 'tests')
|
||||||
|
|
||||||
manager = Manager(app)
|
def shell_context():
|
||||||
|
"""Return context dict for a shell session"""
|
||||||
|
|
||||||
def _make_context():
|
|
||||||
"""Return context dict for a shell session so you can access
|
|
||||||
app, db, and the User model by default.
|
|
||||||
"""
|
|
||||||
return {'app': app, 'db': db, 'User': User}
|
return {'app': app, 'db': db, 'User': User}
|
||||||
|
|
||||||
|
def create_app(script_info=None):
|
||||||
|
"""Initialise the app object"""
|
||||||
|
if os.environ.get("DRIBDAT_ENV") == 'prod':
|
||||||
|
app = init_app(ProdConfig)
|
||||||
|
else:
|
||||||
|
app = init_app(DevConfig)
|
||||||
|
app.shell_context_processor(shell_context)
|
||||||
|
return app
|
||||||
|
|
||||||
@manager.command
|
cli = FlaskGroup(create_app=create_app)
|
||||||
|
|
||||||
|
@cli.command
|
||||||
def test():
|
def test():
|
||||||
"""Run the tests."""
|
"""Run the tests."""
|
||||||
import pytest
|
import pytest
|
||||||
exit_code = pytest.main([TEST_PATH, '--verbose'])
|
exit_code = pytest.main([TEST_PATH, '--verbose'])
|
||||||
return exit_code
|
return exit_code
|
||||||
|
|
||||||
|
cli.add_command('db', MigrateCommand)
|
||||||
manager.add_command('server', Server(port=5000))
|
|
||||||
manager.add_command('shell', Shell(make_context=_make_context))
|
|
||||||
manager.add_command('db', MigrateCommand)
|
|
||||||
manager.add_command("urls", ShowUrls())
|
|
||||||
manager.add_command("clean", Clean())
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
manager.run()
|
cli()
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
from webtest import TestApp
|
from webtest import TestApp
|
||||||
|
|
||||||
from dribdat.app import create_app
|
from dribdat.app import init_app
|
||||||
from dribdat.database import db as _db
|
from dribdat.database import db as _db
|
||||||
from dribdat.settings import TestConfig
|
from dribdat.settings import TestConfig
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ from .factories import UserFactory
|
||||||
@pytest.yield_fixture(scope='function')
|
@pytest.yield_fixture(scope='function')
|
||||||
def app():
|
def app():
|
||||||
"""An application for the tests."""
|
"""An application for the tests."""
|
||||||
_app = create_app(TestConfig)
|
_app = init_app(TestConfig)
|
||||||
ctx = _app.test_request_context()
|
ctx = _app.test_request_context()
|
||||||
ctx.push()
|
ctx.push()
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""Test configs."""
|
"""Test configs."""
|
||||||
from dribdat.app import create_app
|
from dribdat.app import init_app
|
||||||
from dribdat.settings import DevConfig, ProdConfig
|
from dribdat.settings import DevConfig, ProdConfig
|
||||||
|
|
||||||
|
|
||||||
def test_production_config():
|
def test_production_config():
|
||||||
"""Production config."""
|
"""Production config."""
|
||||||
app = create_app(ProdConfig)
|
app = init_app(ProdConfig)
|
||||||
assert app.config['ENV'] == 'prod'
|
assert app.config['ENV'] == 'prod'
|
||||||
assert app.config['DEBUG'] is False
|
assert app.config['DEBUG'] is False
|
||||||
assert app.config['DEBUG_TB_ENABLED'] is False
|
assert app.config['DEBUG_TB_ENABLED'] is False
|
||||||
|
@ -15,7 +15,7 @@ def test_production_config():
|
||||||
|
|
||||||
def test_dev_config():
|
def test_dev_config():
|
||||||
"""Development config."""
|
"""Development config."""
|
||||||
app = create_app(DevConfig)
|
app = init_app(DevConfig)
|
||||||
assert app.config['ENV'] == 'dev'
|
assert app.config['ENV'] == 'dev'
|
||||||
assert app.config['DEBUG'] is True
|
assert app.config['DEBUG'] is True
|
||||||
assert app.config['ASSETS_DEBUG'] is True
|
assert app.config['ASSETS_DEBUG'] is True
|
||||||
|
|
Loading…
Reference in New Issue