feat: use uv (#59)

* feat: use uv
* fix make
This commit is contained in:
dni ⚡ 2025-09-04 07:57:33 +02:00 committed by GitHub
commit 7bdf7db2c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 2324 additions and 3665 deletions

View file

@ -5,27 +5,27 @@ format: prettier black ruff
check: mypy pyright checkblack checkruff checkprettier check: mypy pyright checkblack checkruff checkprettier
prettier: prettier:
poetry run ./node_modules/.bin/prettier --write . uv run ./node_modules/.bin/prettier --write .
pyright: pyright:
poetry run ./node_modules/.bin/pyright uv run ./node_modules/.bin/pyright
mypy: mypy:
poetry run mypy . uv run mypy .
black: black:
poetry run black . uv run black .
ruff: ruff:
poetry run ruff check . --fix uv run ruff check . --fix
checkruff: checkruff:
poetry run ruff check . uv run ruff check .
checkprettier: checkprettier:
poetry run ./node_modules/.bin/prettier --check . uv run ./node_modules/.bin/prettier --check .
checkblack: checkblack:
poetry run black --check . uv run black --check .
checkeditorconfig: checkeditorconfig:
editorconfig-checker editorconfig-checker
@ -33,14 +33,14 @@ checkeditorconfig:
test: test:
PYTHONUNBUFFERED=1 \ PYTHONUNBUFFERED=1 \
DEBUG=true \ DEBUG=true \
poetry run pytest uv run pytest
install-pre-commit-hook: install-pre-commit-hook:
@echo "Installing pre-commit hook to git" @echo "Installing pre-commit hook to git"
@echo "Uninstall the hook with poetry run pre-commit uninstall" @echo "Uninstall the hook with uv run pre-commit uninstall"
poetry run pre-commit install uv run pre-commit install
pre-commit: pre-commit:
poetry run pre-commit run --all-files uv run pre-commit run --all-files
checkbundle: checkbundle:

View file

@ -40,9 +40,9 @@ def boltcards_start():
__all__ = [ __all__ = [
"db",
"boltcards_ext", "boltcards_ext",
"boltcards_static_files",
"boltcards_start", "boltcards_start",
"boltcards_static_files",
"boltcards_stop", "boltcards_stop",
"db",
] ]

15
crud.py
View file

@ -1,6 +1,5 @@
import secrets import secrets
from datetime import datetime from datetime import datetime
from typing import Optional
from lnbits.db import Database from lnbits.db import Database
from lnbits.helpers import urlsafe_short_hash from lnbits.helpers import urlsafe_short_hash
@ -72,7 +71,7 @@ async def get_cards(wallet_ids: list[str]) -> list[Card]:
) )
async def get_card(card_id: str) -> Optional[Card]: async def get_card(card_id: str) -> Card | None:
return await db.fetchone( return await db.fetchone(
"SELECT * FROM boltcards.cards WHERE id = :id", "SELECT * FROM boltcards.cards WHERE id = :id",
{"id": card_id}, {"id": card_id},
@ -80,7 +79,7 @@ async def get_card(card_id: str) -> Optional[Card]:
) )
async def get_card_by_uid(card_uid: str) -> Optional[Card]: async def get_card_by_uid(card_uid: str) -> Card | None:
return await db.fetchone( return await db.fetchone(
"SELECT * FROM boltcards.cards WHERE uid = :uid", "SELECT * FROM boltcards.cards WHERE uid = :uid",
{"uid": card_uid.upper()}, {"uid": card_uid.upper()},
@ -88,7 +87,7 @@ async def get_card_by_uid(card_uid: str) -> Optional[Card]:
) )
async def get_card_by_external_id(external_id: str) -> Optional[Card]: async def get_card_by_external_id(external_id: str) -> Card | None:
return await db.fetchone( return await db.fetchone(
"SELECT * FROM boltcards.cards WHERE external_id = :ext_id", "SELECT * FROM boltcards.cards WHERE external_id = :ext_id",
{"ext_id": external_id.lower()}, {"ext_id": external_id.lower()},
@ -96,7 +95,7 @@ async def get_card_by_external_id(external_id: str) -> Optional[Card]:
) )
async def get_card_by_otp(otp: str) -> Optional[Card]: async def get_card_by_otp(otp: str) -> Card | None:
return await db.fetchone( return await db.fetchone(
"SELECT * FROM boltcards.cards WHERE otp = :otp", "SELECT * FROM boltcards.cards WHERE otp = :otp",
{"otp": otp}, {"otp": otp},
@ -126,7 +125,7 @@ async def update_card_counter(counter: int, card_id: str):
) )
async def enable_disable_card(enable: bool, card_id: str) -> Optional[Card]: async def enable_disable_card(enable: bool, card_id: str) -> Card | None:
await db.execute( await db.execute(
"UPDATE boltcards.cards SET enable = :enable WHERE id = :id", "UPDATE boltcards.cards SET enable = :enable WHERE id = :id",
{"enable": enable, "id": card_id}, {"enable": enable, "id": card_id},
@ -141,7 +140,7 @@ async def update_card_otp(otp: str, card_id: str):
) )
async def get_hit(hit_id: str) -> Optional[Hit]: async def get_hit(hit_id: str) -> Hit | None:
return await db.fetchone( return await db.fetchone(
"SELECT * FROM boltcards.hits WHERE id = :id", "SELECT * FROM boltcards.hits WHERE id = :id",
{"id": hit_id}, {"id": hit_id},
@ -236,7 +235,7 @@ async def create_refund(hit_id, refund_amount) -> Refund:
return refund return refund
async def get_refund(refund_id: str) -> Optional[Refund]: async def get_refund(refund_id: str) -> Refund | None:
return await db.fetchone( return await db.fetchone(
"SELECT * FROM boltcards.refunds WHERE id = :id", "SELECT * FROM boltcards.refunds WHERE id = :id",
{"id": refund_id}, {"id": refund_id},

View file

@ -74,5 +74,5 @@ class Refund(BaseModel):
class UIDPost(BaseModel): class UIDPost(BaseModel):
UID: str = Field(None, description="The UID of the card.") UID: str = Field(description="The UID of the card.")
LNURLW: str = Field(None, description="The LNURLW of the card.") LNURLW: str = Field(description="The LNURLW of the card.")

3609
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,40 +1,34 @@
[tool.poetry] [project]
name = "lnbits-boltcards" name = "lnbits-boltcards"
version = "0.0.0" version = "0.0.0"
requires-python = ">=3.10,<3.13"
description = "LNbits, free and open-source Lightning wallet and accounts system." description = "LNbits, free and open-source Lightning wallet and accounts system."
authors = ["Alan Bits <alan@lnbits.com>"] authors = [{ name = "Alan Bits", email = "alan@lnbits.com" }]
urls = { Homepage = "https://lnbits.com", Repository = "https://github.com/lnbits/bitcoinswitch_extension" }
dependencies = [ "lnbits>1" ]
[tool.poetry]
package-mode = false package-mode = false
[tool.poetry.dependencies] [tool.uv]
python = "~3.12 | ~3.11 | ~3.10" dev-dependencies = [
lnbits = {version = "*", allow-prereleases = true} "black",
"pytest-asyncio",
[tool.poetry.group.dev.dependencies] "pytest",
black = "^24.3.0" "mypy",
pytest-asyncio = "^0.21.0" "pre-commit",
pytest = "^7.3.2" "ruff",
mypy = "^1.5.1" "pytest-md",
pre-commit = "^3.2.2" ]
ruff = "^0.6.3"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.mypy] [tool.mypy]
exclude = "(nostr/*)" plugins = ["pydantic.mypy"]
[[tool.mypy.overrides]]
module = [ [tool.pydantic-mypy]
"lnbits.*", init_forbid_extra = true
"lnurl.*", init_typed = true
"loguru.*", warn_required_dynamic_aliases = true
"fastapi.*", warn_untyped_fields = true
"pydantic.*",
"pyqrcode.*",
"shortuuid.*",
"httpx.*",
]
ignore_missing_imports = "True"
[tool.pytest.ini_options] [tool.pytest.ini_options]
log_cli = false log_cli = false

2276
uv.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,4 @@
from http import HTTPStatus from http import HTTPStatus
from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, Request from fastapi import APIRouter, Depends, HTTPException, Request
from fastapi.responses import HTMLResponse from fastapi.responses import HTMLResponse
@ -26,7 +25,7 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
@boltcards_generic_router.get("/{card_id}", response_class=HTMLResponse) @boltcards_generic_router.get("/{card_id}", response_class=HTMLResponse)
async def display( async def display(
request: Request, card_id: str, user_id: Optional[str] = Depends(optional_user_id) request: Request, card_id: str, user_id: str | None = Depends(optional_user_id)
): ):
if not user_id: if not user_id:
raise HTTPException( raise HTTPException(