Skip to content

Commit d4cdf8e

Browse files
authored
feat: code quality (#11)
* feat: code quality * fixus
1 parent 1ca189d commit d4cdf8e

22 files changed

+2921
-158
lines changed

.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"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Gerty - <small>[LNbits](https://github.com/lnbits/lnbits) extension</small>
2+
23
<small>For more about LNBits extension check [this tutorial](https://github.com/lnbits/lnbits/wiki/LNbits-Extensions)</small>
34

45
### Your Desktop Bitcoin Assistant

__init__.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from fastapi import APIRouter
22

3-
from lnbits.db import Database
4-
from lnbits.helpers import template_renderer
5-
6-
db = Database("ext_gerty")
3+
from .crud import db
4+
from .views import gerty_generic_router
5+
from .views_api import gerty_api_router
76

87
gerty_static_files = [
98
{
@@ -12,13 +11,8 @@
1211
}
1312
]
1413

15-
1614
gerty_ext: APIRouter = APIRouter(prefix="/gerty", tags=["Gerty"])
15+
gerty_ext.include_router(gerty_generic_router)
16+
gerty_ext.include_router(gerty_api_router)
1717

18-
19-
def gerty_renderer():
20-
return template_renderer(["gerty/templates"])
21-
22-
23-
from .views import * # noqa: F401,F403
24-
from .views_api import * # noqa: F401,F403
18+
__all__ = ["db", "gerty_ext", "gerty_static_files"]

crud.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
from typing import List, Optional, Union
44

55
import httpx
6-
from loguru import logger
7-
6+
from lnbits.db import Database
87
from lnbits.helpers import urlsafe_short_hash
8+
from loguru import logger
99

10-
from . import db
1110
from .models import CreateGerty, Gerty, MempoolEndpoint
1211

12+
db = Database("ext_gerty")
13+
1314

1415
async def create_gerty(wallet_id: str, data: CreateGerty) -> Gerty:
1516
gerty_id = urlsafe_short_hash()
@@ -83,17 +84,17 @@ async def delete_gerty(gerty_id: str) -> None:
8384
#############MEMPOOL###########
8485

8586

86-
async def get_mempool_info(endPoint: str, gerty) -> dict:
87-
logger.debug(endPoint)
87+
async def get_mempool_info(end_point: str, gerty) -> dict:
88+
logger.debug(end_point)
8889
endpoints = MempoolEndpoint()
8990
url = ""
9091
for endpoint in endpoints:
91-
if endPoint == endpoint[0]:
92+
if end_point == endpoint[0]:
9293
url = endpoint[1]
9394
row = await db.fetchone(
9495
"SELECT * FROM gerty.mempool WHERE endpoint = ? AND mempool_endpoint = ?",
9596
(
96-
endPoint,
97+
end_point,
9798
gerty.mempool_endpoint,
9899
),
99100
)
@@ -116,7 +117,7 @@ async def get_mempool_info(endPoint: str, gerty) -> dict:
116117
(
117118
mempool_id,
118119
json.dumps(response.json()),
119-
endPoint,
120+
end_point,
120121
time.time(),
121122
gerty.mempool_endpoint,
122123
),
@@ -126,11 +127,12 @@ async def get_mempool_info(endPoint: str, gerty) -> dict:
126127
async with httpx.AsyncClient() as client:
127128
response = await client.get(gerty.mempool_endpoint + url)
128129
await db.execute(
129-
"UPDATE gerty.mempool SET data = ?, time = ? WHERE endpoint = ? AND mempool_endpoint = ?",
130+
"UPDATE gerty.mempool SET data = ?, time = ? "
131+
"WHERE endpoint = ? AND mempool_endpoint = ?",
130132
(
131133
json.dumps(response.json()),
132134
time.time(),
133-
endPoint,
135+
end_point,
134136
gerty.mempool_endpoint,
135137
),
136138
)

description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Gerty, a Bitcoin Assistant controlled from your LNbits wallet.
44

55
This extension can be used as a standalone to display a dashboard of Bitcoin information or you can build / buy the Gerty hardware to display the information on an eink display.
66

7-
Buy assembled from the LNbits shop https://shop.lnbits.com/product/gerty-a-bitcoin-assistant
7+
Buy assembled from the LNbits shop https://shop.lnbits.com/product/gerty-a-bitcoin-assistant

0 commit comments

Comments
 (0)