Skip to content

Commit 552118a

Browse files
authored
Ruff format --line-length=88 (#82)
* ruff format --line-length=88 * ruff --select=ISC -- flake8-implicit-str-concat
1 parent f03e3c1 commit 552118a

12 files changed

+106
-74
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ jobs:
2727
run: |
2828
python -m pylint -E partitionmanager
2929
30-
- name: Checking format with Ruff
31-
run: |
32-
python -m ruff format .
33-
3430
- name: Lint Python code with Ruff
3531
run: |
3632
python -m ruff --output-format=github
3733
34+
- name: Checking format with Ruff
35+
run: |
36+
python -m ruff format --check .
37+
3838
- name: Checking pyproject
3939
run: |
4040
validate-pyproject pyproject.toml

.pre-commit-config.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ repos:
99
- id: requirements-txt-fixer
1010
- id: trailing-whitespace
1111

12+
- repo: https://github.com/codespell-project/codespell
13+
rev: v2.2.6
14+
hooks:
15+
- id: codespell
16+
additional_dependencies:
17+
- tomli
18+
1219
- repo: https://github.com/astral-sh/ruff-pre-commit
13-
rev: v0.2.2
20+
rev: v0.3.0
1421
hooks:
1522
- id: ruff
16-
# - id: ruff-format
23+
- id: ruff-format
1724

1825
- repo: https://github.com/PyCQA/pylint
1926
rev: v3.1.0

partitionmanager/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ def do_stats(conf, metrics=partitionmanager.stats.PrometheusMetrics()):
407407
)
408408
metrics.describe(
409409
"age_of_retained_partitions",
410-
help_text="The age in seconds of the first partition for the table, indicating the "
411-
"retention of data in the table.",
410+
help_text="The age in seconds of the first partition for the table, "
411+
"indicating the retention of data in the table.",
412412
type_name="gauge",
413413
)
414414
metrics.describe(

partitionmanager/cli_test.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ def test_partition_period_seven_days(self):
225225
[
226226
"INFO:partition:Evaluating Table partitioned_last_week "
227227
"(duration=7 days, 0:00:00)",
228-
"DEBUG:partition:Table partitioned_last_week has no pending SQL updates.",
228+
"DEBUG:partition:Table partitioned_last_week has no pending SQL updates.", # noqa: E501
229229
"INFO:partition:Evaluating Table partitioned_yesterday "
230230
"(duration=7 days, 0:00:00)",
231-
"DEBUG:partition:Table partitioned_yesterday has no pending SQL updates.",
231+
"DEBUG:partition:Table partitioned_yesterday has no pending SQL updates.", # noqa: E501
232232
]
233233
),
234234
)
@@ -494,26 +494,26 @@ def test_migrate_cmd_in(self):
494494
"partitioned_yesterday": [
495495
"DROP TABLE IF EXISTS partitioned_yesterday_new_20210421;",
496496
"CREATE TABLE partitioned_yesterday_new_20210421 "
497-
+ "LIKE partitioned_yesterday;",
497+
"LIKE partitioned_yesterday;",
498498
"ALTER TABLE partitioned_yesterday_new_20210421 "
499-
+ "REMOVE PARTITIONING;",
499+
"REMOVE PARTITIONING;",
500500
"ALTER TABLE partitioned_yesterday_new_20210421 "
501-
+ "PARTITION BY RANGE (id) (",
501+
"PARTITION BY RANGE (id) (",
502502
"\tPARTITION p_assumed VALUES LESS THAN MAXVALUE",
503503
");",
504504
"ALTER TABLE `partitioned_yesterday_new_20210421` WAIT 6 "
505-
+ "REORGANIZE PARTITION `p_assumed` INTO (PARTITION "
506-
+ "`p_20210421` VALUES LESS THAN (150), PARTITION "
507-
+ "`p_20210521` VALUES LESS THAN (300), PARTITION "
508-
+ "`p_20210620` VALUES LESS THAN MAXVALUE);",
505+
"REORGANIZE PARTITION `p_assumed` INTO (PARTITION "
506+
"`p_20210421` VALUES LESS THAN (150), PARTITION "
507+
"`p_20210521` VALUES LESS THAN (300), PARTITION "
508+
"`p_20210620` VALUES LESS THAN MAXVALUE);",
509509
"CREATE OR REPLACE TRIGGER copy_inserts_from_"
510-
+ "partitioned_yesterday_to_partitioned_yesterday",
510+
"partitioned_yesterday_to_partitioned_yesterday",
511511
"\tAFTER INSERT ON partitioned_yesterday FOR EACH ROW",
512512
"\t\tINSERT INTO partitioned_yesterday_new_20210421 SET",
513513
"\t\t\t`id` = NEW.`id`,",
514514
"\t\t\t`serial` = NEW.`serial`;",
515515
"CREATE OR REPLACE TRIGGER copy_updates_from_"
516-
+ "partitioned_yesterday_to_partitioned_yesterday",
516+
"partitioned_yesterday_to_partitioned_yesterday",
517517
"\tAFTER UPDATE ON partitioned_yesterday FOR EACH ROW",
518518
"\t\tUPDATE partitioned_yesterday_new_20210421 SET",
519519
"\t\t\t`serial` = NEW.`serial`",
@@ -527,16 +527,16 @@ def test_migrate_cmd_in(self):
527527
"\tPARTITION p_assumed VALUES LESS THAN MAXVALUE",
528528
");",
529529
"ALTER TABLE `two_new_20210421` WAIT 6 REORGANIZE PARTITION "
530-
+ "`p_assumed` INTO (PARTITION `p_20210421` VALUES "
531-
+ "LESS THAN (150), PARTITION `p_20210521` VALUES LESS "
532-
+ "THAN (375), PARTITION `p_20210620` VALUES LESS THAN "
533-
+ "MAXVALUE);",
534-
"CREATE OR REPLACE TRIGGER copy_inserts_from_two_to_two_new_20210421",
530+
"`p_assumed` INTO (PARTITION `p_20210421` VALUES "
531+
"LESS THAN (150), PARTITION `p_20210521` VALUES LESS "
532+
"THAN (375), PARTITION `p_20210620` VALUES LESS THAN "
533+
"MAXVALUE);",
534+
"CREATE OR REPLACE TRIGGER copy_inserts_from_two_to_two_new_20210421", # noqa: E501
535535
"\tAFTER INSERT ON two FOR EACH ROW",
536536
"\t\tINSERT INTO two_new_20210421 SET",
537537
"\t\t\t`id` = NEW.`id`,",
538538
"\t\t\t`serial` = NEW.`serial`;",
539-
"CREATE OR REPLACE TRIGGER copy_updates_from_two_to_two_new_20210421",
539+
"CREATE OR REPLACE TRIGGER copy_updates_from_two_to_two_new_20210421", # noqa: E501
540540
"\tAFTER UPDATE ON two FOR EACH ROW",
541541
"\t\tUPDATE two_new_20210421 SET",
542542
"\t\t\t`serial` = NEW.`serial`",
@@ -583,22 +583,22 @@ def test_migrate_cmd_in_unpartitioned_with_override(self):
583583
"DROP TABLE IF EXISTS unpartitioned_new_20210421;",
584584
"CREATE TABLE unpartitioned_new_20210421 LIKE unpartitioned;",
585585
"ALTER TABLE unpartitioned_new_20210421 REMOVE PARTITIONING;",
586-
"ALTER TABLE unpartitioned_new_20210421 PARTITION BY RANGE (id) (",
586+
"ALTER TABLE unpartitioned_new_20210421 PARTITION BY RANGE (id) (", # noqa: E501
587587
"\tPARTITION p_assumed VALUES LESS THAN MAXVALUE",
588588
");",
589589
"ALTER TABLE `unpartitioned_new_20210421` WAIT 6 REORGANIZE "
590-
+ "PARTITION `p_assumed` INTO (PARTITION `p_20210421` "
591-
+ "VALUES LESS THAN (150), PARTITION `p_20210521` VALUES "
592-
+ "LESS THAN (300), PARTITION `p_20210620` VALUES LESS "
593-
+ "THAN MAXVALUE);",
590+
"PARTITION `p_assumed` INTO (PARTITION `p_20210421` "
591+
"VALUES LESS THAN (150), PARTITION `p_20210521` VALUES "
592+
"LESS THAN (300), PARTITION `p_20210620` VALUES LESS "
593+
"THAN MAXVALUE);",
594594
"CREATE OR REPLACE TRIGGER copy_inserts_from_"
595-
+ "unpartitioned_to_unpartitioned_new_20210421",
595+
"unpartitioned_to_unpartitioned_new_20210421",
596596
"\tAFTER INSERT ON unpartitioned FOR EACH ROW",
597597
"\t\tINSERT INTO unpartitioned_new_20210421 SET",
598598
"\t\t\t`id` = NEW.`id`,",
599599
"\t\t\t`serial` = NEW.`serial`;",
600600
"CREATE OR REPLACE TRIGGER copy_updates_from_"
601-
+ "unpartitioned_to_unpartitioned_new_20210421",
601+
"unpartitioned_to_unpartitioned_new_20210421",
602602
"\tAFTER UPDATE ON unpartitioned FOR EACH ROW",
603603
"\t\tUPDATE unpartitioned_new_20210421 SET",
604604
"\t\t\t`serial` = NEW.`serial`",

partitionmanager/dropper.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def _drop_statement(table, partition_list):
1818

1919
partitions = ",".join(map(lambda x: f"`{x.name}`", partition_list))
2020

21-
alter_cmd = f"ALTER TABLE `{table.name}` " f"DROP PARTITION IF EXISTS {partitions};"
21+
alter_cmd = f"ALTER TABLE `{table.name}` DROP PARTITION IF EXISTS {partitions};"
2222

2323
log.debug("Yielding %s", alter_cmd)
2424

@@ -92,7 +92,8 @@ def get_droppable_partitions(
9292
droppable.append(partition)
9393
except partitionmanager.types.NoExactTimeException:
9494
log.warning(
95-
"Couldn't determine exact times for %s.%s, it is probably droppable too.",
95+
"Couldn't determine exact times for %s.%s, it is probably droppable "
96+
"too.",
9697
table,
9798
partition,
9899
)

partitionmanager/dropper_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,6 @@ def test_get_droppable_partitions_no_exact_times(caplog):
230230
database, partitions, current_position, current_timestamp, table
231231
)
232232
assert (
233-
"Couldn't determine exact times for Table burgers.1: (100), it is probably droppable too."
234-
in caplog.messages
233+
"Couldn't determine exact times for Table burgers.1: (100), it is probably "
234+
"droppable too." in caplog.messages
235235
)

partitionmanager/migrate.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ def _generate_sql_copy_commands(
171171
yield f"DROP TABLE IF EXISTS {new_table.name};"
172172
yield f"CREATE TABLE {new_table.name} LIKE {existing_table.name};"
173173
yield f"ALTER TABLE {new_table.name} REMOVE PARTITIONING;"
174-
yield f"ALTER TABLE {new_table.name} PARTITION BY {range_cols_string} ({range_id_string}) ("
174+
yield (
175+
f"ALTER TABLE {new_table.name} PARTITION BY {range_cols_string} "
176+
f"({range_id_string}) ("
177+
)
175178
yield f"\tPARTITION {max_val_part.name} VALUES LESS THAN {max_val_string}"
176179
yield ");"
177180

@@ -275,8 +278,9 @@ def calculate_sql_alters_from_state_info(conf, in_fp):
275278
raise Exception("Unexpected part?")
276279

277280
log.info(
278-
f"{table}, {time_delta:0.1f} hours, {ordered_prior_pos} - {ordered_current_pos}, "
279-
f"{delta_positions} pos_change, {rate_of_change}/hour"
281+
f"{table}, {time_delta:0.1f} hours, {ordered_prior_pos} - "
282+
f"{ordered_current_pos}, {delta_positions} pos_change, "
283+
f"{rate_of_change}/hour"
280284
)
281285

282286
part_duration = conf.partition_period

partitionmanager/migrate_test.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,16 @@ def test_read_state_info(self):
131131
"ALTER TABLE test_new_20210303 PARTITION BY RANGE (id) (",
132132
"\tPARTITION p_start VALUES LESS THAN MAXVALUE",
133133
");",
134-
"ALTER TABLE `test_new_20210303` WAIT 6 REORGANIZE PARTITION `p_start` "
135-
+ "INTO (PARTITION `p_20210303` VALUES LESS THAN (156), "
136-
+ "PARTITION `p_20210402` VALUES LESS THAN (2406), PARTITION "
137-
+ "`p_20210502` VALUES LESS THAN MAXVALUE);",
138-
"CREATE OR REPLACE TRIGGER copy_inserts_from_test_to_test_new_20210303",
134+
"ALTER TABLE `test_new_20210303` WAIT 6 REORGANIZE PARTITION `p_start` " # noqa: E501
135+
"INTO (PARTITION `p_20210303` VALUES LESS THAN (156), "
136+
"PARTITION `p_20210402` VALUES LESS THAN (2406), PARTITION "
137+
"`p_20210502` VALUES LESS THAN MAXVALUE);",
138+
"CREATE OR REPLACE TRIGGER copy_inserts_from_test_to_test_new_20210303", # noqa: E501
139139
"\tAFTER INSERT ON test FOR EACH ROW",
140140
"\t\tINSERT INTO test_new_20210303 SET",
141141
"\t\t\t`id` = NEW.`id`,",
142142
"\t\t\t`serial` = NEW.`serial`;",
143-
"CREATE OR REPLACE TRIGGER copy_updates_from_test_to_test_new_20210303",
143+
"CREATE OR REPLACE TRIGGER copy_updates_from_test_to_test_new_20210303", # noqa: E501
144144
"\tAFTER UPDATE ON test FOR EACH ROW",
145145
"\t\tUPDATE test_new_20210303 SET",
146146
"\t\t\t`serial` = NEW.`serial`",
@@ -184,16 +184,16 @@ def test_read_state_info_map_table(self):
184184
"CREATE TABLE map_table_new_20210303 LIKE map_table;",
185185
"ALTER TABLE map_table_new_20210303 REMOVE PARTITIONING;",
186186
"ALTER TABLE map_table_new_20210303 PARTITION BY RANGE "
187-
+ "COLUMNS (orderID, authzID) (",
187+
"COLUMNS (orderID, authzID) (",
188188
"\tPARTITION p_assumed VALUES LESS THAN (MAXVALUE, MAXVALUE)",
189189
");",
190190
"ALTER TABLE `map_table_new_20210303` WAIT 6 REORGANIZE PARTITION "
191-
+ "`p_assumed` INTO (PARTITION `p_20210303` VALUES LESS THAN "
192-
+ "(11, 22), PARTITION `p_20210402` VALUES LESS THAN "
193-
+ "(41, 82), PARTITION `p_20210502` VALUES LESS THAN "
194-
+ "(MAXVALUE, MAXVALUE));",
191+
"`p_assumed` INTO (PARTITION `p_20210303` VALUES LESS THAN "
192+
"(11, 22), PARTITION `p_20210402` VALUES LESS THAN "
193+
"(41, 82), PARTITION `p_20210502` VALUES LESS THAN "
194+
"(MAXVALUE, MAXVALUE));",
195195
"CREATE OR REPLACE TRIGGER copy_inserts_from_map_table_"
196-
+ "to_map_table_new_20210303",
196+
"to_map_table_new_20210303",
197197
"\tAFTER INSERT ON map_table FOR EACH ROW",
198198
"\t\tINSERT INTO map_table_new_20210303 SET",
199199
"\t\t\t`authzID` = NEW.`authzID`,",

partitionmanager/stats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def get_statistics(partitions, current_timestamp, table):
6868
if not partitionmanager.types.is_partition_type(p):
6969
log.warning(
7070
f"{table} get_statistics called with a partition list "
71-
+ f"that included a non-Partition entry: {p}"
71+
f"that included a non-Partition entry: {p}"
7272
)
7373
raise partitionmanager.types.UnexpectedPartitionException(p)
7474

@@ -78,7 +78,7 @@ def get_statistics(partitions, current_timestamp, table):
7878
if not isinstance(tail_part, partitionmanager.types.MaxValuePartition):
7979
log.warning(
8080
f"{table} get_statistics called with a partition list tail "
81-
+ f"that wasn't a MaxValuePartition: {tail_part}"
81+
f"that wasn't a MaxValuePartition: {tail_part}"
8282
)
8383
raise partitionmanager.types.UnexpectedPartitionException(tail_part)
8484

partitionmanager/table_append_partition.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get_table_compatibility_problems(database, table):
2424

2525
sql_cmd = (
2626
"SELECT CREATE_OPTIONS FROM INFORMATION_SCHEMA.TABLES "
27-
+ f"WHERE TABLE_SCHEMA='{db_name}' and TABLE_NAME='{table.name}';"
27+
f"WHERE TABLE_SCHEMA='{db_name}' and TABLE_NAME='{table.name}';"
2828
).strip()
2929
return _get_table_information_schema_problems(database.run(sql_cmd), table.name)
3030

@@ -84,8 +84,8 @@ def _parse_partition_map(rows):
8484
The "range_cols" is the ordered list of what columns are used as the
8585
range identifiers for the partitions.
8686
87-
The "partitions" is a list of the Partition objects representing each
88-
defined partition. There will be at least one partitionmanager.types.MaxValuePartition.
87+
The "partitions" is a list of the Partition objects representing each defined
88+
partition. There will be at least one partitionmanager.types.MaxValuePartition.
8989
"""
9090
log = logging.getLogger("parse_partition_map")
9191

@@ -128,7 +128,8 @@ def _parse_partition_map(rows):
128128

129129
if len(part_vals) != len(range_cols):
130130
log.error(
131-
f"Partition columns {part_vals} don't match the partition range {range_cols}"
131+
f"Partition columns {part_vals} don't match the partition range "
132+
f"{range_cols}"
132133
)
133134
raise partitionmanager.types.MismatchedIdException(
134135
"Partition columns mismatch"
@@ -241,7 +242,8 @@ def _get_position_increase_per_day(p1, p2):
241242
return list()
242243
if p1.timestamp() >= p2.timestamp():
243244
log.warning(
244-
f"Skipping rate of change between p1 {p1} and p2 {p2} as they are out-of-order"
245+
f"Skipping rate of change between p1 {p1} and p2 {p2} as they are "
246+
"out-of-order"
245247
)
246248
return list()
247249

@@ -597,7 +599,7 @@ def _plan_partition_changes(
597599
continue
598600

599601
log.debug(
600-
f"{partition} has a conflict for its timestamp, increasing by 1 day."
602+
f"{partition} has a conflict for its timestamp, increasing by 1 day"
601603
)
602604
partition.set_timestamp(partition.timestamp() + timedelta(days=1))
603605
conflict_found = True
@@ -626,9 +628,12 @@ def _should_run_changes(table, altered_partitions):
626628
log.debug(f"{p} is new")
627629
return True
628630

629-
if isinstance(p, partitionmanager.types.ChangePlannedPartition) and p.important():
630-
log.debug(f"{p} is marked important")
631-
return True
631+
if (
632+
isinstance(p, partitionmanager.types.ChangePlannedPartition)
633+
and p.important()
634+
):
635+
log.debug(f"{p} is marked important")
636+
return True
632637
return False
633638

634639

@@ -693,8 +698,8 @@ def generate_sql_reorganize_partition_commands(table, changes):
693698
partition_update = ", ".join(partition_strings)
694699

695700
alter_cmd = (
696-
f"ALTER TABLE `{table.name}` WAIT 6 "
697-
f"REORGANIZE PARTITION `{modified_partition.old.name}` INTO ({partition_update});"
701+
f"ALTER TABLE `{table.name}` WAIT 6 REORGANIZE "
702+
f"PARTITION `{modified_partition.old.name}` INTO ({partition_update});"
698703
)
699704

700705
log.debug(f"Yielding {alter_cmd}")

0 commit comments

Comments
 (0)