invocation-tree 0.0.36__tar.gz → 0.0.38__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: invocation_tree
3
- Version: 0.0.36
3
+ Version: 0.0.38
4
4
  Summary: Generates an invocation tree of functions calls.
5
5
  Author-email: Bas Terwijn <bterwijn@gmail.com>
6
6
  License-Expression: BSD-2-Clause
@@ -2,7 +2,7 @@
2
2
  # Copyright (c) 2023, Bas Terwijn.
3
3
  # SPDX-License-Identifier: BSD-2-Clause
4
4
 
5
- from graphviz import Digraph
5
+ from graphviz import Digraph, Source
6
6
  import html
7
7
  import sys
8
8
  import difflib
@@ -10,7 +10,7 @@ import functools
10
10
 
11
11
  import invocation_tree.regex_set as regset
12
12
 
13
- __version__ = "0.0.36"
13
+ __version__ = "0.0.38"
14
14
  __author__ = 'Bas Terwijn'
15
15
 
16
16
  # colors dark
@@ -27,6 +27,13 @@ color_paused_dark = '#779977'
27
27
  color_active_dark = '#1d1d1d'
28
28
  color_returned_dark = '#997777'
29
29
 
30
+ # color placeholders
31
+ foreground_color_PH = '<foreground_color_PH>'
32
+ background_color_PH = '<background_color_PH>'
33
+ color_paused_PH = '<color_paused_PH>'
34
+ color_active_PH = '<color_active_PH>'
35
+ color_returned_PH = '<color_returned_PH>'
36
+
30
37
 
31
38
  def highlight_diff(str1, str2):
32
39
  matcher = difflib.SequenceMatcher(None, str1, str2)
@@ -133,6 +140,7 @@ class Invocation_Tree:
133
140
  self.is_highlighted = False
134
141
  self.graph = None
135
142
  self.prev_global_tracer = None
143
+ self.uncolored_graph = None
136
144
 
137
145
  def __repr__(self):
138
146
  return f'Invocation_Tree(filename={repr(self.filename)}, show={self.show}, block={self.block}, each_line={self.each_line}, gifcount={self.gifcount})'
@@ -224,14 +232,14 @@ class Invocation_Tree:
224
232
  tree_node.is_returned = is_returned
225
233
  return_value = tree_node.return_value
226
234
  border = 1
227
- color = self.color_paused
235
+ color = color_paused_PH
228
236
  if active:
229
- color = self.color_active
237
+ color = color_active_PH
230
238
  border = 3
231
239
  if is_returned:
232
- color = self.color_returned
233
- alignment = 'ALIGN="left" BALIGN="LEFT"'
234
- table = f'<\n<TABLE BORDER="{str(border)}" COLOR="{self.foreground_color}" CELLBORDER="0" CELLSPACING="0" BGCOLOR="{color}">\n <TR>'
240
+ color = color_returned_PH
241
+ alignment = 'ALIGN="LEFT" BALIGN="LEFT"'
242
+ table = f'<\n<TABLE BORDER="{str(border)}" COLOR={foreground_color_PH} CELLBORDER="0" CELLSPACING="0" BGCOLOR={color}>\n <TR>'
235
243
  class_fun_name = get_class_function_name(tree_node.frame)
236
244
  local_vars = tree_node.frame.f_locals
237
245
  hightlighted_content = self.get_hightlighted_content(tree_node, class_fun_name, class_fun_name, use_old_content)
@@ -270,29 +278,59 @@ class Invocation_Tree:
270
278
  return '.'.join(splits)
271
279
  return self.filename
272
280
 
273
- def create_graph(self):
281
+ def graph_header(self):
274
282
  graphviz_graph_attr = {
275
283
  'fontname': self.fontname,
276
284
  'fontsize': str(self.fontsize),
277
- 'fontcolor': self.foreground_color,
278
- 'bgcolor': self.background_color,
285
+ 'fontcolor': foreground_color_PH,
286
+ 'bgcolor': background_color_PH,
279
287
  }
280
288
  graphviz_node_attr = {
281
289
  'fontname': self.fontname,
282
290
  'fontsize': str(self.fontsize),
283
291
  'shape':'plaintext',
284
- 'fontcolor': self.foreground_color
292
+ 'fontcolor': foreground_color_PH
285
293
  }
286
294
  graphviz_edge_attr = {
287
295
  'fontname': self.fontname,
288
296
  'fontsize': str(self.fontsize),
289
- 'fontcolor': self.foreground_color,
290
- 'color': self.foreground_color
297
+ 'fontcolor': foreground_color_PH,
298
+ 'color': foreground_color_PH
291
299
  }
292
300
  graph = Digraph('invocation_tree',
293
301
  graph_attr=graphviz_graph_attr,
294
302
  node_attr=graphviz_node_attr,
295
303
  edge_attr=graphviz_edge_attr)
304
+ return graph
305
+
306
+ def build_graph_from_nodes(self):
307
+ # add nodes and edges to graph
308
+ graph = self.graph_header()
309
+ for nid, table in self.node_id_to_table.items():
310
+ graph.node(nid, label=table)
311
+ for nid1, nid2 in self.edges:
312
+ graph.edge(nid1, nid2)
313
+ return graph
314
+
315
+ def recolor_last_graph(self):
316
+ if not self.uncolored_graph:
317
+ return self.uncolored_graph
318
+ graph_str = self.uncolored_graph.source
319
+
320
+ def replace_color(token, value):
321
+ return graph_str.replace(f'{token}', f'"{value}"')
322
+
323
+ graph_str = replace_color(foreground_color_PH, self.foreground_color)
324
+ graph_str = replace_color(background_color_PH, self.background_color)
325
+ graph_str = replace_color(color_paused_PH, self.color_paused)
326
+ graph_str = replace_color(color_active_PH, self.color_active)
327
+ graph_str = replace_color(color_returned_PH, self.color_returned)
328
+ graph = Source(graph_str)
329
+ graph.engine = self.uncolored_graph.engine
330
+ graph.format = self.uncolored_graph.format
331
+ return graph
332
+
333
+ def create_graph(self):
296
334
  # update returned nodes
297
335
  for node in self.prev_returned:
298
336
  self.update_node(node, use_old_content=True)
@@ -312,11 +350,8 @@ class Invocation_Tree:
312
350
  self.update_node(node, active=False, use_old_content=True)
313
351
  self.prev_paused = self.paused.copy()
314
352
  self.paused = []
315
- # add nodes and edges to graph
316
- for nid, table in self.node_id_to_table.items():
317
- graph.node(nid, label=table)
318
- for nid1, nid2 in self.edges:
319
- graph.edge(nid1, nid2)
353
+ self.uncolored_graph = self.build_graph_from_nodes()
354
+ graph = self.recolor_last_graph()
320
355
  return graph
321
356
 
322
357
  def render_graph(self, graph):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: invocation_tree
3
- Version: 0.0.36
3
+ Version: 0.0.38
4
4
  Summary: Generates an invocation tree of functions calls.
5
5
  Author-email: Bas Terwijn <bterwijn@gmail.com>
6
6
  License-Expression: BSD-2-Clause
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "invocation_tree"
7
- version = "0.0.36"
7
+ version = "0.0.38"
8
8
  description = "Generates an invocation tree of functions calls."
9
9
  authors = [
10
10
  {name = "Bas Terwijn", email = "bterwijn@gmail.com"}