Skip to content

Commit bb27130

Browse files
committed
add full path to images
1 parent 367b2d6 commit bb27130

19 files changed

+552
-158
lines changed

.isort.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[settings]
2+
known_third_party = clifier,matplotlib,networkx,pytest

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
repos:
2+
- repo: https://github.com/asottile/seed-isort-config
3+
rev: v2.2.0
4+
hooks:
5+
- id: seed-isort-config
6+
- repo: https://github.com/pycqa/isort
7+
rev: 5.4.2
8+
hooks:
9+
- id: isort
10+
- repo: https://github.com/ambv/black
11+
rev: stable
12+
hooks:
13+
- id: black
14+
language_version: python3.8
15+
- repo: https://github.com/PyCQA/flake8
16+
rev: 3.8.3
17+
hooks:
18+
- id: flake8

CHANGELOG.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
1. Command line tool name changed from 'cg' to 'codegraph'.
55
2. Updated versions of dependencies
66
3. Minimal supported python version up to 3.8
7-
4. Cleaned up code
7+
4. Added some unit & functional tests

CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
### Install all dependencies
2+
3+
Project uses poetry as a package manager, so if you don't have it - first of all read official doc & install it: https://python-poetry.org/docs/
4+
5+
6+
7+
```
8+
# after that do install
9+
poetry install
10+
11+
# and activate project shell
12+
poetry shell
13+
14+
```
15+
16+
### Install pre-commit hook
17+
18+
To follow code styles and successfully pass github pipelines install pre-commit hooks
19+
20+
```
21+
22+
pre-commit install
23+
24+
```

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Iuliia Volkova [[email protected]]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,23 @@ Pass '-o' flag if you want only print dependencies in console and don't want gra
4242
If you want to change view and play with graph output - you can check 'vizualyzer.py'
4343
and play with matplotlib and networkX settings.
4444

45-
In default view - red line show dependencies between entities in different modules. Green - entities in module.
45+
### Colors meanings
46+
In default view - **red line** show dependencies between entities in different modules.
47+
**Green** - links between objects/functions inside same module.
4648

47-
![Graph visualisation](/docs/img/graph_visualisation.png "Graph visualisation")
49+
![Graph visualisation](https://github.com/xnuinside/codegraph/blob/main/docs/img/graph_visualisation.png "Graph visualisation")
4850

49-
![ Code with not used module](/docs/img/code_with_trash_module.png "Code with not used module")
51+
![ Code with not used module](https://github.com/xnuinside/codegraph/blob/main/docs/img/code_with_trash_module.png "Code with not used module")
5052

51-
![Code there all modules linked together](/docs/img/normal_code.png "Code there all modules linked together")
53+
![Code there all modules linked together](https://github.com/xnuinside/codegraph/blob/main/docs/img/normal_code.png "Code there all modules linked together")
5254

5355
### TODO
5456

5557
1. Create normal readme
5658
2. Add tests
5759
3. Work on visual part of Graph (now it is not very user friendly)
5860
4. Add support to variables (names) as entities
61+
5. Split usage & inheritance as a different cases
5962

6063
## Changelog
6164
**v0.1.0**
@@ -64,4 +67,4 @@ In default view - red line show dependencies between entities in different modul
6467
1. Command line tool name changed from 'cg' to 'codegraph'.
6568
2. Updated versions of dependencies
6669
3. Minimal supported python version up to 3.8
67-
4. Cleaned up code
70+
4. Added some unit & functional tests

codegraph/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Dict, List, Text, Tuple
55

66
from codegraph.parser import Import, create_objects_array
7-
from codegraph.utils import get_paths_list
7+
from codegraph.utils import get_python_paths_list
88

99
aliases = {}
1010

@@ -36,7 +36,7 @@ def get_code_objects(paths_list: List) -> Dict:
3636

3737
class CodeGraph:
3838
def __init__(self, args: Namespace):
39-
self.paths_list = get_paths_list(args.paths)
39+
self.paths_list = get_python_paths_list(args.paths)
4040
# get py modules list data
4141
self.modules_data = get_code_objects(self.paths_list)
4242

codegraph/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def create_objects_array(fname, source): # noqa: C901
9797
stack = []
9898

9999
g = tokenize.generate_tokens(f.readline)
100+
100101
try:
101102
new_lines = 0
102103
imports = None

codegraph/utils.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
import glob
2-
from typing import List
2+
from pathlib import Path
3+
from typing import List, Union
34

45

5-
def get_paths_list(paths: List) -> List:
6+
def get_python_paths_list(paths: Union[str, List]) -> List:
67
"""
78
return list of paths to python files, that found in provided path
89
:param paths: paths to folder or python file that need to tests
910
:return:
1011
"""
12+
if isinstance(paths, str):
13+
paths = [paths]
1114
if len(paths) == 1 and paths[0].endswith(".py"):
12-
return [paths[0]]
15+
# mean provided path to one python module
16+
path = Path(paths[0]).absolute()
17+
if not path.exists():
18+
raise ValueError(f"Path {path.as_posix()} does not exists")
19+
return [path.as_posix()]
20+
1321
paths_list = []
1422
for path in paths:
23+
path = Path(path).absolute()
24+
if not path.exists():
25+
raise ValueError(f"Path {path.as_posix()} does not exists")
26+
path = path.as_posix()
1527
paths_list += [
1628
path
1729
for path in glob.glob(path + "/*", recursive=True)

codegraph/vizualyzer.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,41 @@
55
import networkx as nx
66

77

8+
def process_module_in_graph(module: Dict[str, list], module_links: list, G: nx.DiGraph):
9+
_module = os.path.basename(module)
10+
11+
module_edges = []
12+
13+
sub_edges = []
14+
for entity in module_links:
15+
module_edges.append((_module, entity))
16+
for dep in module_links[entity]:
17+
if "." in dep:
18+
dep = dep.split(".")[1].replace(".", ".py")
19+
sub_edges.append((entity, dep))
20+
G.add_edges_from(sub_edges)
21+
if not module_links:
22+
G.add_node(_module)
23+
G.add_edges_from(module_edges)
24+
return module_edges, sub_edges
25+
26+
827
def draw_graph(modules_entities: Dict) -> None:
28+
929
G = nx.DiGraph()
30+
1031
module_edges_all = []
32+
1133
sub_edges_all = []
34+
1235
for module in modules_entities:
13-
_module = os.path.basename(module)
14-
module_edges = []
15-
for entity in modules_entities[module]:
16-
sub_edges = []
17-
module_edges.append((_module, entity))
18-
for dep in modules_entities[module][entity]:
19-
if "." in dep:
20-
dep = dep.split(".")[1].replace(".", ".py")
21-
sub_edges.append((entity, dep))
22-
G.add_edges_from(sub_edges)
23-
sub_edges_all += sub_edges
24-
if not modules_entities[module]:
25-
G.add_node(_module)
26-
G.add_edges_from(module_edges)
27-
module_edges_all += module_edges
36+
new_module_edges_all, new_edges_all = process_module_in_graph(
37+
module, modules_entities[module], G
38+
)
39+
40+
module_edges_all += new_module_edges_all
41+
sub_edges_all += new_edges_all
42+
2843
pos = nx.spring_layout(G)
2944
module_list = [os.path.basename(module) for module in modules_entities]
3045
module_list_labels = {module_name: module_name for module_name in module_list}

0 commit comments

Comments
 (0)