88import json
99import os
1010import pathlib
11- import pdb
11+ import pdb # noqa: T100
1212import sys
1313import textwrap
1414from datetime import datetime , timezone
@@ -72,7 +72,7 @@ def _close_databases(ctx):
7272 for db in ctx .meta .get ("_databases_to_close" , []):
7373 try :
7474 db .close ()
75- except Exception :
75+ except sqlite3 . Error :
7676 pass
7777
7878
@@ -1840,9 +1840,7 @@ def rename_table(path, table, new_name, ignore, load_extension):
18401840 db .rename_table (table , new_name )
18411841 except sqlite3 .OperationalError as ex :
18421842 if not ignore :
1843- raise click .ClickException (
1844- f'Table "{ table } " could not be renamed. { ex !s} '
1845- )
1843+ raise click .ClickException (f'Table "{ table } " could not be renamed. { ex !s} ' )
18461844
18471845
18481846@cli .command (name = "drop-table" )
@@ -2378,9 +2376,7 @@ def search(
23782376 table_columns = table_obj .columns_dict
23792377 for c in column :
23802378 if c not in table_columns :
2381- raise click .ClickException (
2382- f"Table '{ dbtable } ' has no column '{ c } "
2383- )
2379+ raise click .ClickException (f"Table '{ dbtable } ' has no column '{ c } " )
23842380 sql = table_obj .search_sql (columns = column , order_by = order , limit = limit )
23852381 if show_sql :
23862382 click .echo (sql )
@@ -2953,7 +2949,7 @@ def yield_paths_and_relative_paths():
29532949 with progressbar (paths_and_relative_paths , silent = silent ) as bar :
29542950
29552951 def to_insert ():
2956- for path , relative_path in bar :
2952+ for file_path , relative_path in bar :
29572953 row = {}
29582954 # content_text is special case as it considers 'encoding'
29592955
@@ -2965,27 +2961,29 @@ def _content_text(p):
29652961 raise UnicodeDecodeErrorForPath (e , resolved )
29662962
29672963 lookups = dict (FILE_COLUMNS , content_text = _content_text )
2968- if path == "-" :
2964+ if file_path == "-" :
29692965 stdin_data = sys .stdin .buffer .read ()
29702966 # We only support a subset of columns for this case
29712967 lookups = {
29722968 "name" : lambda p : name or "-" ,
29732969 "path" : lambda p : name or "-" ,
2974- "content" : lambda p : stdin_data ,
2975- "content_text" : lambda p : stdin_data .decode (
2970+ "content" : lambda p , data = stdin_data : data ,
2971+ "content_text" : lambda p , data = stdin_data : data .decode (
29762972 encoding or "utf-8"
29772973 ),
2978- "sha256" : lambda p : hashlib .sha256 (stdin_data ).hexdigest (),
2979- "md5" : lambda p : hashlib .md5 (stdin_data ).hexdigest (),
2980- "size" : lambda p : len (stdin_data ),
2974+ "sha256" : lambda p , data = stdin_data : hashlib .sha256 (
2975+ data
2976+ ).hexdigest (),
2977+ "md5" : lambda p , data = stdin_data : hashlib .md5 (data ).hexdigest (),
2978+ "size" : lambda p , data = stdin_data : len (data ),
29812979 }
29822980 for coldef in column :
29832981 if ":" in coldef :
29842982 colname , coltype = coldef .rsplit (":" , 1 )
29852983 else :
29862984 colname , coltype = coldef , coldef
29872985 try :
2988- value = lookups [coltype ](path )
2986+ value = lookups [coltype ](file_path )
29892987 row [colname ] = value
29902988 except KeyError :
29912989 raise click .ClickException (
@@ -3314,7 +3312,7 @@ def preview(v):
33143312 def wrapped_fn (value ):
33153313 try :
33163314 return fn_ (value )
3317- except Exception as ex :
3315+ except Exception as ex : # noqa: BLE001
33183316 print ("\n Exception raised, dropping into pdb...:" , ex )
33193317 pdb .post_mortem (ex .__traceback__ )
33203318 sys .exit (1 )
@@ -3477,7 +3475,7 @@ def _load_migration_sets(files):
34773475 "__file__" : str (filepath ),
34783476 "__name__" : "__sqlite_utils_migration__" ,
34793477 }
3480- exec (code , namespace )
3478+ exec (code , namespace ) # noqa: S102
34813479 migration_sets .extend (
34823480 obj for obj in namespace .values () if _compatible_migration_set (obj )
34833481 )
@@ -3587,9 +3585,7 @@ def migrate(db_path, migrations, stop_before, list_, verbose):
35873585 names = {m .name for m in migration_set .pending (db )}
35883586 names .update (m .name for m in migration_set .applied (db ))
35893587 known_names .update (names )
3590- known_names .update (
3591- f"{ migration_set .name } :{ name } " for name in names
3592- )
3588+ known_names .update (f"{ migration_set .name } :{ name } " for name in names )
35933589 unknown = [value for value in stop_before if value not in known_names ]
35943590 if unknown :
35953591 raise click .ClickException (
@@ -3766,7 +3762,7 @@ def _register_functions(db, functions):
37663762 sqlite3 .enable_callback_tracebacks (True )
37673763 globals = {}
37683764 try :
3769- exec (functions , globals )
3765+ exec (functions , globals ) # noqa: S102
37703766 except SyntaxError as ex :
37713767 raise click .ClickException (f"Error in functions definition: { ex } " )
37723768 # Register all callables in the locals dict:
@@ -3792,7 +3788,7 @@ def _rows_from_code(code):
37923788 raise click .ClickException (f"File not found: { code } " )
37933789 namespace = {}
37943790 try :
3795- exec (code , namespace )
3791+ exec (code , namespace ) # noqa: S102
37963792 except SyntaxError as ex :
37973793 raise click .ClickException (f"Error in --code: { ex } " )
37983794 rows = namespace .get ("rows" )
0 commit comments