"""
Factories to configure Flask.

"""
from flask import Flask


def configure_flask(graph):
    """
    Create the Flask instance (only), bound to the "flask" key.

    Conventions should refer to `graph.flask` to avoid circular dependencies.

    """
    app = Flask(graph.metadata.import_name)
    app.debug = graph.metadata.debug
    app.testing = graph.metadata.testing

    # copy in the graph's configuration for non-nested keys
    app.config.update({
        key: value
        for key, value in graph.config.items()
        if not isinstance(value, dict)
    })

    return app


def configure_flask_app(graph):
    """
    Configure a Flask application with common conventions, bound to the "app" key.

    """
    graph.use(
        "audit",
        "basic_auth",
        "error_handlers",
        "logger",
    )
    return graph.flask

@@ -57,16 +57,80 @@
  Flask%0A%0A
+from microcosm.api import defaults%0A%0A%0A@defaults(%0A    port=5000,%0A)
 %0Adef con

Add default flask port