<commit_before># encoding: utf-8
# pylint: disable=too-many-arguments
"""
Application execution related tasks for Invoke.
"""

try:
    from importlib import reload
except ImportError:
    pass  # Python 2 has built-in reload() function
import os
import platform
import warnings

try:
    from invoke import ctask as task
except ImportError:  # Invoke 0.13 renamed ctask to task
    from invoke import task


@task(default=True)
def run(
        context,
        host='127.0.0.1',
        port=5000,
        flask_config=None,
        install_dependencies=True,
        upgrade_db=True
    ):
    """
    Run Example RESTful API Server.
    """
    if flask_config is not None:
        os.environ['FLASK_CONFIG'] = flask_config

    if install_dependencies:
        context.invoke_execute(context, 'app.dependencies.install')

    from app import create_app
    app = create_app()

    if upgrade_db:
        # After the installed dependencies the app.db.* tasks might need to be
        # reloaded to import all necessary dependencies.
        from . import db as db_tasks
        reload(db_tasks)

        context.invoke_execute(context, 'app.db.upgrade', app=app)
        if app.debug:
            context.invoke_execute(
                context,
                'app.db.init_development_data',
                app=app,
                upgrade_db=False,
                skip_on_failure=True
            )

    use_reloader = app.debug
    if platform.system() == 'Windows':
        warnings.warn(
                "Auto-reloader feature doesn't work on Windows. "
                "Follow the issue for more details: "
                "https://github.com/frol/flask-restplus-server-example/issues/16"
            )
        use_reloader = False
    app.run(host=host, port=port, use_reloader=use_reloader)<commit_msg>[tasks] Added uWSGI integration into invoke app.run command<commit_after># encoding: utf-8
# pylint: disable=too-many-arguments
"""
Application execution related tasks for Invoke.
"""

try:
    from importlib import reload
except ImportError:
    pass  # Python 2 has built-in reload() function
import os
import platform
import warnings

try:
    from invoke import ctask as task
except ImportError:  # Invoke 0.13 renamed ctask to task
    from invoke import task


@task(default=True)
def run(
        context,
        host='127.0.0.1',
        port=5000,
        flask_config=None,
        install_dependencies=True,
        upgrade_db=True,
        uwsgi=False,
        uwsgi_mode='http',
        uwsgi_extra_options='',
    ):
    """
    Run Example RESTful API Server.
    """
    if flask_config is not None:
        os.environ['FLASK_CONFIG'] = flask_config

    if install_dependencies:
        context.invoke_execute(context, 'app.dependencies.install')

    from app import create_app
    app = create_app()

    if upgrade_db:
        # After the installed dependencies the app.db.* tasks might need to be
        # reloaded to import all necessary dependencies.
        from . import db as db_tasks
        reload(db_tasks)

        context.invoke_execute(context, 'app.db.upgrade', app=app)
        if app.debug:
            context.invoke_execute(
                context,
                'app.db.init_development_data',
                app=app,
                upgrade_db=False,
                skip_on_failure=True
            )

    use_reloader = app.debug
    if uwsgi:
        uwsgi_args = [
            "uwsgi",
            "--need-app",
            "--manage-script-name",
            "--mount", "/=app:create_app()",
            "--%s-socket" % uwsgi_mode, "%s:%d" % (host, port),
        ]
        if use_reloader:
            uwsgi_args += ["--python-auto-reload", "2"]
        if uwsgi_extra_options:
            uwsgi_args += uwsgi_extra_options.split(' ')
        os.execvpe('uwsgi', uwsgi_args, os.environ)
    else:
        if platform.system() == 'Windows':
            warnings.warn(
                    "Auto-reloader feature doesn't work on Windows. "
                    "Follow the issue for more details: "
                    "https://github.com/frol/flask-restplus-server-example/issues/16"
                )
            use_reloader = False
        return app.run(host=host, port=port, use_reloader=use_reloader)
{'fraction_non_alphanumeric': 0.09505970498712245, 'fraction_numerical': 0.008194802154062281, 'mean_word_length': 2.0711718188353703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5957016', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1216, 'n_words': 318}