Merge pull request #37 from lnbits/feat/uv

This commit is contained in:
blackcoffeexbt 2025-09-10 09:40:42 +01:00 committed by GitHub
commit 89f7c99f75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 2359 additions and 2726 deletions

View file

@ -11,14 +11,9 @@ jobs:
tests: tests:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [lint] needs: [lint]
strategy:
matrix:
python-version: ['3.9', '3.10']
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: lnbits/lnbits/.github/actions/prepare@dev - uses: lnbits/lnbits/.github/actions/prepare@dev
with:
python-version: ${{ matrix.python-version }}
- name: Run pytest - name: Run pytest
uses: pavelzw/pytest-action@v2 uses: pavelzw/pytest-action@v2
env: env:
@ -30,5 +25,5 @@ jobs:
job-summary: true job-summary: true
emoji: false emoji: false
click-to-expand: true click-to-expand: true
custom-pytest: poetry run pytest custom-pytest: uv run pytest
report-title: 'test (${{ matrix.python-version }})' report-title: 'test'

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

@ -53,7 +53,7 @@ def nostrclient_start():
__all__ = [ __all__ = [
"db", "db",
"nostrclient_ext", "nostrclient_ext",
"nostrclient_start",
"nostrclient_static_files", "nostrclient_static_files",
"nostrclient_stop", "nostrclient_stop",
"nostrclient_start",
] ]

View file

@ -1,5 +1,3 @@
from typing import Optional
from lnbits.db import Database from lnbits.db import Database
from .models import Config, Relay, UserConfig from .models import Config, Relay, UserConfig
@ -40,7 +38,7 @@ async def update_config(owner_id: str, config: Config) -> Config:
return user_config.extra return user_config.extra
async def get_config(owner_id: str) -> Optional[Config]: async def get_config(owner_id: str) -> Config | None:
user_config: UserConfig = await db.fetchone( user_config: UserConfig = await db.fetchone(
""" """
SELECT * FROM nostrclient.config SELECT * FROM nostrclient.config

View file

@ -1,27 +1,25 @@
from typing import Optional
from lnbits.helpers import urlsafe_short_hash from lnbits.helpers import urlsafe_short_hash
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
class RelayStatus(BaseModel): class RelayStatus(BaseModel):
num_sent_events: Optional[int] = 0 num_sent_events: int | None = 0
num_received_events: Optional[int] = 0 num_received_events: int | None = 0
error_counter: Optional[int] = 0 error_counter: int | None = 0
error_list: Optional[list] = [] error_list: list | None = []
notice_list: Optional[list] = [] notice_list: list | None = []
class Relay(BaseModel): class Relay(BaseModel):
id: Optional[str] = None id: str | None = None
url: Optional[str] = None url: str | None = None
active: Optional[bool] = None active: bool | None = None
connected: Optional[bool] = Field(default=None, no_database=True) connected: bool | None = Field(default=None, no_database=True)
connected_string: Optional[str] = Field(default=None, no_database=True) connected_string: str | None = Field(default=None, no_database=True)
status: Optional[RelayStatus] = Field(default=None, no_database=True) status: RelayStatus | None = Field(default=None, no_database=True)
ping: Optional[int] = Field(default=None, no_database=True) ping: int | None = Field(default=None, no_database=True)
def _init__(self): def _init__(self):
if not self.id: if not self.id:
@ -31,11 +29,11 @@ class Relay(BaseModel):
class RelayDb(BaseModel): class RelayDb(BaseModel):
id: str id: str
url: str url: str
active: Optional[bool] = True active: bool | None = True
class TestMessage(BaseModel): class TestMessage(BaseModel):
sender_private_key: Optional[str] sender_private_key: str | None
reciever_public_key: str reciever_public_key: str
message: str message: str

2655
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,47 +1,45 @@
[tool.poetry] [project]
name = "lnbits-nostrclient" name = "lnbits-nostrclient"
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/nostrclient" }
dependencies = [ "lnbits>1" ]
[tool.poetry.dependencies] [tool.poetry]
python = "^3.10 | ^3.9" package-mode = false
lnbits = {allow-prereleases = true, version = "*"}
[tool.poetry.group.dev.dependencies] [tool.uv]
black = "^24.3.0" dev-dependencies = [
pytest-asyncio = "^0.21.0" "black",
pytest = "^7.3.2" "pytest-asyncio",
mypy = "^1.5.1" "pytest",
pre-commit = "^3.2.2" "mypy",
ruff = "^0.3.2" "pre-commit",
types-cffi = "^1.16.0.20240331" "ruff",
pytest-md = "^0.2.0" "pytest-md",
"types-cffi",
[build-system] ]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.mypy] [tool.mypy]
exclude = "(nostr/*)" exclude = "(nostr/*)"
plugins = ["pydantic.mypy"]
[[tool.mypy.overrides]] [[tool.mypy.overrides]]
module = [ module = [
"nostr.*", "nostr.*",
"lnbits.*",
"lnurl.*",
"loguru.*",
"fastapi.*",
"pydantic.*",
"pyqrcode.*",
"shortuuid.*",
"httpx.*",
"secp256k1.*", "secp256k1.*",
"websocket.*",
] ]
follow_imports = "skip" follow_imports = "skip"
ignore_missing_imports = "True" ignore_missing_imports = "True"
[tool.pydantic-mypy]
init_forbid_extra = true
init_typed = true
warn_required_dynamic_aliases = true
warn_untyped_fields = true
[tool.pytest.ini_options] [tool.pytest.ini_options]
log_cli = false log_cli = false
testpaths = [ testpaths = [

View file

@ -1,6 +1,6 @@
import asyncio import asyncio
import json import json
from typing import ClassVar, Dict, List from typing import ClassVar
from fastapi import WebSocket, WebSocketDisconnect from fastapi import WebSocket, WebSocketDisconnect
from lnbits.helpers import urlsafe_short_hash from lnbits.helpers import urlsafe_short_hash
@ -16,7 +16,7 @@ all_routers: list["NostrRouter"] = []
class NostrRouter: class NostrRouter:
received_subscription_events: ClassVar[dict[str, List[EventMessage]]] = {} received_subscription_events: ClassVar[dict[str, list[EventMessage]]] = {}
received_subscription_notices: ClassVar[list[NoticeMessage]] = [] received_subscription_notices: ClassVar[list[NoticeMessage]] = []
received_subscription_eosenotices: ClassVar[dict[str, EndOfStoredEventsMessage]] = ( received_subscription_eosenotices: ClassVar[dict[str, EndOfStoredEventsMessage]] = (
{} {}
@ -25,11 +25,11 @@ class NostrRouter:
def __init__(self, websocket: WebSocket): def __init__(self, websocket: WebSocket):
self.connected: bool = True self.connected: bool = True
self.websocket: WebSocket = websocket self.websocket: WebSocket = websocket
self.tasks: List[asyncio.Task] = [] self.tasks: list[asyncio.Task] = []
self.original_subscription_ids: Dict[str, str] = {} self.original_subscription_ids: dict[str, str] = {}
@property @property
def subscriptions(self) -> List[str]: def subscriptions(self) -> list[str]:
return list(self.original_subscription_ids.keys()) return list(self.original_subscription_ids.keys())
def start(self): def start(self):

2299
uv.lock generated Normal file

File diff suppressed because it is too large Load diff