Skip to content

Commit

Permalink
Applied latest Black
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 21, 2024
1 parent 2e62282 commit 10dae61
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 37 deletions.
14 changes: 8 additions & 6 deletions datasette/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"')
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions datasette/utils/shutil_backport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions datasette/views/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,11 @@ async def extra_template():
display_value = markupsafe.Markup(
'<a class="blob-download" href="{}"{}>&lt;Binary:&nbsp;{:,}&nbsp;byte{}&gt;</a>'.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",
)
Expand Down
8 changes: 5 additions & 3 deletions datasette/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
38 changes: 22 additions & 16 deletions datasette/views/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
)
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions tests/plugins/my_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_internals_database.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_internals_datasette.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions tests/test_table_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 10dae61

Please sign in to comment.