Skip to content

Commit cb33bec

Browse files
committed
Reformat with black 26.1.0
1 parent a946e80 commit cb33bec

12 files changed

Lines changed: 48 additions & 114 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

@@ -2919,17 +2918,15 @@ def _analyze(db, tables, columns, save, common_limit=10, no_most=False, no_least
29192918
)
29202919
details = (
29212920
(
2922-
textwrap.dedent(
2923-
"""
2921+
textwrap.dedent("""
29242922
{table}.{column}: ({i}/{total})
29252923
29262924
Total rows: {total_rows}
29272925
Null rows: {num_null}
29282926
Blank rows: {num_blank}
29292927
29302928
Distinct values: {num_distinct}{most_common_rendered}{least_common_rendered}
2931-
"""
2932-
)
2929+
""")
29332930
.strip()
29342931
.format(
29352932
i=i + 1,
@@ -2976,8 +2973,7 @@ def uninstall(packages, yes):
29762973

29772974

29782975
def _generate_convert_help():
2979-
help = textwrap.dedent(
2980-
"""
2976+
help = textwrap.dedent("""
29812977
Convert columns using Python code you supply. For example:
29822978
29832979
\b
@@ -2990,8 +2986,7 @@ def _generate_convert_help():
29902986
Use "-" for CODE to read Python code from standard input.
29912987
29922988
The following common operations are available as recipe functions:
2993-
"""
2994-
).strip()
2989+
""").strip()
29952990
recipe_names = [
29962991
n
29972992
for n in dir(recipes)
@@ -3005,15 +3000,13 @@ def _generate_convert_help():
30053000
name, str(inspect.signature(fn)), textwrap.dedent(fn.__doc__.rstrip())
30063001
)
30073002
help += "\n\n"
3008-
help += textwrap.dedent(
3009-
"""
3003+
help += textwrap.dedent("""
30103004
You can use these recipes like so:
30113005
30123006
\b
30133007
sqlite-utils convert my.db mytable mycolumn \\
30143008
'r.jsonsplit(value, delimiter=":")'
3015-
"""
3016-
).strip()
3009+
""").strip()
30173010
return help
30183011

30193012

sqlite_utils/db.py

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,12 +2348,10 @@ def create_index(
23482348
"{}_{}".format(index_name, suffix) if suffix else index_name
23492349
)
23502350
sql = (
2351-
textwrap.dedent(
2352-
"""
2351+
textwrap.dedent("""
23532352
CREATE {unique}INDEX {if_not_exists}{index_name}
23542353
ON {table_name} ({columns});
2355-
"""
2356-
)
2354+
""")
23572355
.strip()
23582356
.format(
23592357
index_name=quote_identifier(created_index_name),
@@ -2548,8 +2546,7 @@ def enable_counts(self) -> None:
25482546
See :ref:`python_api_cached_table_counts` for details.
25492547
"""
25502548
sql = (
2551-
textwrap.dedent(
2552-
"""
2549+
textwrap.dedent("""
25532550
{create_counts_table}
25542551
CREATE TRIGGER IF NOT EXISTS {trigger_insert} AFTER INSERT ON {table}
25552552
BEGIN
@@ -2574,8 +2571,7 @@ def enable_counts(self) -> None:
25742571
);
25752572
END;
25762573
INSERT OR REPLACE INTO _counts VALUES ({table_quoted}, (select count(*) from {table}));
2577-
"""
2578-
)
2574+
""")
25792575
.strip()
25802576
.format(
25812577
create_counts_table=_COUNTS_TABLE_CREATE_SQL.format(
@@ -2627,14 +2623,12 @@ def enable_fts(
26272623
:param replace: Should any existing FTS index for this table be replaced by the new one?
26282624
"""
26292625
create_fts_sql = (
2630-
textwrap.dedent(
2631-
"""
2626+
textwrap.dedent("""
26322627
CREATE VIRTUAL TABLE {table_fts} USING {fts_version} (
26332628
{columns},{tokenize}
26342629
content={table}
26352630
)
2636-
"""
2637-
)
2631+
""")
26382632
.strip()
26392633
.format(
26402634
table=quote_identifier(self.name),
@@ -2672,8 +2666,7 @@ def enable_fts(
26722666
table = quote_identifier(self.name)
26732667
table_fts = quote_identifier(self.name + "_fts")
26742668
triggers = (
2675-
textwrap.dedent(
2676-
"""
2669+
textwrap.dedent("""
26772670
CREATE TRIGGER {table_ai} AFTER INSERT ON {table} BEGIN
26782671
INSERT INTO {table_fts} (rowid, {columns}) VALUES (new.rowid, {new_cols});
26792672
END;
@@ -2684,8 +2677,7 @@ def enable_fts(
26842677
INSERT INTO {table_fts} ({table_fts}, rowid, {columns}) VALUES('delete', old.rowid, {old_cols});
26852678
INSERT INTO {table_fts} (rowid, {columns}) VALUES (new.rowid, {new_cols});
26862679
END;
2687-
"""
2688-
)
2680+
""")
26892681
.strip()
26902682
.format(
26912683
table=table,
@@ -2710,12 +2702,10 @@ def populate_fts(self, columns: Iterable[str]) -> "Table":
27102702
"""
27112703
columns_quoted = ", ".join(quote_identifier(c) for c in columns)
27122704
sql = (
2713-
textwrap.dedent(
2714-
"""
2705+
textwrap.dedent("""
27152706
INSERT INTO {table_fts} (rowid, {columns})
27162707
SELECT rowid, {columns} FROM {table};
2717-
"""
2718-
)
2708+
""")
27192709
.strip()
27202710
.format(
27212711
table=quote_identifier(self.name),
@@ -2732,17 +2722,11 @@ def disable_fts(self) -> "Table":
27322722
if fts_table:
27332723
self.db[fts_table].drop()
27342724
# Now delete the triggers that related to that table
2735-
sql = (
2736-
textwrap.dedent(
2737-
"""
2725+
sql = textwrap.dedent("""
27382726
SELECT name FROM sqlite_master
27392727
WHERE type = 'trigger'
27402728
AND (sql LIKE '% INSERT INTO [{}]%' OR sql LIKE '% INSERT INTO "{}"%')
2741-
"""
2742-
)
2743-
.strip()
2744-
.format(fts_table, fts_table)
2745-
)
2729+
""").strip().format(fts_table, fts_table)
27462730
trigger_names = []
27472731
for row in self.db.execute(sql).fetchall():
27482732
trigger_names.append(row[0])
@@ -2768,8 +2752,7 @@ def rebuild_fts(self) -> "Table":
27682752

27692753
def detect_fts(self) -> Optional[str]:
27702754
"Detect if table has a corresponding FTS virtual table and return it"
2771-
sql = textwrap.dedent(
2772-
"""
2755+
sql = textwrap.dedent("""
27732756
SELECT name FROM sqlite_master
27742757
WHERE rootpage = 0
27752758
AND (
@@ -2780,8 +2763,7 @@ def detect_fts(self) -> Optional[str]:
27802763
AND sql LIKE '%VIRTUAL TABLE%USING FTS%'
27812764
)
27822765
)
2783-
"""
2784-
).strip()
2766+
""").strip()
27852767
args = {
27862768
"like": '%VIRTUAL TABLE%USING FTS%content="{}"%'.format(self.name),
27872769
"like2": '%VIRTUAL TABLE%USING FTS%content="{}"%'.format(self.name),
@@ -2797,13 +2779,9 @@ def optimize(self) -> "Table":
27972779
"Run the ``optimize`` operation against the associated full-text search index table."
27982780
fts_table = self.detect_fts()
27992781
if fts_table is not None:
2800-
self.db.execute(
2801-
"""
2782+
self.db.execute("""
28022783
INSERT INTO {table} ({table}) VALUES ("optimize");
2803-
""".strip().format(
2804-
table=quote_identifier(fts_table)
2805-
)
2806-
)
2784+
""".strip().format(table=quote_identifier(fts_table)))
28072785
return self
28082786

28092787
def search_sql(
@@ -2841,8 +2819,7 @@ def search_sql(
28412819
)
28422820
fts_table_quoted = quote_identifier(fts_table)
28432821
virtual_table_using = self.db.table(fts_table).virtual_table_using
2844-
sql = textwrap.dedent(
2845-
"""
2822+
sql = textwrap.dedent("""
28462823
with {original} as (
28472824
select
28482825
rowid,
@@ -2859,8 +2836,7 @@ def search_sql(
28592836
order by
28602837
{order_by}
28612838
{limit_offset}
2862-
"""
2863-
).strip()
2839+
""").strip()
28642840
if virtual_table_using == "FTS5":
28652841
rank_implementation = "{}.rank".format(fts_table_quoted)
28662842
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"]
@@ -2038,12 +2035,10 @@ def test_search_quote(tmpdir):
20382035
def test_indexes(tmpdir):
20392036
db_path = str(tmpdir / "test.db")
20402037
db = Database(db_path)
2041-
db.conn.executescript(
2042-
"""
2038+
db.conn.executescript("""
20432039
create table Gosh (c1 text, c2 text, c3 text);
20442040
create index Gosh_idx on Gosh(c2, c3 desc);
2045-
"""
2046-
)
2041+
""")
20472042
result = CliRunner().invoke(
20482043
cli.cli,
20492044
["indexes", str(db_path)],
@@ -2134,16 +2129,12 @@ def test_triggers(tmpdir, extra_args, expected):
21342129
pk="id",
21352130
)
21362131
db["counter"].insert({"count": 1})
2137-
db.conn.execute(
2138-
textwrap.dedent(
2139-
"""
2132+
db.conn.execute(textwrap.dedent("""
21402133
CREATE TRIGGER blah AFTER INSERT ON articles
21412134
BEGIN
21422135
UPDATE counter SET count = count + 1;
21432136
END
2144-
"""
2145-
)
2146-
)
2137+
"""))
21472138
args = ["triggers", db_path]
21482139
if extra_args:
21492140
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)