import logging
import os

from flask import Flask
from flask_cors import CORS

from app.extensions import api
from app.extensions.database import db
from app.extensions.schema import ma
from app.views import albums, artists, hello, tracks


def create_app(config, **kwargs):

    logging.basicConfig(level=logging.INFO)

    app = Flask(__name__, **kwargs)
    CORS(app, resources={r"/api/*": {"origins": "*"}})

    app.config.from_object(config)
    # app.url_map.strict_slashes = False

    with app.app_context():
        api.init_app(app)

        db.init_app(app)
        db.create_all()

        ma.init_app(app)

        api.register_blueprint(hello.blp)
        api.register_blueprint(artists.blp)
        api.register_blueprint(albums.blp)
        api.register_blueprint(tracks.blp)

    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    return app

[((15, 4, 15, 43), 'logging.basicConfig', 'logging.basicConfig', (), '', False, 'import logging\n'), ((17, 10, 17, 35), 'flask.Flask', 'Flask', ({(17, 16, 17, 24): '__name__'}, {}), '(__name__, **kwargs)', False, 'from flask import Flask\n'), ((18, 4, 18, 54), 'flask_cors.CORS', 'CORS', (), '', False, 'from flask_cors import CORS\n'), ((24, 8, 24, 25), 'app.extensions.api.init_app', 'api.init_app', ({(24, 21, 24, 24): 'app'}, {}), '(app)', False, 'from app.extensions import api\n'), ((26, 8, 26, 24), 'app.extensions.database.db.init_app', 'db.init_app', ({(26, 20, 26, 23): 'app'}, {}), '(app)', False, 'from app.extensions.database import db\n'), ((27, 8, 27, 23), 'app.extensions.database.db.create_all', 'db.create_all', ({}, {}), '()', False, 'from app.extensions.database import db\n'), ((29, 8, 29, 24), 'app.extensions.schema.ma.init_app', 'ma.init_app', ({(29, 20, 29, 23): 'app'}, {}), '(app)', False, 'from app.extensions.schema import ma\n'), ((31, 8, 31, 41), 'app.extensions.api.register_blueprint', 'api.register_blueprint', ({(31, 31, 31, 40): 'hello.blp'}, {}), '(hello.blp)', False, 'from app.extensions import api\n'), ((32, 8, 32, 43), 'app.extensions.api.register_blueprint', 'api.register_blueprint', ({(32, 31, 32, 42): 'artists.blp'}, {}), '(artists.blp)', False, 'from app.extensions import api\n'), ((33, 8, 33, 42), 'app.extensions.api.register_blueprint', 'api.register_blueprint', ({(33, 31, 33, 41): 'albums.blp'}, {}), '(albums.blp)', False, 'from app.extensions import api\n'), ((34, 8, 34, 42), 'app.extensions.api.register_blueprint', 'api.register_blueprint', ({(34, 31, 34, 41): 'tracks.blp'}, {}), '(tracks.blp)', False, 'from app.extensions import api\n'), ((37, 8, 37, 38), 'os.makedirs', 'os.makedirs', ({(37, 20, 37, 37): 'app.instance_path'}, {}), '(app.instance_path)', False, 'import os\n')]