Skip to content

Commit 611f804

Browse files
committed
remove networkx dependency
1 parent 94895fb commit 611f804

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ scope_info = ast_scope.annotate(tree)
6363
graph = scope_info.static_dependency_graph
6464
```
6565

66-
which results in the following networkx DiGraph of dependencies between top-level functions:
66+
which results in the following directed graph of dependencies between top-level functions (rendering using networkx):
6767

6868
<img src="img/dependency_graph_example.png">
6969

ast_scope/annotate.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11

2-
import networkx as nx
3-
42
from .annotator import AnnotateScope, IntermediateGlobalScope
53
from .pull_scope import PullScopes
64
from .utils import get_all_nodes, get_name
5+
from .graph import DiGraph
76

87
class ScopeInfo:
98
def __init__(self, tree, global_scope, error_scope, node_to_containing_scope):
@@ -27,7 +26,7 @@ def static_dependency_graph(self):
2726
any other variables.
2827
"""
2928
variables = self.global_scope.symbols_in_frame
30-
g = nx.DiGraph()
29+
g = DiGraph()
3130
g.add_nodes_from(variables)
3231
varis = self.global_scope.variables
3332
for construct in varis.functions | varis.classes:

ast_scope/graph.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
class DiGraph:
3+
def __init__(self):
4+
self.__adjacency_list = {}
5+
6+
def add_nodes_from(self, iterable):
7+
for node in iterable:
8+
self.add_node(node)
9+
10+
def add_node(self, node):
11+
if node not in self.__adjacency_list:
12+
self.__adjacency_list[node] = set()
13+
14+
def add_edge(self, source, target):
15+
self.__adjacency_list[source].add(target)
16+
17+
def nodes(self):
18+
return list(self.__adjacency_list)
19+
20+
def edges(self):
21+
return list((source, target) for source, targets in self.__adjacency_list.items() for target in targets)

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Module
22
attrs==19.3.0
3-
networkx==2.4
43

54
# Tests
65
nose==1.3.3

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
],
2424
python_requires='>=3.5',
2525
install_requires=[
26-
'attrs==19.3.0',
27-
'networkx==2.4'
26+
'attrs==19.3.0'
2827
]
2928
)

0 commit comments

Comments
 (0)