Skip to content

Commit 295397b

Browse files
authored
CLN: Use Black formatter on codebase (#18)
1 parent 4a95a91 commit 295397b

File tree

5 files changed

+116
-89
lines changed

5 files changed

+116
-89
lines changed

tests/test_zkviz.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66

77

88
class TestListZettels(TestCase):
9-
109
def test_list_zettels_with_md_extension(self):
1110
# Create a temporary folder and write files in it
1211
with TemporaryDirectory() as tmpdirname:
13-
ext = '.md'
14-
basename = '201906242157'
12+
ext = ".md"
13+
basename = "201906242157"
1514
filepaths = []
1615
for i in range(3):
1716
path = Path(tmpdirname, basename + str(i) + ext)
@@ -24,49 +23,48 @@ def test_list_zettels_with_md_extension(self):
2423
def test_list_zettels_with_txt_extension(self):
2524
# Create a temporary folder and write files in it
2625
with TemporaryDirectory() as tmpdirname:
27-
ext = '.txt'
28-
basename = '201906242157'
26+
ext = ".txt"
27+
basename = "201906242157"
2928
filepaths = []
3029
for i in range(3):
3130
path = Path(tmpdirname, basename + str(i) + ext)
3231
path.touch()
3332
filepaths.append(str(path))
3433

35-
files_found = zkviz.list_zettels(tmpdirname, '*.txt')
34+
files_found = zkviz.list_zettels(tmpdirname, "*.txt")
3635
self.assertEqual(filepaths, files_found)
3736

3837
def test_list_zettels_with_mixed_extensions(self):
3938
# Create a temporary folder and write files in it
4039
with TemporaryDirectory() as tmpdirname:
4140
filepaths = []
42-
basename = '201906242157'
41+
basename = "201906242157"
4342

44-
ext = '.txt'
43+
ext = ".txt"
4544
for i in range(5):
4645
path = Path(tmpdirname, basename + str(i) + ext)
4746
path.touch()
4847
filepaths.append(str(path))
4948

50-
ext = '.md'
49+
ext = ".md"
5150
for i in range(5, 10):
5251
path = Path(tmpdirname, basename + str(i) + ext)
5352
path.touch()
5453
filepaths.append(str(path))
5554

56-
files_found = zkviz.list_zettels(tmpdirname, '*.txt|*.md')
55+
files_found = zkviz.list_zettels(tmpdirname, "*.txt|*.md")
5756
self.assertEqual(filepaths, files_found)
5857

5958

6059
class TestParseArgs(TestCase):
61-
6260
def test_default_extension(self):
63-
args = zkviz.parse_args('')
64-
self.assertEqual(['*.md'], args.pattern)
61+
args = zkviz.parse_args("")
62+
self.assertEqual(["*.md"], args.pattern)
6563

6664
def test_overwrite_extension(self):
67-
args = zkviz.parse_args(["--pattern","*.txt"])
68-
self.assertEqual(['*.txt'], args.pattern)
65+
args = zkviz.parse_args(["--pattern", "*.txt"])
66+
self.assertEqual(["*.txt"], args.pattern)
6967

7068
def test_multiple_extensions(self):
71-
args = zkviz.parse_args(["--pattern","*.txt", "--pattern", '*.md'])
72-
self.assertEqual(['*.txt', '*.md'], args.pattern)
69+
args = zkviz.parse_args(["--pattern", "*.txt", "--pattern", "*.md"])
70+
self.assertEqual(["*.txt", "*.md"], args.pattern)

zkviz/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.2.0'
1+
__version__ = "1.2.0"

zkviz/graphviz.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55

66
class NetworkGraphviz:
7-
8-
def __init__(self, name='Zettelkasten', engine='sfdp', shape='record'):
7+
def __init__(self, name="Zettelkasten", engine="sfdp", shape="record"):
98
"""
109
Build network to visualize with Graphviz.
1110
@@ -50,11 +49,11 @@ def add_node(self, node_id, title):
5049
The text label for each node, typically the zettel title.
5150
5251
"""
53-
if self.shape == 'plaintext':
52+
if self.shape == "plaintext":
5453
label = self.wrap_title("{} {}".format(node_id, title)).strip()
55-
elif self.shape == 'record':
54+
elif self.shape == "record":
5655
# Wrap in {} so the elements are stacked vertically
57-
label = "{" + '|'.join([node_id, self.wrap_title(title)]) + "}"
56+
label = "{" + "|".join([node_id, self.wrap_title(title)]) + "}"
5857

5958
self.graph.node(node_id, label, shape=self.shape)
6059

zkviz/plotly.py

+29-23
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44

55
class NetworkPlotly:
6-
7-
def __init__(self, name='Zettelkasten'):
6+
def __init__(self, name="Zettelkasten"):
87
"""
98
Build network to visualize with Plotly
109
@@ -75,64 +74,71 @@ def build_plotly_figure(self, pos=None):
7574
x=[],
7675
y=[],
7776
text=[],
78-
mode='markers',
79-
hoverinfo='text',
77+
mode="markers",
78+
hoverinfo="text",
8079
marker=dict(
8180
showscale=True,
8281
# colorscale options
8382
#'Greys' | 'YlGnBu' | 'Greens' | 'YlOrRd' | 'Bluered' | 'RdBu' |
8483
#'Reds' | 'Blues' | 'Picnic' | 'Rainbow' | 'Portland' | 'Jet' |
8584
#'Hot' | 'Blackbody' | 'Earth' | 'Electric' | 'Viridis' |
86-
colorscale='YlGnBu',
85+
colorscale="YlGnBu",
8786
reversescale=True,
8887
color=[],
8988
size=10,
9089
colorbar=dict(
91-
thickness=15,
92-
title='Centrality',
93-
xanchor='left',
94-
titleside='right'
90+
thickness=15, title="Centrality", xanchor="left", titleside="right"
9591
),
96-
line=dict(width=2)))
92+
line=dict(width=2),
93+
),
94+
)
9795

9896
for node in self.graph.nodes():
9997
x, y = pos[node]
100-
text = '<br>'.join([node, self.graph.node[node].get('title', '')])
101-
node_trace['x'] += tuple([x])
102-
node_trace['y'] += tuple([y])
103-
node_trace['text'] += tuple([text])
98+
text = "<br>".join([node, self.graph.node[node].get("title", "")])
99+
node_trace["x"] += tuple([x])
100+
node_trace["y"] += tuple([y])
101+
node_trace["text"] += tuple([text])
104102

105103
# Color nodes based on the centrality
106104
for node, centrality in nx.degree_centrality(self.graph).items():
107-
node_trace['marker']['color']+=tuple([centrality])
105+
node_trace["marker"]["color"] += tuple([centrality])
108106

109107
# Draw the edges as annotations because it's only sane way to draw arrows.
110108
edges = []
111109
for from_node, to_node in self.graph.edges():
112110
edges.append(
113111
dict(
114112
# Tail coordinates
115-
ax=pos[from_node][0], ay=pos[from_node][1], axref='x', ayref='y',
113+
ax=pos[from_node][0],
114+
ay=pos[from_node][1],
115+
axref="x",
116+
ayref="y",
116117
# Head coordinates
117-
x=pos[to_node][0], y=pos[to_node][1], xref='x', yref='y',
118+
x=pos[to_node][0],
119+
y=pos[to_node][1],
120+
xref="x",
121+
yref="y",
118122
# Aesthetics
119-
arrowwidth=2, arrowcolor='#666', arrowhead=2,
123+
arrowwidth=2,
124+
arrowcolor="#666",
125+
arrowhead=2,
120126
# Have the head stop short 5 px for the center point,
121127
# i.e., depends on the node marker size.
122128
standoff=5,
123-
)
124129
)
130+
)
125131

126132
fig = go.Figure(
127133
data=[node_trace],
128134
layout=go.Layout(
129135
showlegend=False,
130-
hovermode='closest',
136+
hovermode="closest",
131137
margin=dict(b=20, l=5, r=5, t=40),
132138
annotations=edges,
133139
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
134140
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
135-
)
141+
),
136142
)
137143
return fig
138144

@@ -150,6 +156,6 @@ def render(self, output, view=True):
150156
151157
"""
152158
fig = self.build_plotly_figure()
153-
if not output.endswith('.html'):
154-
output += '.html'
159+
if not output.endswith(".html"):
160+
output += ".html"
155161
fig.write_html(output, auto_open=view)

0 commit comments

Comments
 (0)