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

[((280, 319), 'logging.basicConfig', 'logging.basicConfig', ([], {'level': 'logging.INFO'}), '(level=logging.INFO)\n', (299, 319), False, 'import logging\n'), ((331, 356), 'flask.Flask', 'Flask', (['__name__'], {}), '(__name__, **kwargs)\n', (336, 356), False, 'from flask import Flask\n'), ((361, 410), 'flask_cors.CORS', 'CORS', (['app'], {'resources': "{'/api/*': {'origins': '*'}}"}), "(app, resources={'/api/*': {'origins': '*'}})\n", (365, 410), False, 'from flask_cors import CORS\n'), ((526, 543), 'app.extensions.api.init_app', 'api.init_app', (['app'], {}), '(app)\n', (538, 543), False, 'from app.extensions import api\n'), ((553, 569), 'app.extensions.database.db.init_app', 'db.init_app', (['app'], {}), '(app)\n', (564, 569), False, 'from app.extensions.database import db\n'), ((578, 593), 'app.extensions.database.db.create_all', 'db.create_all', ([], {}), '()\n', (591, 593), False, 'from app.extensions.database import db\n'), ((603, 619), 'app.extensions.schema.ma.init_app', 'ma.init_app', (['app'], {}), '(app)\n', (614, 619), False, 'from app.extensions.schema import ma\n'), ((629, 662), 'app.extensions.api.register_blueprint', 'api.register_blueprint', (['hello.blp'], {}), '(hello.blp)\n', (651, 662), False, 'from app.extensions import api\n'), ((671, 706), 'app.extensions.api.register_blueprint', 'api.register_blueprint', (['artists.blp'], {}), '(artists.blp)\n', (693, 706), False, 'from app.extensions import api\n'), ((715, 749), 'app.extensions.api.register_blueprint', 'api.register_blueprint', (['albums.blp'], {}), '(albums.blp)\n', (737, 749), False, 'from app.extensions import api\n'), ((758, 792), 'app.extensions.api.register_blueprint', 'api.register_blueprint', (['tracks.blp'], {}), '(tracks.blp)\n', (780, 792), False, 'from app.extensions import api\n'), ((811, 841), 'os.makedirs', 'os.makedirs', (['app.instance_path'], {}), '(app.instance_path)\n', (822, 841), False, 'import os\n')]