Passed
Push — try-connexion3-alpha ( 79648c...6821e1 )
by Juho
03:00
created

annif.create_app()   A

Complexity

Conditions 4

Size

Total Lines 36
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 16
nop 1
dl 0
loc 36
rs 9.6
c 0
b 0
f 0
1
#!/usr/bin/env python3
2
3
import logging
4
import os
5
import os.path
6
7
import connexion
8
9
# from flask import Flask
10
# from flask_cors import CORS
11
12
# from annif.openapi.validation import CustomRequestBodyValidator
13
14
logging.basicConfig()
15
logger = logging.getLogger("annif")
16
logger.setLevel(level=logging.INFO)
17
18
import annif.backend  # noqa
19
20
21
def create_app(config_name=None):
22
    # 'cxapp' here is the Connexion application that has a normal Flask app
23
    # as a property (cxapp.app)
24
25
    specdir = os.path.join(os.path.dirname(__file__), "openapi")
26
    cxapp = connexion.FlaskApp(__name__, specification_dir=specdir)
27
    if config_name is None:
28
        config_name = os.environ.get("ANNIF_CONFIG")
29
    if config_name is None:
30
        if os.environ.get("FLASK_RUN_FROM_CLI") == "true":
31
            config_name = "annif.default_config.Config"
32
        else:
33
            config_name = "annif.default_config.ProductionConfig"
34
    logger.debug("creating app with configuration %s", config_name)
35
    cxapp.app.config.from_object(config_name)
36
    cxapp.app.config.from_envvar("ANNIF_SETTINGS", silent=True)
37
38
    # validator_map = {
39
    #     "body": CustomRequestBodyValidator,
40
    # }
41
    cxapp.add_api("annif.yaml")  # validator_map=validator_map)
42
43
    # add CORS support
44
    # CORS(cxapp.app)
45
46
    # if cxapp.app.config["INITIALIZE_PROJECTS"]:
47
    #     annif.registry.initialize_projects(cxapp.app)
48
    #     logger.info("finished initializing projects")
49
50
    # register the views via blueprints
51
    from annif.views import bp
52
53
    cxapp.app.register_blueprint(bp)
54
55
    # return the Connexion app
56
    return cxapp
57