commit 91cdd6523f608923d9c9ff6016e64d03a76edb34 Author: Diogo Diniz Date: Wed Apr 1 14:30:07 2026 +0100 chore: Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..061cef2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +**__pycache__/ +**.egg-info/ +instance/ +build/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0fb4e23 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +repos: +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.15.0 + hooks: + - id: ruff-check + args: [ --fix ] + - id: ruff-format +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.19.1 + hooks: + - id: mypy + args: [--strict] + additional_dependencies: [flask, sqlalchemy, qrcode] diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e7efa9e --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,18 @@ +from flask import Flask + +from .db import init_db + + +def create_app() -> Flask: + app = Flask(__name__, instance_relative_config=True) + + app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///app.db" + app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False + + init_db(app) + + from .routes import bp # noqa: PLC0415 + + app.register_blueprint(bp) + + return app diff --git a/app/db.py b/app/db.py new file mode 100644 index 0000000..940c7e7 --- /dev/null +++ b/app/db.py @@ -0,0 +1,21 @@ +from flask import Flask +from sqlalchemy import create_engine +from sqlalchemy.orm import DeclarativeBase, scoped_session, sessionmaker + +engine = None +SessionLocal = None + + +class Base(DeclarativeBase): + pass + + +def init_db(app: Flask) -> None: # noqa: ARG001 + global engine, SessionLocal # noqa: PLW0603 + + engine = create_engine("sqlite:///instance/app.db", echo=True, future=True) + SessionLocal = scoped_session(sessionmaker(bind=engine)) + + from . import models # noqa: F401, PLC0415 + + Base.metadata.create_all(bind=engine) diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..488dae9 --- /dev/null +++ b/app/main.py @@ -0,0 +1,6 @@ +from app import create_app + +app = create_app() + +if __name__ == "__main__": + app.run(debug=True) diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..6475416 --- /dev/null +++ b/app/models.py @@ -0,0 +1,11 @@ +from sqlalchemy import Integer, String +from sqlalchemy.orm import Mapped, mapped_column + +from .db import Base + + +class Drink(Base): + __tablename__ = "drinks" + + id: Mapped[int] = mapped_column(Integer, primary_key=True) + name: Mapped[str] = mapped_column(String) diff --git a/app/routes.py b/app/routes.py new file mode 100644 index 0000000..5529e45 --- /dev/null +++ b/app/routes.py @@ -0,0 +1,8 @@ +from flask import Blueprint, render_template + +bp = Blueprint("main", __name__) + + +@bp.route("/") +def index() -> str: + return render_template("index.html") diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..e97672b --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,10 @@ + + + + Fridge Tracker + + +

Fridge Tracker

+

Welcome. System is running.

+ + diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ad09cc7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,50 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "fridge-tracker" +version = "0.1.0" +description = "Simple fridge tracking web app" +requires-python = ">=3.11" + +dependencies = [ "flask>=3.0.0", "sqlalchemy>=2.0.0", "qrcode[pil]>=7.4.2" ] + +[tool.ruff] +line-length = 120 +indent-width = 4 + +[tool.ruff.lint] +select = ["ALL"] +ignore = [ + # Conflicting + "D203", + "D212", + "COM812", + + # Allow 'TODO' and 'HACK' in code + "FIX002", + "TD002", + "TD003", + "FIX004", + + # Others I dont care about + "D" +] + +[tool.ruff.format] +quote-style = "double" +indent-style = "space" + +[tool.mypy] +strict = true +warn_unused_configs = true +warn_return_any = true +warn_unused_ignores = true +no_implicit_optional = true +show_error_codes = true +pretty = true + +disable_error_code = [ + "attr-defined" +]