mirror of
https://github.com/lnbits/lnbits.git
synced 2025-03-30 04:32:01 +02:00
chore: adhere to ruff's RUF
rules, 2nd try (#2420)
* chore: adhere to ruff's `RUF` rules, 2nd try closes #2382
This commit is contained in:
parent
d78f6a1f9e
commit
daa1b5a313
@ -300,7 +300,7 @@ async def check_installed_extension_files(ext: InstallableExtension) -> bool:
|
|||||||
|
|
||||||
zip_files = glob.glob(os.path.join(settings.lnbits_data_folder, "zips", "*.zip"))
|
zip_files = glob.glob(os.path.join(settings.lnbits_data_folder, "zips", "*.zip"))
|
||||||
|
|
||||||
if f"./{str(ext.zip_path)}" not in zip_files:
|
if f"./{ext.zip_path!s}" not in zip_files:
|
||||||
await ext.download_archive()
|
await ext.download_archive()
|
||||||
ext.extract_archive()
|
ext.extract_archive()
|
||||||
|
|
||||||
@ -403,7 +403,7 @@ def register_all_ext_routes(app: FastAPI):
|
|||||||
try:
|
try:
|
||||||
register_ext_routes(app, ext)
|
register_ext_routes(app, ext)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Could not load extension `{ext.code}`: {str(e)}")
|
logger.error(f"Could not load extension `{ext.code}`: {e!s}")
|
||||||
|
|
||||||
|
|
||||||
def initialize_server_logger():
|
def initialize_server_logger():
|
||||||
@ -474,7 +474,7 @@ def register_exception_handlers(app: FastAPI):
|
|||||||
async def exception_handler(request: Request, exc: Exception):
|
async def exception_handler(request: Request, exc: Exception):
|
||||||
etype, _, tb = sys.exc_info()
|
etype, _, tb = sys.exc_info()
|
||||||
traceback.print_exception(etype, exc, tb)
|
traceback.print_exception(etype, exc, tb)
|
||||||
logger.error(f"Exception: {str(exc)}")
|
logger.error(f"Exception: {exc!s}")
|
||||||
# Only the browser sends "text/html" request
|
# Only the browser sends "text/html" request
|
||||||
# not fail proof, but everything else get's a JSON response
|
# not fail proof, but everything else get's a JSON response
|
||||||
if (
|
if (
|
||||||
@ -483,7 +483,7 @@ def register_exception_handlers(app: FastAPI):
|
|||||||
and "text/html" in request.headers["accept"]
|
and "text/html" in request.headers["accept"]
|
||||||
):
|
):
|
||||||
return template_renderer().TemplateResponse(
|
return template_renderer().TemplateResponse(
|
||||||
request, "error.html", {"err": f"Error: {str(exc)}"}
|
request, "error.html", {"err": f"Error: {exc!s}"}
|
||||||
)
|
)
|
||||||
|
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
@ -495,7 +495,7 @@ def register_exception_handlers(app: FastAPI):
|
|||||||
async def validation_exception_handler(
|
async def validation_exception_handler(
|
||||||
request: Request, exc: RequestValidationError
|
request: Request, exc: RequestValidationError
|
||||||
):
|
):
|
||||||
logger.error(f"RequestValidationError: {str(exc)}")
|
logger.error(f"RequestValidationError: {exc!s}")
|
||||||
# Only the browser sends "text/html" request
|
# Only the browser sends "text/html" request
|
||||||
# not fail proof, but everything else get's a JSON response
|
# not fail proof, but everything else get's a JSON response
|
||||||
|
|
||||||
@ -507,7 +507,7 @@ def register_exception_handlers(app: FastAPI):
|
|||||||
return template_renderer().TemplateResponse(
|
return template_renderer().TemplateResponse(
|
||||||
request,
|
request,
|
||||||
"error.html",
|
"error.html",
|
||||||
{"err": f"Error: {str(exc)}"},
|
{"err": f"Error: {exc!s}"},
|
||||||
)
|
)
|
||||||
|
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
|
@ -124,7 +124,8 @@ def database_migrate():
|
|||||||
|
|
||||||
|
|
||||||
async def db_migrate():
|
async def db_migrate():
|
||||||
asyncio.create_task(migrate_databases())
|
task = asyncio.create_task(migrate_databases())
|
||||||
|
await task
|
||||||
|
|
||||||
|
|
||||||
async def migrate_databases():
|
async def migrate_databases():
|
||||||
@ -492,7 +493,7 @@ async def extensions_uninstall(
|
|||||||
click.echo(f"Failed to uninstall '{extension}' Error: '{ex.detail}'.")
|
click.echo(f"Failed to uninstall '{extension}' Error: '{ex.detail}'.")
|
||||||
return False, ex.detail
|
return False, ex.detail
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
click.echo(f"Failed to uninstall '{extension}': {str(ex)}.")
|
click.echo(f"Failed to uninstall '{extension}': {ex!s}.")
|
||||||
return False, str(ex)
|
return False, str(ex)
|
||||||
|
|
||||||
|
|
||||||
@ -530,7 +531,7 @@ async def install_extension(
|
|||||||
click.echo(f"Failed to install '{extension}' Error: '{ex.detail}'.")
|
click.echo(f"Failed to install '{extension}' Error: '{ex.detail}'.")
|
||||||
return False, ex.detail
|
return False, ex.detail
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
click.echo(f"Failed to install '{extension}': {str(ex)}.")
|
click.echo(f"Failed to install '{extension}': {ex!s}.")
|
||||||
return False, str(ex)
|
return False, str(ex)
|
||||||
|
|
||||||
|
|
||||||
@ -582,7 +583,7 @@ async def update_extension(
|
|||||||
click.echo(f"Failed to update '{extension}' Error: '{ex.detail}.")
|
click.echo(f"Failed to update '{extension}' Error: '{ex.detail}.")
|
||||||
return False, ex.detail
|
return False, ex.detail
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
click.echo(f"Failed to update '{extension}': {str(ex)}.")
|
click.echo(f"Failed to update '{extension}': {ex!s}.")
|
||||||
return False, str(ex)
|
return False, str(ex)
|
||||||
|
|
||||||
|
|
||||||
@ -605,7 +606,7 @@ async def _select_release(
|
|||||||
return latest_repo_releases[source_repo]
|
return latest_repo_releases[source_repo]
|
||||||
|
|
||||||
if len(latest_repo_releases) == 1:
|
if len(latest_repo_releases) == 1:
|
||||||
return latest_repo_releases[list(latest_repo_releases.keys())[0]]
|
return latest_repo_releases[next(iter(latest_repo_releases.keys()))]
|
||||||
|
|
||||||
repos = list(latest_repo_releases.keys())
|
repos = list(latest_repo_releases.keys())
|
||||||
repos.sort()
|
repos.sort()
|
||||||
|
@ -434,6 +434,6 @@ async def api_payments_decode(data: DecodePayment) -> JSONResponse:
|
|||||||
return JSONResponse(invoice.data)
|
return JSONResponse(invoice.data)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
{"message": f"Failed to decode: {str(exc)}"},
|
{"message": f"Failed to decode: {exc!s}"},
|
||||||
status_code=HTTPStatus.BAD_REQUEST,
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
@ -50,7 +50,7 @@ async def api_public_payment_longpolling(payment_hash):
|
|||||||
cancel_scope.cancel()
|
cancel_scope.cancel()
|
||||||
|
|
||||||
cancel_scope = asyncio.create_task(payment_info_receiver())
|
cancel_scope = asyncio.create_task(payment_info_receiver())
|
||||||
asyncio.create_task(timeouter(cancel_scope))
|
asyncio.create_task(timeouter(cancel_scope)) # noqa: RUF006
|
||||||
|
|
||||||
if response:
|
if response:
|
||||||
return response
|
return response
|
||||||
|
@ -491,8 +491,9 @@ class InstallableExtension(BaseModel):
|
|||||||
settings.lnbits_upgraded_extensions,
|
settings.lnbits_upgraded_extensions,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
settings.lnbits_upgraded_extensions = clean_upgraded_exts + [
|
settings.lnbits_upgraded_extensions = [
|
||||||
f"{self.hash}/{self.id}"
|
*clean_upgraded_exts,
|
||||||
|
f"{self.hash}/{self.id}",
|
||||||
]
|
]
|
||||||
|
|
||||||
def clean_extension_files(self):
|
def clean_extension_files(self):
|
||||||
@ -639,7 +640,7 @@ class InstallableExtension(BaseModel):
|
|||||||
extension_list += [ext]
|
extension_list += [ext]
|
||||||
extension_id_list += [e.id]
|
extension_id_list += [e.id]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Manifest {url} failed with '{str(e)}'")
|
logger.warning(f"Manifest {url} failed with '{e!s}'")
|
||||||
|
|
||||||
return extension_list
|
return extension_list
|
||||||
|
|
||||||
@ -666,7 +667,7 @@ class InstallableExtension(BaseModel):
|
|||||||
extension_releases.append(explicit_release)
|
extension_releases.append(explicit_release)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Manifest {url} failed with '{str(e)}'")
|
logger.warning(f"Manifest {url} failed with '{e!s}'")
|
||||||
|
|
||||||
return extension_releases
|
return extension_releases
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ class ExtensionsRedirectMiddleware:
|
|||||||
req_tail_path = req_path.split("/")[len(from_path) :]
|
req_tail_path = req_path.split("/")[len(from_path) :]
|
||||||
|
|
||||||
elements = [
|
elements = [
|
||||||
e for e in ([redirect["ext_id"]] + redirect_to + req_tail_path) if e != ""
|
e for e in ([redirect["ext_id"], *redirect_to, *req_tail_path]) if e != ""
|
||||||
]
|
]
|
||||||
|
|
||||||
return "/" + "/".join(elements)
|
return "/" + "/".join(elements)
|
||||||
|
@ -174,7 +174,7 @@ class LndRestNode(Node):
|
|||||||
status_code=HTTPStatus.BAD_REQUEST, detail="Channel point required"
|
status_code=HTTPStatus.BAD_REQUEST, detail="Channel point required"
|
||||||
)
|
)
|
||||||
|
|
||||||
asyncio.create_task(self._close_channel(point, force))
|
asyncio.create_task(self._close_channel(point, force)) # noqa: RUF006
|
||||||
|
|
||||||
async def get_channels(self) -> list[NodeChannel]:
|
async def get_channels(self) -> list[NodeChannel]:
|
||||||
normal, pending, closed = await asyncio.gather(
|
normal, pending, closed = await asyncio.gather(
|
||||||
|
@ -506,7 +506,7 @@ def send_admin_user_to_saas():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
"error sending super_user to saas:"
|
"error sending super_user to saas:"
|
||||||
f" {settings.lnbits_saas_callback}. Error: {str(e)}"
|
f" {settings.lnbits_saas_callback}. Error: {e!s}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ def create_unique_task(name: str, coro: Coroutine):
|
|||||||
try:
|
try:
|
||||||
unique_tasks[name].cancel()
|
unique_tasks[name].cancel()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning(f"error while cancelling task `{name}`: {str(exc)}")
|
logger.warning(f"error while cancelling task `{name}`: {exc!s}")
|
||||||
task = asyncio.create_task(coro)
|
task = asyncio.create_task(coro)
|
||||||
unique_tasks[name] = task
|
unique_tasks[name] = task
|
||||||
return task
|
return task
|
||||||
@ -54,12 +54,12 @@ def cancel_all_tasks():
|
|||||||
try:
|
try:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning(f"error while cancelling task: {str(exc)}")
|
logger.warning(f"error while cancelling task: {exc!s}")
|
||||||
for name, task in unique_tasks.items():
|
for name, task in unique_tasks.items():
|
||||||
try:
|
try:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning(f"error while cancelling task `{name}`: {str(exc)}")
|
logger.warning(f"error while cancelling task `{name}`: {exc!s}")
|
||||||
|
|
||||||
|
|
||||||
async def catch_everything_and_restart(func):
|
async def catch_everything_and_restart(func):
|
||||||
|
@ -145,7 +145,7 @@ currencies = {
|
|||||||
"TJS": "Tajikistani Somoni",
|
"TJS": "Tajikistani Somoni",
|
||||||
"TMT": "Turkmenistani Manat",
|
"TMT": "Turkmenistani Manat",
|
||||||
"TND": "Tunisian Dinar",
|
"TND": "Tunisian Dinar",
|
||||||
"TOP": "Tongan Paʻanga",
|
"TOP": "Tongan Pa'anga",
|
||||||
"TRY": "Turkish Lira",
|
"TRY": "Turkish Lira",
|
||||||
"TTD": "Trinidad and Tobago Dollar",
|
"TTD": "Trinidad and Tobago Dollar",
|
||||||
"TWD": "New Taiwan Dollar",
|
"TWD": "New Taiwan Dollar",
|
||||||
|
@ -173,9 +173,11 @@ extend-exclude = [
|
|||||||
# C - mccabe
|
# C - mccabe
|
||||||
# N - naming
|
# N - naming
|
||||||
# UP - pyupgrade
|
# UP - pyupgrade
|
||||||
select = ["F", "E", "W", "I", "A", "C", "N", "UP"]
|
# RUF - ruff specific rules
|
||||||
|
select = ["F", "E", "W", "I", "A", "C", "N", "UP", "RUF"]
|
||||||
# UP007: pyupgrade: use X | Y instead of Optional. (python3.10)
|
# UP007: pyupgrade: use X | Y instead of Optional. (python3.10)
|
||||||
ignore = ["UP007"]
|
# RUF012: mutable-class-default
|
||||||
|
ignore = ["UP007", "RUF012"]
|
||||||
|
|
||||||
# Allow autofix for all enabled rules (when `--fix`) is provided.
|
# Allow autofix for all enabled rules (when `--fix`) is provided.
|
||||||
fixable = ["ALL"]
|
fixable = ["ALL"]
|
||||||
|
@ -120,7 +120,7 @@ class WalletTest(BaseModel):
|
|||||||
self.dict()
|
self.dict()
|
||||||
| {
|
| {
|
||||||
"description": f"""{self.description}:{mock.description or ""}""",
|
"description": f"""{self.description}:{mock.description or ""}""",
|
||||||
"mocks": self.mocks + [mock],
|
"mocks": [*self.mocks, mock],
|
||||||
"skip": self.skip or mock.skip,
|
"skip": self.skip or mock.skip,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import functools
|
||||||
import importlib
|
import importlib
|
||||||
import json
|
import json
|
||||||
|
import operator
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -24,7 +26,9 @@ def wallet_fixtures_from_json(path) -> List["WalletTest"]:
|
|||||||
fn_tests = _tests_for_function(funding_sources, fn_name, fn)
|
fn_tests = _tests_for_function(funding_sources, fn_name, fn)
|
||||||
_merge_dict_of_lists(tests, fn_tests)
|
_merge_dict_of_lists(tests, fn_tests)
|
||||||
|
|
||||||
all_tests = sum([tests[fs_name] for fs_name in tests], [])
|
all_tests: list["WalletTest"] = functools.reduce(
|
||||||
|
operator.iadd, [tests[fs_name] for fs_name in tests], []
|
||||||
|
)
|
||||||
return all_tests
|
return all_tests
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user