Skip to content

Commit cb143c0

Browse files
committed
Ran latest Black
1 parent b0b6adb commit cb143c0

12 files changed

Lines changed: 46 additions & 110 deletions

sqlite_utils/cli.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
TypeTracker,
4343
)
4444

45-
4645
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
4746

4847

@@ -2911,17 +2910,15 @@ def _analyze(db, tables, columns, save, common_limit=10, no_most=False, no_least
29112910
)
29122911
details = (
29132912
(
2914-
textwrap.dedent(
2915-
"""
2913+
textwrap.dedent("""
29162914
{table}.{column}: ({i}/{total})
29172915
29182916
Total rows: {total_rows}
29192917
Null rows: {num_null}
29202918
Blank rows: {num_blank}
29212919
29222920
Distinct values: {num_distinct}{most_common_rendered}{least_common_rendered}
2923-
"""
2924-
)
2921+
""")
29252922
.strip()
29262923
.format(
29272924
i=i + 1,
@@ -2968,8 +2965,7 @@ def uninstall(packages, yes):
29682965

29692966

29702967
def _generate_convert_help():
2971-
help = textwrap.dedent(
2972-
"""
2968+
help = textwrap.dedent("""
29732969
Convert columns using Python code you supply. For example:
29742970
29752971
\b
@@ -2982,8 +2978,7 @@ def _generate_convert_help():
29822978
Use "-" for CODE to read Python code from standard input.
29832979
29842980
The following common operations are available as recipe functions:
2985-
"""
2986-
).strip()
2981+
""").strip()
29872982
recipe_names = [
29882983
n
29892984
for n in dir(recipes)
@@ -2997,15 +2992,13 @@ def _generate_convert_help():
29972992
name, str(inspect.signature(fn)), textwrap.dedent(fn.__doc__.rstrip())
29982993
)
29992994
help += "\n\n"
3000-
help += textwrap.dedent(
3001-
"""
2995+
help += textwrap.dedent("""
30022996
You can use these recipes like so:
30032997
30042998
\b
30052999
sqlite-utils convert my.db mytable mycolumn \\
30063000
'r.jsonsplit(value, delimiter=":")'
3007-
"""
3008-
).strip()
3001+
""").strip()
30093002
return help
30103003

30113004

sqlite_utils/db.py

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,12 +2275,10 @@ def create_index(
22752275
"{}_{}".format(index_name, suffix) if suffix else index_name
22762276
)
22772277
sql = (
2278-
textwrap.dedent(
2279-
"""
2278+
textwrap.dedent("""
22802279
CREATE {unique}INDEX {if_not_exists}{index_name}
22812280
ON {table_name} ({columns});
2282-
"""
2283-
)
2281+
""")
22842282
.strip()
22852283
.format(
22862284
index_name=quote_identifier(created_index_name),
@@ -2475,8 +2473,7 @@ def enable_counts(self) -> None:
24752473
See :ref:`python_api_cached_table_counts` for details.
24762474
"""
24772475
sql = (
2478-
textwrap.dedent(
2479-
"""
2476+
textwrap.dedent("""
24802477
{create_counts_table}
24812478
CREATE TRIGGER IF NOT EXISTS {trigger_insert} AFTER INSERT ON {table}
24822479
BEGIN
@@ -2501,8 +2498,7 @@ def enable_counts(self) -> None:
25012498
);
25022499
END;
25032500
INSERT OR REPLACE INTO _counts VALUES ({table_quoted}, (select count(*) from {table}));
2504-
"""
2505-
)
2501+
""")
25062502
.strip()
25072503
.format(
25082504
create_counts_table=_COUNTS_TABLE_CREATE_SQL.format(
@@ -2554,14 +2550,12 @@ def enable_fts(
25542550
:param replace: Should any existing FTS index for this table be replaced by the new one?
25552551
"""
25562552
create_fts_sql = (
2557-
textwrap.dedent(
2558-
"""
2553+
textwrap.dedent("""
25592554
CREATE VIRTUAL TABLE {table_fts} USING {fts_version} (
25602555
{columns},{tokenize}
25612556
content={table}
25622557
)
2563-
"""
2564-
)
2558+
""")
25652559
.strip()
25662560
.format(
25672561
table=quote_identifier(self.name),
@@ -2599,8 +2593,7 @@ def enable_fts(
25992593
table = quote_identifier(self.name)
26002594
table_fts = quote_identifier(self.name + "_fts")
26012595
triggers = (
2602-
textwrap.dedent(
2603-
"""
2596+
textwrap.dedent("""
26042597
CREATE TRIGGER {table_ai} AFTER INSERT ON {table} BEGIN
26052598
INSERT INTO {table_fts} (rowid, {columns}) VALUES (new.rowid, {new_cols});
26062599
END;
@@ -2611,8 +2604,7 @@ def enable_fts(
26112604
INSERT INTO {table_fts} ({table_fts}, rowid, {columns}) VALUES('delete', old.rowid, {old_cols});
26122605
INSERT INTO {table_fts} (rowid, {columns}) VALUES (new.rowid, {new_cols});
26132606
END;
2614-
"""
2615-
)
2607+
""")
26162608
.strip()
26172609
.format(
26182610
table=table,
@@ -2637,12 +2629,10 @@ def populate_fts(self, columns: Iterable[str]) -> "Table":
26372629
"""
26382630
columns_quoted = ", ".join(quote_identifier(c) for c in columns)
26392631
sql = (
2640-
textwrap.dedent(
2641-
"""
2632+
textwrap.dedent("""
26422633
INSERT INTO {table_fts} (rowid, {columns})
26432634
SELECT rowid, {columns} FROM {table};
2644-
"""
2645-
)
2635+
""")
26462636
.strip()
26472637
.format(
26482638
table=quote_identifier(self.name),
@@ -2659,17 +2649,11 @@ def disable_fts(self) -> "Table":
26592649
if fts_table:
26602650
self.db[fts_table].drop()
26612651
# Now delete the triggers that related to that table
2662-
sql = (
2663-
textwrap.dedent(
2664-
"""
2652+
sql = textwrap.dedent("""
26652653
SELECT name FROM sqlite_master
26662654
WHERE type = 'trigger'
26672655
AND (sql LIKE '% INSERT INTO [{}]%' OR sql LIKE '% INSERT INTO "{}"%')
2668-
"""
2669-
)
2670-
.strip()
2671-
.format(fts_table, fts_table)
2672-
)
2656+
""").strip().format(fts_table, fts_table)
26732657
trigger_names = []
26742658
for row in self.db.execute(sql).fetchall():
26752659
trigger_names.append(row[0])
@@ -2695,8 +2679,7 @@ def rebuild_fts(self) -> "Table":
26952679

26962680
def detect_fts(self) -> Optional[str]:
26972681
"Detect if table has a corresponding FTS virtual table and return it"
2698-
sql = textwrap.dedent(
2699-
"""
2682+
sql = textwrap.dedent("""
27002683
SELECT name FROM sqlite_master
27012684
WHERE rootpage = 0
27022685
AND (
@@ -2707,8 +2690,7 @@ def detect_fts(self) -> Optional[str]:
27072690
AND sql LIKE '%VIRTUAL TABLE%USING FTS%'
27082691
)
27092692
)
2710-
"""
2711-
).strip()
2693+
""").strip()
27122694
args = {
27132695
"like": '%VIRTUAL TABLE%USING FTS%content="{}"%'.format(self.name),
27142696
"like2": '%VIRTUAL TABLE%USING FTS%content="{}"%'.format(self.name),
@@ -2724,13 +2706,9 @@ def optimize(self) -> "Table":
27242706
"Run the ``optimize`` operation against the associated full-text search index table."
27252707
fts_table = self.detect_fts()
27262708
if fts_table is not None:
2727-
self.db.execute(
2728-
"""
2709+
self.db.execute("""
27292710
INSERT INTO {table} ({table}) VALUES ("optimize");
2730-
""".strip().format(
2731-
table=quote_identifier(fts_table)
2732-
)
2733-
)
2711+
""".strip().format(table=quote_identifier(fts_table)))
27342712
return self
27352713

27362714
def search_sql(
@@ -2768,8 +2746,7 @@ def search_sql(
27682746
)
27692747
fts_table_quoted = quote_identifier(fts_table)
27702748
virtual_table_using = self.db.table(fts_table).virtual_table_using
2771-
sql = textwrap.dedent(
2772-
"""
2749+
sql = textwrap.dedent("""
27732750
with {original} as (
27742751
select
27752752
rowid,
@@ -2786,8 +2763,7 @@ def search_sql(
27862763
order by
27872764
{order_by}
27882765
{limit_offset}
2789-
"""
2790-
).strip()
2766+
""").strip()
27912767
if virtual_table_using == "FTS5":
27922768
rank_implementation = "{}.rank".format(fts_table_quoted)
27932769
else:

tests/conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ def fresh_db():
4242
@pytest.fixture
4343
def existing_db():
4444
database = Database(memory=True)
45-
database.executescript(
46-
"""
45+
database.executescript("""
4746
CREATE TABLE foo (text TEXT);
4847
INSERT INTO foo (text) values ("one");
4948
INSERT INTO foo (text) values ("two");
5049
INSERT INTO foo (text) values ("three");
51-
"""
52-
)
50+
""")
5351
return database
5452

5553

tests/test_analyze_tables.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,7 @@ def db_to_analyze_path(db_to_analyze, tmpdir):
143143

144144
def test_analyze_table(db_to_analyze_path):
145145
result = CliRunner().invoke(cli.cli, ["analyze-tables", db_to_analyze_path])
146-
assert (
147-
result.output.strip()
148-
== (
149-
"""
146+
assert result.output.strip() == ("""
150147
stuff.id: (1/3)
151148
152149
Total rows: 8
@@ -179,9 +176,7 @@ def test_analyze_table(db_to_analyze_path):
179176
180177
Most common:
181178
5: 5
182-
3: 4"""
183-
).strip()
184-
)
179+
3: 4""").strip()
185180

186181

187182
def test_analyze_table_save(db_to_analyze_path):

tests/test_cli.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,9 @@ def test_query_json_with_json_cols(db_path):
967967
result = CliRunner().invoke(
968968
cli.cli, [db_path, "select id, name, friends from dogs"]
969969
)
970-
assert (
971-
r"""
970+
assert r"""
972971
[{"id": 1, "name": "Cleo", "friends": "[{\"name\": \"Pancakes\"}, {\"name\": \"Bailey\"}]"}]
973-
""".strip()
974-
== result.output.strip()
975-
)
972+
""".strip() == result.output.strip()
976973
# With --json-cols:
977974
result = CliRunner().invoke(
978975
cli.cli, [db_path, "select id, name, friends from dogs", "--json-cols"]
@@ -1998,12 +1995,10 @@ def test_search_quote(tmpdir):
19981995
def test_indexes(tmpdir):
19991996
db_path = str(tmpdir / "test.db")
20001997
db = Database(db_path)
2001-
db.conn.executescript(
2002-
"""
1998+
db.conn.executescript("""
20031999
create table Gosh (c1 text, c2 text, c3 text);
20042000
create index Gosh_idx on Gosh(c2, c3 desc);
2005-
"""
2006-
)
2001+
""")
20072002
result = CliRunner().invoke(
20082003
cli.cli,
20092004
["indexes", str(db_path)],
@@ -2094,16 +2089,12 @@ def test_triggers(tmpdir, extra_args, expected):
20942089
pk="id",
20952090
)
20962091
db["counter"].insert({"count": 1})
2097-
db.conn.execute(
2098-
textwrap.dedent(
2099-
"""
2092+
db.conn.execute(textwrap.dedent("""
21002093
CREATE TRIGGER blah AFTER INSERT ON articles
21012094
BEGIN
21022095
UPDATE counter SET count = count + 1;
21032096
END
2104-
"""
2105-
)
2106-
)
2097+
"""))
21072098
args = ["triggers", db_path]
21082099
if extra_args:
21092100
args.extend(extra_args)

tests/test_cli_convert.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,16 +371,14 @@ def test_convert_multi_complex_column_types(fresh_db_and_path):
371371
],
372372
pk="id",
373373
)
374-
code = textwrap.dedent(
375-
"""
374+
code = textwrap.dedent("""
376375
if value == 1:
377376
return {"is_str": "", "is_float": 1.2, "is_int": None}
378377
elif value == 2:
379378
return {"is_float": 1, "is_int": 12}
380379
elif value == 3:
381380
return {"is_bytes": b"blah"}
382-
"""
383-
)
381+
""")
384382
result = CliRunner().invoke(
385383
cli.cli,
386384
[

tests/test_create.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import pytest
2121
import uuid
2222

23-
2423
try:
2524
import pandas as pd # type: ignore
2625
except ImportError:

tests/test_default_value.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22

3-
43
EXAMPLES = [
54
("TEXT DEFAULT 'foo'", "'foo'", "'foo'"),
65
("TEXT DEFAULT 'foo)'", "'foo)'", "'foo)'"),

tests/test_duplicate.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55

66
def test_duplicate(fresh_db):
77
# Create table using native Sqlite statement:
8-
fresh_db.execute(
9-
"""CREATE TABLE "table1" (
8+
fresh_db.execute("""CREATE TABLE "table1" (
109
"text_col" TEXT,
1110
"real_col" REAL,
1211
"int_col" INTEGER,
1312
"bool_col" INTEGER,
14-
"datetime_col" TEXT)"""
15-
)
13+
"datetime_col" TEXT)""")
1614
# Insert one row of mock data:
1715
dt = datetime.datetime.now()
1816
data = {

tests/test_extract.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,15 @@ def test_extract_rowid_table(fresh_db):
126126
' "common_name_latin_name_id" INTEGER REFERENCES "common_name_latin_name"("id")\n'
127127
")"
128128
)
129-
assert (
130-
fresh_db.execute(
131-
"""
129+
assert fresh_db.execute("""
132130
select
133131
tree.name,
134132
common_name_latin_name.common_name,
135133
common_name_latin_name.latin_name
136134
from tree
137135
join common_name_latin_name
138136
on tree.common_name_latin_name_id = common_name_latin_name.id
139-
"""
140-
).fetchall()
141-
== [("Tree 1", "Palm", "Arecaceae")]
142-
)
137+
""").fetchall() == [("Tree 1", "Palm", "Arecaceae")]
143138

144139

145140
def test_reuse_lookup_table(fresh_db):

0 commit comments

Comments
 (0)