Skip to content

Commit f34244e

Browse files
authored
feat: code quality (#20)
1 parent 06e1469 commit f34244e

21 files changed

Lines changed: 2848 additions & 97 deletions

.github/workflows/lint.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: lint
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
jobs:
9+
lint:
10+
uses: lnbits/lnbits/.github/workflows/lint.yml@dev

.github/workflows/release.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
on:
22
push:
33
tags:
4-
- "v[0-9]+.[0-9]+.[0-9]+"
4+
- 'v[0-9]+.[0-9]+.[0-9]+'
55

66
jobs:
7-
87
release:
98
runs-on: ubuntu-latest
109
steps:
@@ -34,12 +33,12 @@ jobs:
3433
- name: Create pull request in extensions repo
3534
env:
3635
GH_TOKEN: ${{ secrets.EXT_GITHUB }}
37-
repo_name: "${{ github.event.repository.name }}"
38-
tag: "${{ github.ref_name }}"
39-
branch: "update-${{ github.event.repository.name }}-${{ github.ref_name }}"
40-
title: "[UPDATE] ${{ github.event.repository.name }} to ${{ github.ref_name }}"
41-
body: "https://github.com/lnbits/${{ github.event.repository.name }}/releases/${{ github.ref_name }}"
42-
archive: "https://github.com/lnbits/${{ github.event.repository.name }}/archive/refs/tags/${{ github.ref_name }}.zip"
36+
repo_name: '${{ github.event.repository.name }}'
37+
tag: '${{ github.ref_name }}'
38+
branch: 'update-${{ github.event.repository.name }}-${{ github.ref_name }}'
39+
title: '[UPDATE] ${{ github.event.repository.name }} to ${{ github.ref_name }}'
40+
body: 'https://github.com/lnbits/${{ github.event.repository.name }}/releases/${{ github.ref_name }}'
41+
archive: 'https://github.com/lnbits/${{ github.event.repository.name }}/archive/refs/tags/${{ github.ref_name }}.zip'
4342
run: |
4443
cd lnbits-extensions
4544
git checkout -b $branch

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
__pycache__
2+
node_modules
3+
.mypy_cache
4+
.venv

.prettierrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"semi": false,
3+
"arrowParens": "avoid",
4+
"insertPragma": false,
5+
"printWidth": 80,
6+
"proseWrap": "preserve",
7+
"singleQuote": true,
8+
"trailingComma": "none",
9+
"useTabs": false,
10+
"bracketSameLine": false,
11+
"bracketSpacing": false
12+
}

Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
all: format check
2+
3+
format: prettier black ruff
4+
5+
check: mypy pyright checkblack checkruff checkprettier
6+
7+
prettier:
8+
poetry run ./node_modules/.bin/prettier --write .
9+
pyright:
10+
poetry run ./node_modules/.bin/pyright
11+
12+
mypy:
13+
poetry run mypy .
14+
15+
black:
16+
poetry run black .
17+
18+
ruff:
19+
poetry run ruff check . --fix
20+
21+
checkruff:
22+
poetry run ruff check .
23+
24+
checkprettier:
25+
poetry run ./node_modules/.bin/prettier --check .
26+
27+
checkblack:
28+
poetry run black --check .
29+
30+
checkeditorconfig:
31+
editorconfig-checker
32+
33+
test:
34+
PYTHONUNBUFFERED=1 \
35+
DEBUG=true \
36+
poetry run pytest
37+
install-pre-commit-hook:
38+
@echo "Installing pre-commit hook to git"
39+
@echo "Uninstall the hook with poetry run pre-commit uninstall"
40+
poetry run pre-commit install
41+
42+
pre-commit:
43+
poetry run pre-commit run --all-files
44+
45+
46+
checkbundle:
47+
@echo "skipping checkbundle"

__init__.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import asyncio
2-
from loguru import logger
32

43
from fastapi import APIRouter
4+
from loguru import logger
55

6-
from lnbits.db import Database
7-
from lnbits.helpers import template_renderer
8-
from lnbits.tasks import create_permanent_unique_task
9-
10-
db = Database("ext_copilot")
6+
from .crud import db
7+
from .tasks import wait_for_paid_invoices
8+
from .views import copilot_generic_router
9+
from .views_api import copilot_api_router
10+
from .views_lnurl import copilot_lnurl_router
1111

1212
copilot_static_files = [
1313
{
@@ -16,16 +16,9 @@
1616
}
1717
]
1818
copilot_ext: APIRouter = APIRouter(prefix="/copilot", tags=["copilot"])
19-
20-
21-
def copilot_renderer():
22-
return template_renderer(["copilot/templates"])
23-
24-
25-
from .lnurl import * # noqa
26-
from .tasks import wait_for_paid_invoices
27-
from .views import * # noqa
28-
from .views_api import * # noqa
19+
copilot_ext.include_router(copilot_generic_router)
20+
copilot_ext.include_router(copilot_api_router)
21+
copilot_ext.include_router(copilot_lnurl_router)
2922

3023
scheduled_tasks: list[asyncio.Task] = []
3124

@@ -39,5 +32,10 @@ def copilot_stop():
3932

4033

4134
def copilot_start():
35+
from lnbits.tasks import create_permanent_unique_task
36+
4237
task = create_permanent_unique_task("ext_copilot", wait_for_paid_invoices)
4338
scheduled_tasks.append(task)
39+
40+
41+
__all__ = ["copilot_ext", "copilot_static_files", "copilot_start", "copilot_stop", "db"]

crud.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
from typing import List, Optional
22

3+
from lnbits.db import Database
34
from lnbits.helpers import urlsafe_short_hash
45

5-
from . import db
66
from .models import Copilot, CreateCopilotData
77

8-
###############COPILOTS##########################
8+
db = Database("ext_copilot")
99

1010

11-
async def create_copilot(
12-
data: CreateCopilotData, inkey: Optional[str] = ""
13-
) -> Copilot:
11+
async def create_copilot(data: CreateCopilotData, inkey: Optional[str] = "") -> Copilot:
1412
copilot_id = urlsafe_short_hash()
1513
await db.execute(
1614
"""
@@ -68,9 +66,7 @@ async def create_copilot(
6866
return copilot
6967

7068

71-
async def update_copilot(
72-
data: CreateCopilotData, copilot_id: str
73-
) -> Copilot:
69+
async def update_copilot(data: CreateCopilotData, copilot_id: str) -> Copilot:
7470
q = ", ".join([f"{field[0]} = ?" for field in data])
7571
items = [f"{field[1]}" for field in data]
7672
items.append(copilot_id)

description.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Get tipped in your video streams and trigger events!
22
Use in conjunction with OBS (Open Broadcaster Software) by simply connecting the browser window.
33

4-
* Supports LNURLpay comments, allowing you to optionally enable paid comments on the screen.
5-
* Includes an optional troll box.
6-
* Features a BTC price ticker.
7-
* Elements can be rearranged on the screen.
4+
- Supports LNURLpay comments, allowing you to optionally enable paid comments on the screen.
5+
- Includes an optional troll box.
6+
- Features a BTC price ticker.
7+
- Elements can be rearranged on the screen.

migrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ async def m003_fix_data_types(db):
7676

7777
await db.execute(
7878
"INSERT INTO copilot.newer_copilots SELECT * FROM copilot.copilots"
79-
)
79+
)

models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from typing import Optional
2+
23
from fastapi import Query, Request
3-
from lnurl.types import LnurlPayMetadata
4+
from lnurl import encode as lnurl_encode
45
from pydantic import BaseModel
56

6-
from lnbits.lnurl import encode as lnurl_encode
7-
87

98
class CreateCopilotData(BaseModel):
109
user: str = Query(None)

0 commit comments

Comments
 (0)