From 270121083a38b4c99db92ee88e27cab8e40d4b83 Mon Sep 17 00:00:00 2001 From: jo <ljonas@riseup.net> Date: Thu, 16 Feb 2023 19:57:39 +0100 Subject: [PATCH] style: format code using black (pre-commit) --- funkwhale_network/cli.py | 1 - funkwhale_network/db.py | 30 +++++++++++++++--------------- funkwhale_network/output.py | 1 - tests/test_db.py | 1 - 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/funkwhale_network/cli.py b/funkwhale_network/cli.py index 9c62da5..0f93f00 100644 --- a/funkwhale_network/cli.py +++ b/funkwhale_network/cli.py @@ -153,7 +153,6 @@ async def crawl(domain, use_public, detail, passes, sort): aggregate = aggregate_crawl_results(results["results"]) if detail != NOOP: - click.echo("") click.echo("Info per domain") click.echo("===============") diff --git a/funkwhale_network/db.py b/funkwhale_network/db.py index 5fc301d..088844c 100644 --- a/funkwhale_network/db.py +++ b/funkwhale_network/db.py @@ -36,7 +36,7 @@ class DB: yield self.pool.cursor() async def create_domains_table(self): - with (await self.pool.cursor()) as cursor: + with await self.pool.cursor() as cursor: await cursor.execute( """ CREATE TABLE IF NOT EXISTS domains ( @@ -77,7 +77,7 @@ class DB: ALTER TABLE checks ADD COLUMN IF NOT EXISTS usage_downloads_total INTEGER NULL; SELECT create_hypertable('checks', 'time', if_not_exists => TRUE); """ - with (await self.pool.cursor()) as cursor: + with await self.pool.cursor() as cursor: await cursor.execute(sql) cursor.close() @@ -86,7 +86,7 @@ class DB: await create_handler() async def clear(self): - with (await self.pool.cursor()) as cursor: + with await self.pool.cursor() as cursor: for table, _ in self.TABLES: await cursor.execute(f"DROP TABLE IF EXISTS {table} CASCADE") @@ -98,8 +98,8 @@ class DB: WHERE private = %s AND domains.blocked = false ORDER BY domain, time DESC """ - with ( - await self.pool.cursor(cursor_factory=psycopg2.extras.RealDictCursor) + with await self.pool.cursor( + cursor_factory=psycopg2.extras.RealDictCursor ) as cursor: await cursor.execute(sql, [False]) return list(await cursor.fetchall()) @@ -165,16 +165,16 @@ class DB: return base_query.format(where_clause=""), [] async def get_all_domains(self): - with ( - await self.pool.cursor(cursor_factory=psycopg2.extras.RealDictCursor) + with await self.pool.cursor( + cursor_factory=psycopg2.extras.RealDictCursor ) as cursor: await cursor.execute("SELECT name FROM domains") domains = list(await cursor.fetchall()) return domains async def get_domains(self, **kwargs): - with ( - await self.pool.cursor(cursor_factory=psycopg2.extras.RealDictCursor) + with await self.pool.cursor( + cursor_factory=psycopg2.extras.RealDictCursor ) as cursor: filters = kwargs.copy() filters.setdefault("private", False) @@ -209,15 +209,15 @@ class DB: return True async def get_domain(self, name): - with ( - await self.pool.cursor(cursor_factory=psycopg2.extras.RealDictCursor) + with await self.pool.cursor( + cursor_factory=psycopg2.extras.RealDictCursor ) as cursor: await cursor.execute("SELECT * FROM domains WHERE name = %s", (name,)) return list(await cursor.fetchall())[0] async def save_check(self, data): - with ( - await self.pool.cursor(cursor_factory=psycopg2.extras.RealDictCursor) + with await self.pool.cursor( + cursor_factory=psycopg2.extras.RealDictCursor ) as cursor: node_name = data.pop("node_name", None) fields, values = [], [] @@ -245,8 +245,8 @@ class DB: return check async def create_domain(self, data): - with ( - await self.pool.cursor(cursor_factory=psycopg2.extras.RealDictCursor) + with await self.pool.cursor( + cursor_factory=psycopg2.extras.RealDictCursor ) as cursor: sql = "INSERT INTO domains (name) VALUES (%s) ON CONFLICT DO NOTHING RETURNING *" await cursor.execute(sql, [data["name"]]) diff --git a/funkwhale_network/output.py b/funkwhale_network/output.py index 8deecb4..f470def 100644 --- a/funkwhale_network/output.py +++ b/funkwhale_network/output.py @@ -51,7 +51,6 @@ def get_value(obj, config, truncate=30): def table(objects, fields, type, headers=True, format="simple", sort=None): - configs = {} if sort: diff --git a/tests/test_db.py b/tests/test_db.py index 8b8cb88..52362da 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -14,7 +14,6 @@ async def test_create_domain_ignore_duplicate(populated_db): async def test_db_create(): - async with DB() as db: try: await db.create() -- GitLab