Skip to content

Commit 48d96c2

Browse files
committed
fix lint
1 parent 63a34bb commit 48d96c2

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

libs/community/langchain_community/graph_vectorstores/visualize.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from typing import TYPE_CHECKING, Dict, Iterable, Optional
21
import re
2+
from typing import TYPE_CHECKING, Dict, Iterable, Optional
33

44
from langchain_core.documents import Document
55
from langchain_core.graph_vectorstores.links import get_links
@@ -18,7 +18,8 @@ def _escape_id(id: str) -> str:
1818
"bidir": "both",
1919
}
2020

21-
_WORD_RE = re.compile('\s*\S+')
21+
_WORD_RE = re.compile("\s*\S+")
22+
2223

2324
def _split_prefix(s: str, max_chars: int = 50) -> str:
2425
words = _WORD_RE.finditer(s)
@@ -29,11 +30,12 @@ def _split_prefix(s: str, max_chars: int = 50) -> str:
2930
break
3031
split = word.end(0)
3132

32-
if split == len(s):
33+
if split == len(s):
3334
return s
3435
else:
3536
return f"{s[0:split]}..."
3637

38+
3739
def render_graphviz(
3840
documents: Iterable[Document],
3941
engine: Optional[str] = None,
@@ -90,7 +92,10 @@ def render_graphviz(
9092
escaped_id = _escape_id(id)
9193
color = node_colors[id] if id in node_colors else node_color
9294

93-
node_label=f"{graphviz.escape(id)}\n{graphviz.escape(_split_prefix(document.page_content))}"
95+
node_label = "\n".join([
96+
graphviz.escape(id),
97+
graphviz.escape(_split_prefix(document.page_content)),
98+
])
9499
graph.node(
95100
escaped_id,
96101
label=node_label,

libs/community/tests/unit_tests/graph_vectorstores/test_visualize.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def test_visualize_simple_graph():
3939
"\ta -> href_a [dir=back]\n"
4040
'\tkw_foo [label="kw:foo"]\n'
4141
"\ta -> kw_foo [dir=both]\n"
42-
'\tb [label="b\n<some\n more content>" shape=note tooltip="<some\n more content>"]\n'
42+
'\tb [label="b\n<some\n more content>" '
43+
'shape=note tooltip="<some\n more content>"]\n'
4344
'\thref_b [label="href:b"]\n'
4445
"\tb -> href_b [dir=back]\n"
4546
"\tb -> href_a [dir=forward]\n"
@@ -55,12 +56,14 @@ def test_visualize_simple_graph():
5556
"digraph {\n"
5657
"\trankdir=LR\n"
5758
"\tnode [style=filled]\n"
58-
'\ta [label="a\nsome content" fillcolor=gold shape=note tooltip="some content"]\n'
59+
'\ta [label="a\nsome content" fillcolor=gold '
60+
'shape=note tooltip="some content"]\n'
5961
'\thref_a [label="href:a"]\n'
6062
"\ta -> href_a [dir=back]\n"
6163
'\tkw_foo [label="kw:foo"]\n'
6264
"\ta -> kw_foo [dir=both]\n"
63-
'\tb [label="b\n<some\n more content>" shape=note tooltip="<some\n more content>"]\n'
65+
'\tb [label="b\n<some\n more content>" '
66+
'shape=note tooltip="<some\n more content>"]\n'
6467
'\thref_b [label="href:b"]\n'
6568
"\tb -> href_b [dir=back]\n"
6669
"\tb -> href_a [dir=forward]\n"
@@ -70,7 +73,9 @@ def test_visualize_simple_graph():
7073
"}\n"
7174
)
7275

73-
assert render_graphviz([doc1, doc2], node_color = "gold", node_colors={"a": None}).source == (
76+
assert render_graphviz(
77+
[doc1, doc2], node_color="gold", node_colors={"a": None}
78+
).source == (
7479
"digraph {\n"
7580
"\trankdir=LR\n"
7681
"\tnode [style=filled]\n"
@@ -79,7 +84,8 @@ def test_visualize_simple_graph():
7984
"\ta -> href_a [dir=back]\n"
8085
'\tkw_foo [label="kw:foo"]\n'
8186
"\ta -> kw_foo [dir=both]\n"
82-
'\tb [label="b\n<some\n more content>" fillcolor=gold shape=note tooltip="<some\n more content>"]\n'
87+
'\tb [label="b\n<some\n more content>" fillcolor=gold '
88+
'shape=note tooltip="<some\n more content>"]\n'
8389
'\thref_b [label="href:b"]\n'
8490
"\tb -> href_b [dir=back]\n"
8591
"\tb -> href_a [dir=forward]\n"

0 commit comments

Comments
 (0)