from flask import Flask from flask_sqlalchemy import SQLAlchemy import tomllib import os db = SQLAlchemy() def create_app(config_path=None): app = Flask(__name__, instance_relative_config=True) os.makedirs(app.instance_path, exist_ok=True) app.config["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{os.path.join(app.instance_path, 'worklog.db')}" app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "dev-secret-change-in-prod") # Load TOML config if config_path is None: config_path = os.path.join(os.path.dirname(app.root_path), "config.toml") if os.path.exists(config_path): with open(config_path, "rb") as f: app.config["TOML"] = tomllib.load(f) else: app.config["TOML"] = {} db.init_app(app) from app.routes.dashboard import bp as dashboard_bp from app.routes.entries import bp as entries_bp from app.routes.reports import bp as reports_bp app.register_blueprint(dashboard_bp) app.register_blueprint(entries_bp) app.register_blueprint(reports_bp) with app.app_context(): db.create_all() return app