Skip to content

Commit e4a834e

Browse files
committed
improve linting
1 parent e00b023 commit e4a834e

File tree

4 files changed

+110
-103
lines changed

4 files changed

+110
-103
lines changed

pyproject.toml

+16-17
Original file line numberDiff line numberDiff line change
@@ -91,29 +91,28 @@ analysis = [
9191
default-groups = ["dev", "docs", "analysis"]
9292

9393
[tool.ruff]
94-
# Same as Black.
95-
line-length = 88
96-
indent-width = 4
94+
line-length = 88 # Like Black, use 88 characters per line.
95+
indent-width = 4 # Like Black, use 4 spaces per indentation level.
9796
exclude = ["*.ipynb"]
9897

9998
[tool.ruff.lint]
10099
select = [
101-
"F", # Pyflakes
100+
"F", # Pyflakes
102101
"E", "W", # pycodestyle
103-
"I", # isort
104-
"N", # pep8-naming
105-
"Q", # flake8-quotes
106-
"UP", # pyupgrade
107-
"D", # pydocstyle
108-
"RUF", # Ruff-specific rules
109-
"B", # flake8-bugbear
110-
"T20", # print found
111-
"C90", # mccabe (complex structures)
112-
"SIM", # flake8-simplify
113-
"ANN", # flake8-annotations
114-
"TID", # flake8-tidy-imports
102+
"I", # isort
103+
"N", # pep8-naming
104+
"Q", # flake8-quotes
105+
"UP", # pyupgrade
106+
"D", # pydocstyle
107+
"RUF", # Ruff-specific rules
108+
"B", # flake8-bugbear
109+
"T20", # flake8-print
110+
"C90", # mccabe (complex structures)
111+
"SIM", # flake8-simplify
112+
"ANN", # flake8-annotations
113+
"TID", # flake8-tidy-imports
115114
]
116-
ignore = ["B008","B904"]
115+
ignore = [] # ignore specific rules here
117116

118117
# Allow fix for all enabled rules (when `--fix`) is provided.
119118
fixable = ["ALL"]

sqldeps/cli.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def extract(
347347

348348
except Exception as e:
349349
logger.error(f"Error extracting dependencies: {e}")
350-
raise typer.Exit(code=1)
350+
raise typer.Exit(code=1) from e
351351

352352

353353
# App subcommand
@@ -368,7 +368,7 @@ def app_main() -> None:
368368
subprocess.run([sys.executable, "-m", "streamlit", "run", str(app_module_path)])
369369
except Exception as e:
370370
logger.error(f"Failed to start web application: {e}")
371-
raise typer.Exit(code=1)
371+
raise typer.Exit(code=1) from e
372372

373373

374374
# Cache subcommands
@@ -385,7 +385,7 @@ def cache_clear() -> None:
385385
raise typer.Exit(code=1)
386386
except Exception as e:
387387
logger.error(f"Error clearing cache: {e}")
388-
raise typer.Exit(code=1)
388+
raise typer.Exit(code=1) from e
389389

390390

391391
if __name__ == "__main__":

sqldeps/llm_parsers/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def _process_response(self, response: str) -> SQLProfile:
351351
)
352352

353353
except json.JSONDecodeError as e:
354-
raise ValueError(f"Failed to decode JSON: {e}\nResponse: {response}")
354+
raise ValueError(f"Failed to decode JSON: {e}\nResponse: {response}") from e
355355

356356
@staticmethod
357357
def _normalize_extensions(extensions: set[str] | None) -> set[str]:

sqldeps/visualization.py

+90-82
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def get_layout(algorithm: str) -> dict:
180180
if node_type == "file":
181181
# File nodes
182182
full_path = G.nodes[node].get("full_path", node)
183-
connected_tables = [n for n in G.neighbors(node)]
183+
connected_tables = list(G.neighbors(node))
184184
hover_text = f"<b>File:</b> {full_path}<br>"
185185
hover_text += f"<b>Tables Used:</b> {len(connected_tables)}<br>"
186186
hover_text += "<br>".join(f"- {table}" for table in connected_tables)
@@ -190,7 +190,7 @@ def get_layout(algorithm: str) -> dict:
190190
table_count = len(connected_tables)
191191
max_tables = max(
192192
[
193-
len([n for n in G.neighbors(node)])
193+
len([list(G.neighbors(node))])
194194
for node in G.nodes()
195195
if G.nodes[node].get("type") == "file"
196196
],
@@ -281,7 +281,7 @@ def get_layout(algorithm: str) -> dict:
281281
edge_trace = go.Scatter(
282282
x=edge_x,
283283
y=edge_y,
284-
line=dict(width=1, color="rgba(150, 150, 150, 0.5)"),
284+
line={"width": 1, "color": "rgba(150, 150, 150, 0.5)"},
285285
hoverinfo="none",
286286
mode="lines",
287287
showlegend=False,
@@ -307,15 +307,15 @@ def get_layout(algorithm: str) -> dict:
307307
textposition="top center",
308308
hovertext=[data["hover_text"] for data in file_nodes.values()],
309309
hoverinfo="text",
310-
marker=dict(
311-
symbol=file_symbol,
312-
size=[data["size"] for data in file_nodes.values()],
313-
color=[data["color"] for data in file_nodes.values()]
310+
marker={
311+
"symbol": file_symbol,
312+
"size": [data["size"] for data in file_nodes.values()],
313+
"color": [data["color"] for data in file_nodes.values()]
314314
if color_gradient
315315
else "rgba(31, 119, 180, 0.8)",
316-
line=dict(width=1, color="rgba(31, 119, 180, 1)"),
317-
),
318-
textfont=dict(size=text_font_size),
316+
"line": {"width": 1, "color": "rgba(31, 119, 180, 1)"},
317+
},
318+
textfont={"size": text_font_size},
319319
)
320320
traces.append(file_trace)
321321

@@ -333,15 +333,15 @@ def get_layout(algorithm: str) -> dict:
333333
textposition="top center",
334334
hovertext=[data["hover_text"] for data in regular_table_nodes.values()],
335335
hoverinfo="text",
336-
marker=dict(
337-
symbol=table_symbol,
338-
size=[data["size"] for data in regular_table_nodes.values()],
339-
color=[data["color"] for data in regular_table_nodes.values()]
336+
marker={
337+
"symbol": table_symbol,
338+
"size": [data["size"] for data in regular_table_nodes.values()],
339+
"color": [data["color"] for data in regular_table_nodes.values()]
340340
if color_gradient
341341
else "rgba(255, 127, 14, 0.8)",
342-
line=dict(width=1, color="rgba(255, 127, 14, 1)"),
343-
),
344-
textfont=dict(size=text_font_size),
342+
"line": {"width": 1, "color": "rgba(255, 127, 14, 1)"},
343+
},
344+
textfont={"size": text_font_size},
345345
)
346346
traces.append(regular_table_trace)
347347

@@ -356,15 +356,15 @@ def get_layout(algorithm: str) -> dict:
356356
textposition="top center",
357357
hovertext=[data["hover_text"] for data in common_table_nodes.values()],
358358
hoverinfo="text",
359-
marker=dict(
360-
symbol=table_symbol,
361-
size=[data["size"] for data in common_table_nodes.values()],
362-
color=[data["color"] for data in common_table_nodes.values()]
359+
marker={
360+
"symbol": table_symbol,
361+
"size": [data["size"] for data in common_table_nodes.values()],
362+
"color": [data["color"] for data in common_table_nodes.values()]
363363
if color_gradient
364364
else "rgba(214, 39, 40, 0.8)",
365-
line=dict(width=2, color="rgba(214, 39, 40, 1)"),
366-
),
367-
textfont=dict(size=text_font_size),
365+
"line": {"width": 2, "color": "rgba(214, 39, 40, 1)"},
366+
},
367+
textfont={"size": text_font_size},
368368
)
369369
traces.append(common_table_trace)
370370

@@ -376,12 +376,12 @@ def get_layout(algorithm: str) -> dict:
376376

377377
# Add text toggle buttons if requested
378378
if show_text_buttons:
379-
text_buttons = dict(
380-
type="buttons",
381-
direction="right",
382-
buttons=[
383-
dict(
384-
args=[
379+
text_buttons = {
380+
"type": "buttons",
381+
"direction": "right",
382+
"buttons": [
383+
{
384+
"args": [
385385
{
386386
"mode": [
387387
"lines",
@@ -393,50 +393,50 @@ def get_layout(algorithm: str) -> dict:
393393
else ["lines", "markers+text", "markers+text"]
394394
}
395395
],
396-
label="Show All Text",
397-
method="restyle",
398-
),
399-
dict(
400-
args=[
396+
"label": "Show All Text",
397+
"method": "restyle",
398+
},
399+
{
400+
"args": [
401401
{
402402
"mode": ["lines", "markers", "markers", "markers"]
403403
if len(traces) == 4
404404
else ["lines", "markers", "markers"]
405405
}
406406
],
407-
label="Hide All Text",
408-
method="restyle",
409-
),
410-
dict(
411-
args=[
407+
"label": "Hide All Text",
408+
"method": "restyle",
409+
},
410+
{
411+
"args": [
412412
{
413413
"mode": ["lines", "markers+text", "markers", "markers"]
414414
if len(traces) == 4
415415
else ["lines", "markers+text", "markers"]
416416
}
417417
],
418-
label="Files Text Only",
419-
method="restyle",
420-
),
421-
dict(
422-
args=[
418+
"label": "Files Text Only",
419+
"method": "restyle",
420+
},
421+
{
422+
"args": [
423423
{
424424
"mode": ["lines", "markers", "markers+text", "markers+text"]
425425
if len(traces) == 4
426426
else ["lines", "markers", "markers+text"]
427427
}
428428
],
429-
label="Tables Text Only",
430-
method="restyle",
431-
),
429+
"label": "Tables Text Only",
430+
"method": "restyle",
431+
},
432432
],
433-
pad={"r": 10, "t": 10},
434-
showactive=True,
435-
x=0.5,
436-
xanchor="center",
437-
y=1.15,
438-
yanchor="top",
439-
)
433+
"pad": {"r": 10, "t": 10},
434+
"showactive": True,
435+
"x": 0.5,
436+
"xanchor": "center",
437+
"y": 1.15,
438+
"yanchor": "top",
439+
}
440440
updatemenus.append(text_buttons)
441441

442442
# Add layout change buttons if requested
@@ -502,21 +502,25 @@ def get_layout(algorithm: str) -> dict:
502502
]
503503

504504
# Create button
505-
button = dict(args=args, label=layout_name.capitalize(), method="update")
505+
button = {
506+
"args": args,
507+
"label": layout_name.capitalize(),
508+
"method": "update",
509+
}
506510
layout_buttons.append(button)
507511

508512
# Add layout button menu
509-
layout_menu = dict(
510-
type="buttons",
511-
direction="right",
512-
buttons=layout_buttons,
513-
pad={"r": 10, "t": 10},
514-
showactive=True,
515-
x=0.5,
516-
xanchor="center",
517-
y=1.08 if show_text_buttons else 1.15,
518-
yanchor="top",
519-
)
513+
layout_menu = {
514+
"type": "buttons",
515+
"direction": "right",
516+
"buttons": layout_buttons,
517+
"pad": {"r": 10, "t": 10},
518+
"showactive": True,
519+
"x": 0.5,
520+
"xanchor": "center",
521+
"y": 1.08 if show_text_buttons else 1.15,
522+
"yanchor": "top",
523+
}
520524
updatemenus.append(layout_menu)
521525

522526
# Set top margin based on buttons
@@ -532,26 +536,30 @@ def get_layout(algorithm: str) -> dict:
532536
f"SQL Dependency Graph ({len(sql_profiles)} files, "
533537
f"{len(table_usage)} tables)"
534538
),
535-
title_font=dict(size=16),
539+
title_font={"size": 16},
536540
showlegend=True,
537-
legend=dict(
538-
yanchor="top", y=0.99, xanchor="left", x=0.01, itemsizing="constant"
539-
),
541+
legend={
542+
"yanchor": "top",
543+
"y": 0.99,
544+
"xanchor": "left",
545+
"x": 0.01,
546+
"itemsizing": "constant",
547+
},
540548
updatemenus=updatemenus if updatemenus else None,
541549
hovermode="closest",
542-
margin=dict(b=20, l=5, r=5, t=top_margin),
550+
margin={"b": 20, "l": 5, "r": 5, "t": top_margin},
543551
annotations=[
544-
dict(
545-
showarrow=False,
546-
text="Size indicates usage frequency",
547-
xref="paper",
548-
yref="paper",
549-
x=0.01,
550-
y=0.01,
551-
)
552+
{
553+
"showarrow": False,
554+
"text": "Size indicates usage frequency",
555+
"xref": "paper",
556+
"yref": "paper",
557+
"x": 0.01,
558+
"y": 0.01,
559+
}
552560
],
553-
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
554-
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
561+
xaxis={"showgrid": False, "zeroline": False, "showticklabels": False},
562+
yaxis={"showgrid": False, "zeroline": False, "showticklabels": False},
555563
plot_bgcolor="rgba(248, 248, 248, 1)",
556564
paper_bgcolor="rgba(248, 248, 248, 1)",
557565
)

0 commit comments

Comments
 (0)