import logging
import os

import aiohttp.web
from connexion import AioHttpApp

from nlp_annotator_api.config.config import conf
from nlp_annotator_api.config.logging import setup_logging
from nlp_annotator_api.server.middleware.statsd_middleware import StatsdMiddleware
from nlp_annotator_api.server.signals.statsd_client import statsd_client_factory

setup_logging()

access_log = logging.getLogger("nlp_annotator_api.access")

_file_dir = os.path.dirname(__file__)

app = AioHttpApp(
    __name__, specification_dir=os.path.join(_file_dir, "..", "resources", "schemas"),
    server_args=dict(
        client_max_size=8 * 1024**2
    )  
)

app.add_api("openapi.yaml", pass_context_arg_name="request")

aiohttp_app: aiohttp.web.Application = app.app

aiohttp_app.cleanup_ctx.append(statsd_client_factory(conf.statsd))

aiohttp_app.middlewares.append(StatsdMiddleware())

if __name__ == "__main__":
    app.run(access_log=access_log)

[((12, 0, 12, 15), 'nlp_annotator_api.config.logging.setup_logging', 'setup_logging', ({}, {}), '()', False, 'from nlp_annotator_api.config.logging import setup_logging\n'), ((14, 13, 14, 58), 'logging.getLogger', 'logging.getLogger', ({(14, 31, 14, 57): '"""nlp_annotator_api.access"""'}, {}), "('nlp_annotator_api.access')", False, 'import logging\n'), ((16, 12, 16, 37), 'os.path.dirname', 'os.path.dirname', ({(16, 28, 16, 36): '__file__'}, {}), '(__file__)', False, 'import os\n'), ((29, 31, 29, 65), 'nlp_annotator_api.server.signals.statsd_client.statsd_client_factory', 'statsd_client_factory', ({(29, 53, 29, 64): 'conf.statsd'}, {}), '(conf.statsd)', False, 'from nlp_annotator_api.server.signals.statsd_client import statsd_client_factory\n'), ((31, 31, 31, 49), 'nlp_annotator_api.server.middleware.statsd_middleware.StatsdMiddleware', 'StatsdMiddleware', ({}, {}), '()', False, 'from nlp_annotator_api.server.middleware.statsd_middleware import StatsdMiddleware\n'), ((19, 32, 19, 85), 'os.path.join', 'os.path.join', ({(19, 45, 19, 54): '_file_dir', (19, 56, 19, 60): '""".."""', (19, 62, 19, 73): '"""resources"""', (19, 75, 19, 84): '"""schemas"""'}, {}), "(_file_dir, '..', 'resources', 'schemas')", False, 'import os\n')]