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, 'logging.basicConfig', 'logging.basicConfig', False, 'import logging\n'), (17, 'flask.Flask', 'Flask', False, 'from flask import Flask\n'), (18, 'flask_cors.CORS', 'CORS', False, 'from flask_cors import CORS\n'), (24, 'app.extensions.api.init_app', 'api.init_app', False, 'from app.extensions import api\n'), (26, 'app.extensions.database.db.init_app', 'db.init_app', False, 'from app.extensions.database import db\n'), (27, 'app.extensions.database.db.create_all', 'db.create_all', False, 'from app.extensions.database import db\n'), (29, 'app.extensions.schema.ma.init_app', 'ma.init_app', False, 'from app.extensions.schema import ma\n'), (31, 'app.extensions.api.register_blueprint', 'api.register_blueprint', False, 'from app.extensions import api\n'), (32, 'app.extensions.api.register_blueprint', 'api.register_blueprint', False, 'from app.extensions import api\n'), (33, 'app.extensions.api.register_blueprint', 'api.register_blueprint', False, 'from app.extensions import api\n'), (34, 'app.extensions.api.register_blueprint', 'api.register_blueprint', False, 'from app.extensions import api\n'), (37, 'os.makedirs', 'os.makedirs', False, 'import os\n')]