From 45b36b896b5e2a79488649adf86ce304a3e696c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 17 Apr 2023 08:07:46 +0200 Subject: [PATCH 1/8] move flake config from setup.cfg to .flake8, to not confuse it with setup.cfg python package settings --- setup.cfg => .flake8 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename setup.cfg => .flake8 (100%) diff --git a/setup.cfg b/.flake8 similarity index 100% rename from setup.cfg rename to .flake8 From 42b7cd304691595808f71b8077a12c8086108484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 17 Apr 2023 08:09:34 +0200 Subject: [PATCH 2/8] fix E266 --- .flake8 | 2 -- lnbits/settings.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/.flake8 b/.flake8 index fada0c12..affa4ed5 100644 --- a/.flake8 +++ b/.flake8 @@ -20,8 +20,6 @@ ignore = F821, # E265 block comment should start with '# ' - should be addressed in future PR E265, - # E266 too many leading '#' for block comment - should be addressed in future PR - E266, # E722 do not use bare 'except' - should be addressed in future PR E722, # flake8-requirements import checks diff --git a/lnbits/settings.py b/lnbits/settings.py index c5bdc43d..e4df2772 100644 --- a/lnbits/settings.py +++ b/lnbits/settings.py @@ -355,8 +355,6 @@ def send_admin_user_to_saas(): ) -############### INIT ################# - readonly_variables = ReadOnlySettings.readonly_fields() transient_variables = TransientSettings.readonly_fields() From b465ecf22afa54d5689d8433653f48d3469f9f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 17 Apr 2023 08:11:07 +0200 Subject: [PATCH 3/8] E265 --- .flake8 | 2 -- lnbits/core/views/api.py | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.flake8 b/.flake8 index affa4ed5..e87185fa 100644 --- a/.flake8 +++ b/.flake8 @@ -18,8 +18,6 @@ ignore = W503, # F821: undefined name - should be addressed in future PR F821, - # E265 block comment should start with '# ' - should be addressed in future PR - E265, # E722 do not use bare 'except' - should be addressed in future PR E722, # flake8-requirements import checks diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index e0555b37..6421706f 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -704,7 +704,7 @@ async def api_auditor(): } -##################UNIVERSAL WEBSOCKET MANAGER######################## +# UNIVERSAL WEBSOCKET MANAGER @core_app.websocket("/api/v1/ws/{item_id}") @@ -843,7 +843,7 @@ async def get_extension_releases(ext_id: str): ) -############################TINYURL################################## +# TINYURL @core_app.post("/api/v1/tinyurl") From 4a72a5b6b3ae99b28f4cfb54d0cf2de51ae848db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 17 Apr 2023 08:14:04 +0200 Subject: [PATCH 4/8] E241, E501 --- .flake8 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.flake8 b/.flake8 index e87185fa..bd5f2e22 100644 --- a/.flake8 +++ b/.flake8 @@ -6,12 +6,8 @@ ignore = E203, # E221: multiple spaces before operator E221, - # E241: multiple spaces after ':' - E241, # E402: module level import not at top of file E402, - # E501: line too long - E501, # E741 ambiguous variable name E741, # W503: line break before binary operator From 1ac9d2572d8695a20f906201b1e8008c6644c19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 17 Apr 2023 08:16:59 +0200 Subject: [PATCH 5/8] E203, E221 --- .flake8 | 4 ---- lnbits/bolt11.py | 4 ++-- lnbits/core/migrations.py | 2 +- lnbits/middleware.py | 2 +- lnbits/wallets/lnbits.py | 2 +- lnbits/wallets/lntips.py | 2 +- 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.flake8 b/.flake8 index bd5f2e22..f9e0eabd 100644 --- a/.flake8 +++ b/.flake8 @@ -2,10 +2,6 @@ max-line-length = 300 exclude = lnbits/wallets/lnd_grpc_files/, lnbits/extensions/ ignore = - # E203 whitespace before ':' - E203, - # E221: multiple spaces before operator - E221, # E402: module level import not at top of file E402, # E741 ambiguous variable name diff --git a/lnbits/bolt11.py b/lnbits/bolt11.py index 84bf61e7..c62bbe5f 100644 --- a/lnbits/bolt11.py +++ b/lnbits/bolt11.py @@ -50,7 +50,7 @@ def decode(pr: str) -> Invoice: raise ValueError("Too short to contain signature") # extract the signature - signature = bitarray[-65 * 8 :].tobytes() + signature = bitarray[-65 * 8:].tobytes() # the tagged fields as a bitstream data = bitstring.ConstBitStream(bitarray[: -65 * 8]) @@ -61,7 +61,7 @@ def decode(pr: str) -> Invoice: # decode the amount from the hrp m = re.search(r"[^\d]+", hrp[2:]) if m: - amountstr = hrp[2 + m.end() :] + amountstr = hrp[2 + m.end():] if amountstr != "": invoice.amount_msat = _unshorten_amount(amountstr) diff --git a/lnbits/core/migrations.py b/lnbits/core/migrations.py index c19f40af..4e84ef85 100644 --- a/lnbits/core/migrations.py +++ b/lnbits/core/migrations.py @@ -109,7 +109,7 @@ async def m002_add_fields_to_apipayments(db): for ext in ["withdraw", "events", "lnticket", "paywall", "tpos"]: prefix = f"#{ext} " if row["memo"].startswith(prefix): - new = row["memo"][len(prefix) :] + new = row["memo"][len(prefix):] await db.execute( """ UPDATE apipayments SET extra = ?, memo = ? diff --git a/lnbits/middleware.py b/lnbits/middleware.py index 93a5671c..815dbc2f 100644 --- a/lnbits/middleware.py +++ b/lnbits/middleware.py @@ -125,7 +125,7 @@ class ExtensionsRedirectMiddleware: def _new_path(self, redirect: dict, req_path: str) -> str: from_path = redirect["from_path"].split("/") redirect_to = redirect["redirect_to_path"].split("/") - req_tail_path = req_path.split("/")[len(from_path) :] + req_tail_path = req_path.split("/")[len(from_path):] elements = [ e for e in ([redirect["ext_id"]] + redirect_to + req_tail_path) if e != "" diff --git a/lnbits/wallets/lnbits.py b/lnbits/wallets/lnbits.py index 902711d6..e222b1a1 100644 --- a/lnbits/wallets/lnbits.py +++ b/lnbits/wallets/lnbits.py @@ -164,7 +164,7 @@ class LNbitsWallet(Wallet): sse_trigger = True continue elif sse_trigger and line.startswith("data:"): - data = json.loads(line[len("data:") :]) + data = json.loads(line[len("data:"):]) sse_trigger = False yield data["payment_hash"] else: diff --git a/lnbits/wallets/lntips.py b/lnbits/wallets/lntips.py index be8159b9..e6a3275b 100644 --- a/lnbits/wallets/lntips.py +++ b/lnbits/wallets/lntips.py @@ -155,7 +155,7 @@ class LnTipsWallet(Wallet): prefix = "data: " if not line.startswith(prefix): continue - data = line[len(prefix) :] # sse parsing + data = line[len(prefix):] # sse parsing inv = json.loads(data) if not inv.get("payment_hash"): continue From 0af22a6256cb653cb6278c09157c01e66b68638c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 17 Apr 2023 08:21:45 +0200 Subject: [PATCH 6/8] E471 --- .flake8 | 2 -- lnbits/bolt11.py | 16 ++++++++-------- lnbits/db.py | 2 +- lnbits/wallets/lndrest.py | 4 ++-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.flake8 b/.flake8 index f9e0eabd..532b94f0 100644 --- a/.flake8 +++ b/.flake8 @@ -4,8 +4,6 @@ exclude = lnbits/wallets/lnd_grpc_files/, lnbits/extensions/ ignore = # E402: module level import not at top of file E402, - # E741 ambiguous variable name - E741, # W503: line break before binary operator W503, # F821: undefined name - should be addressed in future PR diff --git a/lnbits/bolt11.py b/lnbits/bolt11.py index c62bbe5f..9c7229cb 100644 --- a/lnbits/bolt11.py +++ b/lnbits/bolt11.py @@ -316,23 +316,23 @@ def _pull_tagged(stream): # Tagged field containing BitArray -def tagged(char, l): +def tagged(char, bits): # Tagged fields need to be zero-padded to 5 bits. - while l.len % 5 != 0: - l.append("0b0") + while bits.len % 5 != 0: + bits.append("0b0") return ( bitstring.pack( "uint:5, uint:5, uint:5", CHARSET.find(char), - (l.len / 5) / 32, - (l.len / 5) % 32, + (bits.len / 5) / 32, + (bits.len / 5) % 32, ) - + l + + bits ) -def tagged_bytes(char, l): - return tagged(char, bitstring.BitArray(l)) +def tagged_bytes(char, bits): + return tagged(char, bitstring.BitArray(bits)) def _trim_to_bytes(barr): diff --git a/lnbits/db.py b/lnbits/db.py index 4a6673a7..6c9002a3 100644 --- a/lnbits/db.py +++ b/lnbits/db.py @@ -96,7 +96,7 @@ class Connection(Compat): # tuple to list and back to tuple value_list = [values] if isinstance(values, str) else list(values) - values = tuple([cleanhtml(l) for l in value_list]) + values = tuple([cleanhtml(val) for val in value_list]) return values async def fetchall(self, query: str, values: tuple = ()) -> list: diff --git a/lnbits/wallets/lndrest.py b/lnbits/wallets/lndrest.py index 303b4879..b891be59 100644 --- a/lnbits/wallets/lndrest.py +++ b/lnbits/wallets/lndrest.py @@ -173,9 +173,9 @@ class LndRestWallet(Wallet): timeout=None, headers=self.auth, verify=self.cert ) as client: async with client.stream("GET", url) as r: - async for l in r.aiter_lines(): + async for json_line in r.aiter_lines(): try: - line = json.loads(l) + line = json.loads(json_line) if line.get("error"): logger.error( line["error"]["message"] From 0b596c00ca51ee373555bba0c0fbf5987c706359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 17 Apr 2023 08:29:01 +0200 Subject: [PATCH 7/8] reduce max string length --- .flake8 | 2 +- lnbits/app.py | 5 ++++- lnbits/core/migrations.py | 3 ++- lnbits/core/services.py | 3 ++- lnbits/wallets/void.py | 7 ++++--- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.flake8 b/.flake8 index 532b94f0..6c11afad 100644 --- a/.flake8 +++ b/.flake8 @@ -1,5 +1,5 @@ [flake8] -max-line-length = 300 +max-line-length = 150 exclude = lnbits/wallets/lnd_grpc_files/, lnbits/extensions/ ignore = # E402: module level import not at top of file diff --git a/lnbits/app.py b/lnbits/app.py index 03dff297..f8bfd448 100644 --- a/lnbits/app.py +++ b/lnbits/app.py @@ -428,7 +428,10 @@ class Formatter: self.padding = 0 self.minimal_fmt: str = "{time:YYYY-MM-DD HH:mm:ss.SS} | {level} | {message}\n" if settings.debug: - self.fmt: str = "{time:YYYY-MM-DD HH:mm:ss.SS} | {level: <4} | {name}:{function}:{line} | {message}\n" + self.fmt: str = ( + "{time:YYYY-MM-DD HH:mm:ss.SS} | {level: <4} | " + "{name}:{function}:{line} | {message}\n" + ) else: self.fmt: str = self.minimal_fmt diff --git a/lnbits/core/migrations.py b/lnbits/core/migrations.py index 4e84ef85..b66fa696 100644 --- a/lnbits/core/migrations.py +++ b/lnbits/core/migrations.py @@ -168,7 +168,8 @@ async def m004_ensure_fees_are_always_negative(db): async def m005_balance_check_balance_notify(db): """ - Keep track of balanceCheck-enabled lnurl-withdrawals to be consumed by an LNbits wallet and of balanceNotify URLs supplied by users to empty their wallets. + Keep track of balanceCheck-enabled lnurl-withdrawals to be consumed by an + LNbits wallet and of balanceNotify URLs supplied by users to empty their wallets. """ await db.execute( diff --git a/lnbits/core/services.py b/lnbits/core/services.py index 9b699571..49ae4ef5 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -334,7 +334,8 @@ async def perform_lnurlauth( def encode_strict_der(r: int, s: int, order: int): # if s > order/2 verification will fail sometimes - # so we must fix it here (see https://github.com/indutny/elliptic/blob/e71b2d9359c5fe9437fbf46f1f05096de447de57/lib/elliptic/ec/index.js#L146-L147) + # so we must fix it here see: + # https://github.com/indutny/elliptic/blob/e71b2d9359c5fe9437fbf46f1f05096de447de57/lib/elliptic/ec/index.js#L146-L147 if s > order // 2: s = order - s diff --git a/lnbits/wallets/void.py b/lnbits/wallets/void.py index b74eb245..c109ddd0 100644 --- a/lnbits/wallets/void.py +++ b/lnbits/wallets/void.py @@ -23,9 +23,10 @@ class VoidWallet(Wallet): raise Unsupported("") async def status(self) -> StatusResponse: - logger.warning( - "This backend does nothing, it is here just as a placeholder, you must configure an actual backend before being able to do anything useful with LNbits." - ) + logger.warning(( + "This backend does nothing, it is here just as a placeholder, you must configure an " + "actual backend before being able to do anything useful with LNbits." + )) return StatusResponse(None, 0) async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse: From 06fa6c10c13a3fbab3d3b714cd36c147d577932e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 17 Apr 2023 08:38:12 +0200 Subject: [PATCH 8/8] reintroduce E203, black does not like that one --- .flake8 | 2 ++ lnbits/bolt11.py | 4 ++-- lnbits/core/migrations.py | 2 +- lnbits/middleware.py | 2 +- lnbits/wallets/lnbits.py | 2 +- lnbits/wallets/lntips.py | 2 +- lnbits/wallets/void.py | 10 ++++++---- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.flake8 b/.flake8 index 6c11afad..9fc73459 100644 --- a/.flake8 +++ b/.flake8 @@ -2,6 +2,8 @@ max-line-length = 150 exclude = lnbits/wallets/lnd_grpc_files/, lnbits/extensions/ ignore = + # E203 whitespace before ':' black does not like it + E203 # E402: module level import not at top of file E402, # W503: line break before binary operator diff --git a/lnbits/bolt11.py b/lnbits/bolt11.py index 9c7229cb..c2e750f1 100644 --- a/lnbits/bolt11.py +++ b/lnbits/bolt11.py @@ -50,7 +50,7 @@ def decode(pr: str) -> Invoice: raise ValueError("Too short to contain signature") # extract the signature - signature = bitarray[-65 * 8:].tobytes() + signature = bitarray[-65 * 8 :].tobytes() # the tagged fields as a bitstream data = bitstring.ConstBitStream(bitarray[: -65 * 8]) @@ -61,7 +61,7 @@ def decode(pr: str) -> Invoice: # decode the amount from the hrp m = re.search(r"[^\d]+", hrp[2:]) if m: - amountstr = hrp[2 + m.end():] + amountstr = hrp[2 + m.end() :] if amountstr != "": invoice.amount_msat = _unshorten_amount(amountstr) diff --git a/lnbits/core/migrations.py b/lnbits/core/migrations.py index b66fa696..435e30b0 100644 --- a/lnbits/core/migrations.py +++ b/lnbits/core/migrations.py @@ -109,7 +109,7 @@ async def m002_add_fields_to_apipayments(db): for ext in ["withdraw", "events", "lnticket", "paywall", "tpos"]: prefix = f"#{ext} " if row["memo"].startswith(prefix): - new = row["memo"][len(prefix):] + new = row["memo"][len(prefix) :] await db.execute( """ UPDATE apipayments SET extra = ?, memo = ? diff --git a/lnbits/middleware.py b/lnbits/middleware.py index 815dbc2f..93a5671c 100644 --- a/lnbits/middleware.py +++ b/lnbits/middleware.py @@ -125,7 +125,7 @@ class ExtensionsRedirectMiddleware: def _new_path(self, redirect: dict, req_path: str) -> str: from_path = redirect["from_path"].split("/") redirect_to = redirect["redirect_to_path"].split("/") - req_tail_path = req_path.split("/")[len(from_path):] + req_tail_path = req_path.split("/")[len(from_path) :] elements = [ e for e in ([redirect["ext_id"]] + redirect_to + req_tail_path) if e != "" diff --git a/lnbits/wallets/lnbits.py b/lnbits/wallets/lnbits.py index e222b1a1..902711d6 100644 --- a/lnbits/wallets/lnbits.py +++ b/lnbits/wallets/lnbits.py @@ -164,7 +164,7 @@ class LNbitsWallet(Wallet): sse_trigger = True continue elif sse_trigger and line.startswith("data:"): - data = json.loads(line[len("data:"):]) + data = json.loads(line[len("data:") :]) sse_trigger = False yield data["payment_hash"] else: diff --git a/lnbits/wallets/lntips.py b/lnbits/wallets/lntips.py index e6a3275b..be8159b9 100644 --- a/lnbits/wallets/lntips.py +++ b/lnbits/wallets/lntips.py @@ -155,7 +155,7 @@ class LnTipsWallet(Wallet): prefix = "data: " if not line.startswith(prefix): continue - data = line[len(prefix):] # sse parsing + data = line[len(prefix) :] # sse parsing inv = json.loads(data) if not inv.get("payment_hash"): continue diff --git a/lnbits/wallets/void.py b/lnbits/wallets/void.py index c109ddd0..60f981ea 100644 --- a/lnbits/wallets/void.py +++ b/lnbits/wallets/void.py @@ -23,10 +23,12 @@ class VoidWallet(Wallet): raise Unsupported("") async def status(self) -> StatusResponse: - logger.warning(( - "This backend does nothing, it is here just as a placeholder, you must configure an " - "actual backend before being able to do anything useful with LNbits." - )) + logger.warning( + ( + "This backend does nothing, it is here just as a placeholder, you must configure an " + "actual backend before being able to do anything useful with LNbits." + ) + ) return StatusResponse(None, 0) async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse: