From 10dae612131734f35b9124b07295f32d94818121 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 21 Jun 2024 16:28:25 -0700 Subject: [PATCH] Applied latest Black --- datasette/filters.py | 14 ++++++----- datasette/utils/shutil_backport.py | 1 + datasette/views/database.py | 8 ++++--- datasette/views/index.py | 8 ++++--- datasette/views/table.py | 38 +++++++++++++++++------------- tests/plugins/my_plugin.py | 6 ++--- tests/test_docs.py | 1 + tests/test_internals_database.py | 1 + tests/test_internals_datasette.py | 1 + tests/test_permissions.py | 8 ++++--- tests/test_table_api.py | 8 ++++--- tests/test_utils.py | 1 + 12 files changed, 58 insertions(+), 37 deletions(-) diff --git a/datasette/filters.py b/datasette/filters.py index 5ea3488bd7..73eea85779 100644 --- a/datasette/filters.py +++ b/datasette/filters.py @@ -80,9 +80,9 @@ async def inner(): "{fts_pk} in (select rowid from {fts_table} where {fts_table} match {match_clause})".format( fts_table=escape_sqlite(fts_table), fts_pk=escape_sqlite(fts_pk), - match_clause=":search" - if search_mode_raw - else "escape_fts(:search)", + match_clause=( + ":search" if search_mode_raw else "escape_fts(:search)" + ), ) ) human_descriptions.append(f'search matches "{search}"') @@ -99,9 +99,11 @@ async def inner(): "rowid in (select rowid from {fts_table} where {search_col} match {match_clause})".format( fts_table=escape_sqlite(fts_table), search_col=escape_sqlite(search_col), - match_clause=":search_{}".format(i) - if search_mode_raw - else "escape_fts(:search_{})".format(i), + match_clause=( + ":search_{}".format(i) + if search_mode_raw + else "escape_fts(:search_{})".format(i) + ), ) ) human_descriptions.append( diff --git a/datasette/utils/shutil_backport.py b/datasette/utils/shutil_backport.py index dbe2240429..d1fd1bd7bc 100644 --- a/datasette/utils/shutil_backport.py +++ b/datasette/utils/shutil_backport.py @@ -4,6 +4,7 @@ This code is licensed under the Python License: https://github.com/python/cpython/blob/v3.8.3/LICENSE """ + import os from shutil import copy, copy2, copystat, Error diff --git a/datasette/views/database.py b/datasette/views/database.py index 964561a9e4..34d4d603e8 100644 --- a/datasette/views/database.py +++ b/datasette/views/database.py @@ -431,9 +431,11 @@ async def extra_template(): display_value = markupsafe.Markup( '<Binary: {:,} byte{}>'.format( blob_url, - ' title="{}"'.format(formatted) - if "bytes" not in formatted - else "", + ( + ' title="{}"'.format(formatted) + if "bytes" not in formatted + else "" + ), len(value), "" if len(value) == 1 else "s", ) diff --git a/datasette/views/index.py b/datasette/views/index.py index 1f366a49ce..0b86376f32 100644 --- a/datasette/views/index.py +++ b/datasette/views/index.py @@ -105,9 +105,11 @@ async def get(self, request): { "name": name, "hash": db.hash, - "color": db.hash[:6] - if db.hash - else hashlib.md5(name.encode("utf8")).hexdigest()[:6], + "color": ( + db.hash[:6] + if db.hash + else hashlib.md5(name.encode("utf8")).hexdigest()[:6] + ), "path": self.ds.urls.database(name), "tables_and_views_truncated": tables_and_views_truncated, "tables_and_views_more": (len(visible_tables) + len(views)) diff --git a/datasette/views/table.py b/datasette/views/table.py index 4c50664cbc..17d1b2485d 100644 --- a/datasette/views/table.py +++ b/datasette/views/table.py @@ -339,9 +339,11 @@ async def gather(*args): from_sql = "from {table_name} {where}".format( table_name=escape_sqlite(table_name), - where=("where {} ".format(" and ".join(where_clauses))) - if where_clauses - else "", + where=( + ("where {} ".format(" and ".join(where_clauses))) + if where_clauses + else "" + ), ) # Copy of params so we can mutate them later: from_sql_params = dict(**params) @@ -406,10 +408,12 @@ async def gather(*args): column=escape_sqlite(sort or sort_desc), op=">" if sort else "<", p=len(params), - extra_desc_only="" - if sort - else " or {column2} is null".format( - column2=escape_sqlite(sort or sort_desc) + extra_desc_only=( + "" + if sort + else " or {column2} is null".format( + column2=escape_sqlite(sort or sort_desc) + ) ), next_clauses=" and ".join(next_by_pk_clauses), ) @@ -772,9 +776,9 @@ async def table_actions(): "metadata": metadata, "view_definition": await db.get_view_definition(table_name), "table_definition": await db.get_table_definition(table_name), - "datasette_allow_facet": "true" - if self.ds.setting("allow_facet") - else "false", + "datasette_allow_facet": ( + "true" if self.ds.setting("allow_facet") else "false" + ), } d.update(extra_context_from_filters) return d @@ -933,9 +937,11 @@ async def display_columns_and_rows( path_from_row_pks(row, pks, not pks), column, ), - ' title="{}"'.format(formatted) - if "bytes" not in formatted - else "", + ( + ' title="{}"'.format(formatted) + if "bytes" not in formatted + else "" + ), len(value), "" if len(value) == 1 else "s", ) @@ -986,9 +992,9 @@ async def display_columns_and_rows( "column": column, "value": display_value, "raw": value, - "value_type": "none" - if value is None - else str(type(value).__name__), + "value_type": ( + "none" if value is None else str(type(value).__name__) + ), } ) cell_rows.append(Row(cells)) diff --git a/tests/plugins/my_plugin.py b/tests/plugins/my_plugin.py index 1a41de38ea..c19243951a 100644 --- a/tests/plugins/my_plugin.py +++ b/tests/plugins/my_plugin.py @@ -39,9 +39,9 @@ async def inner(): "database": database, "table": table, "view_name": view_name, - "request_path": request.path - if request is not None - else None, + "request_path": ( + request.path if request is not None else None + ), "added": ( await datasette.get_database().execute("select 3 * 5") ).first()[0], diff --git a/tests/test_docs.py b/tests/test_docs.py index cd5a6c13e0..50a912e553 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -1,6 +1,7 @@ """ Tests to ensure certain things are documented. """ + from click.testing import CliRunner from datasette import app, utils from datasette.cli import cli diff --git a/tests/test_internals_database.py b/tests/test_internals_database.py index 4e33beed4a..ad3f1d7af3 100644 --- a/tests/test_internals_database.py +++ b/tests/test_internals_database.py @@ -1,6 +1,7 @@ """ Tests for the datasette.database.Database class """ + from datasette.database import Database, Results, MultipleValues from datasette.utils.sqlite import sqlite3 from datasette.utils import Column diff --git a/tests/test_internals_datasette.py b/tests/test_internals_datasette.py index e2cb087010..39532ad097 100644 --- a/tests/test_internals_datasette.py +++ b/tests/test_internals_datasette.py @@ -1,6 +1,7 @@ """ Tests for the datasette.app.Datasette class """ + from datasette import Forbidden from datasette.app import Datasette, Database from itsdangerous import BadSignature diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 8812d0f7ba..62a92c7cf9 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -342,9 +342,11 @@ def test_permissions_debug(app_client): { "action": div.select_one(".check-action").text, # True = green tick, False = red cross, None = gray None - "result": None - if div.select(".check-result-no-opinion") - else bool(div.select(".check-result-true")), + "result": ( + None + if div.select(".check-result-no-opinion") + else bool(div.select(".check-result-true")) + ), "used_default": bool(div.select(".check-used-default")), } for div in check_divs diff --git a/tests/test_table_api.py b/tests/test_table_api.py index 8e913983f3..f6b3517308 100644 --- a/tests/test_table_api.py +++ b/tests/test_table_api.py @@ -279,9 +279,11 @@ def test_paginate_compound_keys_with_extra_filters(app_client): "_sort_desc=sortable_with_nulls", lambda row: ( 1 if row["sortable_with_nulls"] is None else 0, - -row["sortable_with_nulls"] - if row["sortable_with_nulls"] is not None - else 0, + ( + -row["sortable_with_nulls"] + if row["sortable_with_nulls"] is not None + else 0 + ), row["content"], ), "sorted by sortable_with_nulls descending", diff --git a/tests/test_utils.py b/tests/test_utils.py index 8b64f8653a..f6e7798163 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,6 +1,7 @@ """ Tests for various datasette helper functions. """ + from datasette.app import Datasette from datasette import utils from datasette.utils.asgi import Request