cpg2py 1.0.2__py3-none-any.whl → 1.0.4__py3-none-any.whl

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.
cpg2py/__init__.py CHANGED
@@ -1,9 +1,9 @@
1
- from pathlib import Path
2
1
  from csv import DictReader
2
+ from pathlib import Path
3
3
  from .cpg import _Graph
4
4
  from .abc import *
5
5
 
6
- def cpg_graph(node_csv: Path, edge_csv: Path) -> _Graph:
6
+ def cpg_graph(node_csv: Path, edge_csv: Path) -> "_Graph":
7
7
  storage = Storage()
8
8
  with open(node_csv, 'r') as n_file:
9
9
  reader = DictReader(n_file, delimiter='\t')
@@ -11,9 +11,9 @@ def cpg_graph(node_csv: Path, edge_csv: Path) -> _Graph:
11
11
  nid = node_props.get("id:int", None)
12
12
  if nid is None: node_props.get("id")
13
13
  if not storage.add_node(nid):
14
- print(f"Node {nid} already exists in the graph")
14
+ print(f"WARN: Node {nid} already exists in the graph")
15
15
  if not storage.set_node_props(nid, node_props):
16
- print(f"Failed to set properties for node {nid}")
16
+ print(f"WARN: Failed to set properties for node {nid}")
17
17
  with open(edge_csv, 'r') as f:
18
18
  reader = DictReader(f, delimiter='\t')
19
19
  for edge_props in reader:
@@ -24,11 +24,17 @@ def cpg_graph(node_csv: Path, edge_csv: Path) -> _Graph:
24
24
  e_type = str(edge_props.get("type", None))
25
25
  if e_type is None: e_type = str(edge_props.get("type:str"))
26
26
  edge_id = (f_nid, t_nid, e_type)
27
+ if not storage.contains_node(edge_id[0]):
28
+ storage.add_node(edge_id[0])
29
+ print(f"WARN: node {edge_id[0]} does not exists")
30
+ if not storage.contains_node(edge_id[1]):
31
+ storage.add_node(edge_id[1])
32
+ print(f"WARN: node {edge_id[1]} does not exists")
27
33
  if not storage.add_edge(edge_id):
28
- print(f"Edge {f_nid} -> {t_nid} already exists in the graph")
34
+ print(f"WARN: Edge {f_nid} -> {t_nid} already exists in the graph")
29
35
  if not storage.set_edge_props(edge_id, edge_props):
30
- print(f"Failed to set properties for edge {edge_id}")
31
- return _Graph(storage)
36
+ print(f"WARN: Failed to set properties for edge {edge_id}")
37
+ return _Graph(storage)
32
38
 
33
39
 
34
40
  __all__ = ['cpg_graph', 'AbcGraphQuerier', 'AbcNodeQuerier', 'AbcEdgeQuerier', 'Storage']
cpg2py/cpg/edge.py CHANGED
@@ -1,6 +1,5 @@
1
1
  from __future__ import annotations
2
2
  from typing import Optional, Tuple
3
- from enum import Enum
4
3
  from ..abc import AbcGraphQuerier, AbcEdgeQuerier
5
4
 
6
5
  class _Edge(AbcEdgeQuerier):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: cpg2py
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary: A graph-based data structure designed for querying CSV files in Joern format in Python
5
5
  Home-page: https://github.com/YichaoXu/cpg2py
6
6
  Author: Yichao Xu
@@ -1,15 +1,15 @@
1
- cpg2py/__init__.py,sha256=bjd1EjYmNa0N8DW4tSQg-YpzzkqgtBVR2FrgDZReY10,1557
1
+ cpg2py/__init__.py,sha256=4GXaMrMxlqWKpjrwAZlSwBCG-9_osMeChuFS-WRqtKg,1918
2
2
  cpg2py/abc/__init__.py,sha256=HgDXsJkGcPQvr6ac3hMrUU9TuQibMaP7-oXbXLs_iLI,207
3
3
  cpg2py/abc/edge.py,sha256=zLlRebDKT2qK5XOJq23_UUCESgGsvgalbXdx_uUcKks,1240
4
4
  cpg2py/abc/graph.py,sha256=DbeHN6qsNaqcqL9cUquJWC16BihDxy1MEhyuL-qVMBI,3902
5
5
  cpg2py/abc/node.py,sha256=E2EQv_KisEPuslFaglZZvSBm-VY5LYCFBOFY1yiPzDY,844
6
6
  cpg2py/abc/storage.py,sha256=BF82Vs_7FxGYSPiM_6JwQVzmaqMzGy2r-WSk8pQQclY,5976
7
7
  cpg2py/cpg/__init__.py,sha256=fO59Yd7OISyxdjdZDJ5zFM41r4cYKawOsvpqV4gWrGM,48
8
- cpg2py/cpg/edge.py,sha256=_ERU_lS4_5AxlOiuX73JvTZBSr9o8ae0q-kWwO82580,1029
8
+ cpg2py/cpg/edge.py,sha256=brG7cQl7tjihbUCBYyjNUnMLsKIif-XQc_TFdGz8ZYo,1007
9
9
  cpg2py/cpg/graph.py,sha256=n4EjAhhjzl0XRJBwlAmK5AcSrECiqhjA6dXt2Ucf7IM,3448
10
10
  cpg2py/cpg/node.py,sha256=-2xl8c-eSbe4Kv4xPAEf6POlCYOV4j0voxJAKDZj3Cc,2037
11
- cpg2py-1.0.2.dist-info/LICENSE,sha256=vTjbt7iL1hUilI8E87FoQerEDa9nbpeip26iA6bguHI,1066
12
- cpg2py-1.0.2.dist-info/METADATA,sha256=dCiQ4H2zcFC9AfFVOsSAkzFJDsKccGwcuyGYCnj9LRs,7077
13
- cpg2py-1.0.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
14
- cpg2py-1.0.2.dist-info/top_level.txt,sha256=xDY8faKh5Rczvsqb5Jt9Sq-Y7EOImh7jh-m1oVTnH5k,7
15
- cpg2py-1.0.2.dist-info/RECORD,,
11
+ cpg2py-1.0.4.dist-info/LICENSE,sha256=vTjbt7iL1hUilI8E87FoQerEDa9nbpeip26iA6bguHI,1066
12
+ cpg2py-1.0.4.dist-info/METADATA,sha256=Xhx-JFz1RECxW-aLxPhfy4elJgFoaTjxxiXR28YD-c8,7077
13
+ cpg2py-1.0.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
14
+ cpg2py-1.0.4.dist-info/top_level.txt,sha256=xDY8faKh5Rczvsqb5Jt9Sq-Y7EOImh7jh-m1oVTnH5k,7
15
+ cpg2py-1.0.4.dist-info/RECORD,,
File without changes