From dc34a78e066145e643d022a8347870146be219fb Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Tue, 10 Feb 2026 18:12:52 +0000 Subject: [PATCH] Cleanup --- Dockerfile | 10 +--------- barker/barker/routers/bundle.py | 8 ++++++-- barker/barker/tasks/__init__.py | 0 barker/barker/tasks/printing.py | 33 ------------------------------- barker/barker/worker.py | 35 --------------------------------- barker/pyproject.toml | 7 ++++++- barker/worker-start.sh | 5 ----- 7 files changed, 13 insertions(+), 85 deletions(-) delete mode 100644 barker/barker/tasks/__init__.py delete mode 100644 barker/barker/tasks/printing.py delete mode 100644 barker/barker/worker.py delete mode 100755 barker/worker-start.sh diff --git a/Dockerfile b/Dockerfile index 1c2af459..027f1485 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,17 +25,9 @@ RUN \ else echo "Lockfile not found." && exit 1; \ fi -FROM python:3.13 AS runner +FROM python:3.14 AS runner LABEL maintainer="Amritanshu " -RUN apt-get update && \ - apt-get install -y locales && \ - sed --in-place --expression='s/# en_IN UTF-8/en_IN UTF-8/' /etc/locale.gen && \ - dpkg-reconfigure --frontend=noninteractive locales - -ENV LANG=en_IN -ENV LC_ALL=en_IN - # Install Poetry RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python - && \ cd /usr/local/bin && \ diff --git a/barker/barker/routers/bundle.py b/barker/barker/routers/bundle.py index 7c90c9a0..0c153248 100644 --- a/barker/barker/routers/bundle.py +++ b/barker/barker/routers/bundle.py @@ -99,7 +99,9 @@ def save( status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="Not enough bundle items.", ) - sale_price = round(sum(round(it.sale_price, 2) * round(it.quantity, 5) for it in data.items), 2) + sale_price = round( + sum((round(it.sale_price, 2) * round(it.quantity, 5) for it in data.items), start=Decimal(0)), 2 + ) product = Product(sort_order=data.sort_order) db.add(product) @@ -174,7 +176,9 @@ def update_route( status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="Not enough bundle items.", ) - sale_price = round(sum(round(it.sale_price, 2) * round(it.quantity, 5) for it in data.items), 2) + sale_price = round( + sum((round(it.sale_price, 2) * round(it.quantity, 5) for it in data.items), start=Decimal(0)), 2 + ) # Load header SKU + active header SkuVersion + menu category + product + active ProductVersion sv: SkuVersion | None = ( db.execute( diff --git a/barker/barker/tasks/__init__.py b/barker/barker/tasks/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/barker/barker/tasks/printing.py b/barker/barker/tasks/printing.py deleted file mode 100644 index 4d484f42..00000000 --- a/barker/barker/tasks/printing.py +++ /dev/null @@ -1,33 +0,0 @@ -import re # noqa: F401 -import socket # noqa: F401 -import sys # noqa: F401 - -from arq import Retry - - -async def sent_to_printer(ctx: dict, data: str, address: str, cut_code: str): - print(ctx, data, address, cut_code) - try: - with open(address, "w") as printer: - printer.write(data) - printer.write("\n") - print(cut_code) - printer.write(cut_code) - except LookupError as e: - print("Lookup error:", e) - except: # noqa: E722 - print("Unexpected error:", sys.exc_info()[0]) - # retry the job with increasing back-off - # delays will be 5s, 10s, 15s, 20s - # after max_tries (default 5) the job will permanently fail - raise Retry(defer=ctx["job_try"] * 5) from None - - # GS = "\x1d" - # PAPER_CUT = GS + "V" - # # For the printer ESC/POS Reference - # # https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=87 - # # The m codes are in decimal and can be converted using the following table - # # https://www.eso.org/~ndelmott/ascii.html - # # The \x03 in all the following is to feed 3 lines before cut it can be increased or reduced - # FUNCTION_B_FULL_CUT = "\x41\x03" - # FUNCTION_B_PARTIAL_CUT = "\x42\x03" diff --git a/barker/barker/worker.py b/barker/barker/worker.py deleted file mode 100644 index dfec9012..00000000 --- a/barker/barker/worker.py +++ /dev/null @@ -1,35 +0,0 @@ -import sys - -from aiohttp import ClientSession - -from barker.core.arq import settings -from barker.core.config import settings as sett -from barker.tasks.printing import sent_to_printer - - -sys.path.extend(["./"]) - - -async def startup(ctx): - ctx["session"] = ClientSession() - print(f"Worker listening for: {sett.WORKER_QUEUE_NAME}") - # print(f"Worker printing on: {sett.WORKER_PRINTER_ADDRESS}") - - -async def shutdown(ctx): - await ctx["session"].close() - - -class WorkerSettings: - """ - Settings for the ARQ worker. - """ - - queue_name = f"barker:print:{sett.WORKER_QUEUE_NAME}" - redis_settings = settings - functions: list = [sent_to_printer] - on_startup = startup - on_shutdown = shutdown - - -# command to run arq barker.worker.WorkerSettings diff --git a/barker/pyproject.toml b/barker/pyproject.toml index 2556101f..53f5e36b 100644 --- a/barker/pyproject.toml +++ b/barker/pyproject.toml @@ -124,5 +124,10 @@ disallow_subclassing_any = true disallow_untyped_defs = true disallow_untyped_decorators = true -plugins = ["sqlalchemy.ext.mypy.plugin"] +plugins = ["sqlalchemy.ext.mypy.plugin", "pydantic.mypy"] # --strict end + +[tool.pydantic-mypy] +init_forbid_extra = true +init_typed = true +warn_required_dynamic_aliases = true diff --git a/barker/worker-start.sh b/barker/worker-start.sh deleted file mode 100755 index 7d828cfa..00000000 --- a/barker/worker-start.sh +++ /dev/null @@ -1,5 +0,0 @@ -#! /usr/bin/env bash -set -e - -echo arq barker.worker.WorkerSettings -arq barker.worker.WorkerSettings