Skip to content

Commit

Permalink
feat: code quality (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
dni authored Aug 2, 2024
1 parent 06e1469 commit f34244e
Show file tree
Hide file tree
Showing 21 changed files with 2,848 additions and 97 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: lint
on:
push:
branches:
- main
pull_request:

jobs:
lint:
uses: lnbits/lnbits/.github/workflows/lint.yml@dev
15 changes: 7 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:

release:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -34,12 +33,12 @@ jobs:
- name: Create pull request in extensions repo
env:
GH_TOKEN: ${{ secrets.EXT_GITHUB }}
repo_name: "${{ github.event.repository.name }}"
tag: "${{ github.ref_name }}"
branch: "update-${{ github.event.repository.name }}-${{ github.ref_name }}"
title: "[UPDATE] ${{ github.event.repository.name }} to ${{ github.ref_name }}"
body: "https://github.com/lnbits/${{ github.event.repository.name }}/releases/${{ github.ref_name }}"
archive: "https://github.com/lnbits/${{ github.event.repository.name }}/archive/refs/tags/${{ github.ref_name }}.zip"
repo_name: '${{ github.event.repository.name }}'
tag: '${{ github.ref_name }}'
branch: 'update-${{ github.event.repository.name }}-${{ github.ref_name }}'
title: '[UPDATE] ${{ github.event.repository.name }} to ${{ github.ref_name }}'
body: 'https://github.com/lnbits/${{ github.event.repository.name }}/releases/${{ github.ref_name }}'
archive: 'https://github.com/lnbits/${{ github.event.repository.name }}/archive/refs/tags/${{ github.ref_name }}.zip'
run: |
cd lnbits-extensions
git checkout -b $branch
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
__pycache__
node_modules
.mypy_cache
.venv
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"semi": false,
"arrowParens": "avoid",
"insertPragma": false,
"printWidth": 80,
"proseWrap": "preserve",
"singleQuote": true,
"trailingComma": "none",
"useTabs": false,
"bracketSameLine": false,
"bracketSpacing": false
}
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
all: format check

format: prettier black ruff

check: mypy pyright checkblack checkruff checkprettier

prettier:
poetry run ./node_modules/.bin/prettier --write .
pyright:
poetry run ./node_modules/.bin/pyright

mypy:
poetry run mypy .

black:
poetry run black .

ruff:
poetry run ruff check . --fix

checkruff:
poetry run ruff check .

checkprettier:
poetry run ./node_modules/.bin/prettier --check .

checkblack:
poetry run black --check .

checkeditorconfig:
editorconfig-checker

test:
PYTHONUNBUFFERED=1 \
DEBUG=true \
poetry run pytest
install-pre-commit-hook:
@echo "Installing pre-commit hook to git"
@echo "Uninstall the hook with poetry run pre-commit uninstall"
poetry run pre-commit install

pre-commit:
poetry run pre-commit run --all-files


checkbundle:
@echo "skipping checkbundle"
30 changes: 14 additions & 16 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import asyncio
from loguru import logger

from fastapi import APIRouter
from loguru import logger

from lnbits.db import Database
from lnbits.helpers import template_renderer
from lnbits.tasks import create_permanent_unique_task

db = Database("ext_copilot")
from .crud import db
from .tasks import wait_for_paid_invoices
from .views import copilot_generic_router
from .views_api import copilot_api_router
from .views_lnurl import copilot_lnurl_router

copilot_static_files = [
{
Expand All @@ -16,16 +16,9 @@
}
]
copilot_ext: APIRouter = APIRouter(prefix="/copilot", tags=["copilot"])


def copilot_renderer():
return template_renderer(["copilot/templates"])


from .lnurl import * # noqa
from .tasks import wait_for_paid_invoices
from .views import * # noqa
from .views_api import * # noqa
copilot_ext.include_router(copilot_generic_router)
copilot_ext.include_router(copilot_api_router)
copilot_ext.include_router(copilot_lnurl_router)

scheduled_tasks: list[asyncio.Task] = []

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


def copilot_start():
from lnbits.tasks import create_permanent_unique_task

task = create_permanent_unique_task("ext_copilot", wait_for_paid_invoices)
scheduled_tasks.append(task)


__all__ = ["copilot_ext", "copilot_static_files", "copilot_start", "copilot_stop", "db"]
12 changes: 4 additions & 8 deletions crud.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from typing import List, Optional

from lnbits.db import Database
from lnbits.helpers import urlsafe_short_hash

from . import db
from .models import Copilot, CreateCopilotData

###############COPILOTS##########################
db = Database("ext_copilot")


async def create_copilot(
data: CreateCopilotData, inkey: Optional[str] = ""
) -> Copilot:
async def create_copilot(data: CreateCopilotData, inkey: Optional[str] = "") -> Copilot:
copilot_id = urlsafe_short_hash()
await db.execute(
"""
Expand Down Expand Up @@ -68,9 +66,7 @@ async def create_copilot(
return copilot


async def update_copilot(
data: CreateCopilotData, copilot_id: str
) -> Copilot:
async def update_copilot(data: CreateCopilotData, copilot_id: str) -> Copilot:
q = ", ".join([f"{field[0]} = ?" for field in data])
items = [f"{field[1]}" for field in data]
items.append(copilot_id)
Expand Down
8 changes: 4 additions & 4 deletions description.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Get tipped in your video streams and trigger events!
Use in conjunction with OBS (Open Broadcaster Software) by simply connecting the browser window.

* Supports LNURLpay comments, allowing you to optionally enable paid comments on the screen.
* Includes an optional troll box.
* Features a BTC price ticker.
* Elements can be rearranged on the screen.
- Supports LNURLpay comments, allowing you to optionally enable paid comments on the screen.
- Includes an optional troll box.
- Features a BTC price ticker.
- Elements can be rearranged on the screen.
2 changes: 1 addition & 1 deletion migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ async def m003_fix_data_types(db):

await db.execute(
"INSERT INTO copilot.newer_copilots SELECT * FROM copilot.copilots"
)
)
5 changes: 2 additions & 3 deletions models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import Optional

from fastapi import Query, Request
from lnurl.types import LnurlPayMetadata
from lnurl import encode as lnurl_encode
from pydantic import BaseModel

from lnbits.lnurl import encode as lnurl_encode


class CreateCopilotData(BaseModel):
user: str = Query(None)
Expand Down
59 changes: 59 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "copilot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"prettier": "^3.2.5",
"pyright": "^1.1.358"
}
}
Loading

0 comments on commit f34244e

Please sign in to comment.