From 6f03e2ad4cffd5ca91359785801acce24b652ff7 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Fri, 23 Feb 2024 20:04:31 -0500 Subject: [PATCH] fix linter issues --- relay/application.py | 18 ++++++++++-------- relay/database/connection.py | 2 +- relay/manage.py | 2 -- relay/misc.py | 8 ++++---- relay/template.py | 2 -- relay/views/api.py | 1 - 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/relay/application.py b/relay/application.py index fdf2503..05aa8cc 100644 --- a/relay/application.py +++ b/relay/application.py @@ -2,10 +2,7 @@ from __future__ import annotations import asyncio import multiprocessing -import os import signal -import subprocess -import sys import time import traceback import typing @@ -127,10 +124,15 @@ class Application(web.Application): if self["running"]: return - if not check_open_port(self.config.listen, self.config.port): - return logging.error(f'A server is already running on port {self.config.port}') + domain = self.config.domain + host = self.config.listen + port = self.config.port - logging.info(f'Starting webserver at {self.config.domain} ({self.config.listen}:{self.config.port})') + if not check_open_port(host, port): + logging.error(f'A server is already running on {host}:{port}') + return + + logging.info(f'Starting webserver at {domain} ({host}:{port})') asyncio.run(self.handle_run()) @@ -158,7 +160,7 @@ class Application(web.Application): self['cleanup_thread'] = CacheCleanupThread(self) self['cleanup_thread'].start() - for i in range(self.config.workers): + for _ in range(self.config.workers): worker = PushWorker(self['push_queue']) worker.start() @@ -181,7 +183,7 @@ class Application(web.Application): await site.stop() - for worker in self['workers']: + for worker in self['workers']: # pylint: disable=not-an-iterable worker.stop() self.set_signal_handler(False) diff --git a/relay/database/connection.py b/relay/database/connection.py index 16168b7..f2247aa 100644 --- a/relay/database/connection.py +++ b/relay/database/connection.py @@ -18,7 +18,7 @@ from .config import ( ) from .. import logger as logging -from ..misc import get_app +from ..misc import boolean, get_app if typing.TYPE_CHECKING: from collections.abc import Iterator diff --git a/relay/manage.py b/relay/manage.py index 8066d79..9343d3d 100644 --- a/relay/manage.py +++ b/relay/manage.py @@ -5,8 +5,6 @@ import asyncio import click import os import platform -import subprocess -import sys import typing from aputils.signer import Signer diff --git a/relay/misc.py b/relay/misc.py index 7060aa4..231eea5 100644 --- a/relay/misc.py +++ b/relay/misc.py @@ -88,11 +88,11 @@ def get_resource(path: str) -> Path: class JsonEncoder(json.JSONEncoder): - def default(self, obj: Any) -> str: - if isinstance(obj, datetime): - return obj.isoformat() + def default(self, o: Any) -> str: + if isinstance(o, datetime): + return o.isoformat() - return JSONEncoder.default(self, obj) + return json.JSONEncoder.default(self, o) class Message(ApMessage): diff --git a/relay/template.py b/relay/template.py index ecb556a..11687b5 100644 --- a/relay/template.py +++ b/relay/template.py @@ -5,8 +5,6 @@ import typing from hamlish_jinja.extension import HamlishExtension from jinja2 import Environment, FileSystemLoader -from pathlib import Path - from .database.config import THEMES from .misc import get_resource diff --git a/relay/views/api.py b/relay/views/api.py index 07a5c9a..a5c0fba 100644 --- a/relay/views/api.py +++ b/relay/views/api.py @@ -4,7 +4,6 @@ import typing from aiohttp import web from argon2.exceptions import VerifyMismatchError -from datetime import datetime, timezone from urllib.parse import urlparse from .base import View, register_route