Skip to content

Commit

Permalink
feat: code quality (#11)
Browse files Browse the repository at this point in the history
* feat: code quality

* fixes
  • Loading branch information
dni authored Aug 2, 2024
1 parent 01323f8 commit 896930f
Show file tree
Hide file tree
Showing 19 changed files with 2,817 additions and 201 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
131 changes: 3 additions & 128 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,129 +1,4 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
__pycache__
node_modules
.mypy_cache
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
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"
16 changes: 6 additions & 10 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from fastapi import APIRouter

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

db = Database("ext_tipjar")
from .crud import db
from .views import tipjar_generic_router
from .views_api import tipjar_api_router

tipjar_ext: APIRouter = APIRouter(prefix="/tipjar", tags=["tipjar"])
tipjar_ext.include_router(tipjar_generic_router)
tipjar_ext.include_router(tipjar_api_router)

tipjar_static_files = [
{
Expand All @@ -15,9 +16,4 @@
]


def tipjar_renderer():
return template_renderer(["tipjar/templates"])


from .views import * # noqa: F401,F403
from .views_api import * # noqa: F401,F403
__all__ = ["db", "tipjar_ext", "tipjar_static_files"]
10 changes: 5 additions & 5 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Tip Jar",
"short_description": "Accept Bitcoin donations, with messages attached!",
"tile": "/tipjar/static/image/tipjar.png",
"contributors": ["Fittiboy"],
"min_lnbits_version": "0.11.0"
"name": "Tip Jar",
"short_description": "Accept Bitcoin donations, with messages attached!",
"tile": "/tipjar/static/image/tipjar.png",
"contributors": ["Fittiboy"],
"min_lnbits_version": "0.11.0"
}
23 changes: 12 additions & 11 deletions crud.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from typing import List, Optional
from typing import Optional

from lnbits.db import SQLITE
from lnbits.db import SQLITE, Database

from . import db
from .models import Tip, TipJar, createTipJar
from .models import CreateTipJar, Tip, TipJar

db = Database("ext_tipjar")


async def create_tip(
id: str, wallet: str, message: str, name: str, sats: int, tipjar: str
tip_id: str, wallet: str, message: str, name: str, sats: int, tipjar: str
) -> Tip:
"""Create a new Tip"""
await db.execute(
Expand All @@ -22,21 +23,21 @@ async def create_tip(
)
VALUES (?, ?, ?, ?, ?, ?)
""",
(id, wallet, name, message, sats, tipjar),
(tip_id, wallet, name, message, sats, tipjar),
)

tip = await get_tip(id)
tip = await get_tip(tip_id)
assert tip, "Newly created tip couldn't be retrieved"
return tip


async def create_tipjar(data: createTipJar) -> TipJar:
async def create_tipjar(data: CreateTipJar) -> TipJar:
"""Create a new TipJar"""

returning = "" if db.type == SQLITE else "RETURNING ID"
method = db.execute if db.type == SQLITE else db.fetchone

result = await (method)(
result = await method(
f"""
INSERT INTO tipjar.TipJars (
name,
Expand All @@ -52,7 +53,7 @@ async def create_tipjar(data: createTipJar) -> TipJar:
if db.type == SQLITE:
tipjar_id = result._result_proxy.lastrowid
else:
tipjar_id = result[0]
tipjar_id = result[0] # type: ignore

tipjar = await get_tipjar(tipjar_id)
assert tipjar
Expand Down Expand Up @@ -87,7 +88,7 @@ async def get_tip(tip_id: str) -> Optional[Tip]:
return Tip(**row) if row else None


async def get_tipjar_tips(tipjar_id: int) -> List[Tip]:
async def get_tipjar_tips(tipjar_id: int) -> list[Tip]:
"""Return all Tips for a tipjar"""
rows = await db.fetchall("SELECT * FROM tipjar.Tips WHERE tipjar = ?", (tipjar_id,))
return [Tip(**row) for row in rows]
Expand Down
3 changes: 1 addition & 2 deletions helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import httpx

from lnbits.app import settings
from lnbits.settings import settings


async def create_charge(data: dict, api_key: str) -> str:
Expand Down
14 changes: 7 additions & 7 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"repos": [
{
"id": "tipjar",
"organisation": "lnbits",
"repository": "tipjar"
}
]
"repos": [
{
"id": "tipjar",
"organisation": "lnbits",
"repository": "tipjar"
}
]
}
6 changes: 3 additions & 3 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pydantic import BaseModel


class createTip(BaseModel):
class CreateTip(BaseModel):
id: str
wallet: str
sats: int
Expand All @@ -28,14 +28,14 @@ def from_row(cls, row: Row) -> "Tip":
return cls(**dict(row))


class createTipJar(BaseModel):
class CreateTipJar(BaseModel):
name: str
wallet: str
webhook: Optional[str]
onchain: Optional[str]


class createTips(BaseModel):
class CreateTips(BaseModel):
name: str
sats: str
tipjar: str
Expand Down
Loading

0 comments on commit 896930f

Please sign in to comment.