-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdodo.py
75 lines (61 loc) · 1.84 KB
/
dodo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pathlib
import pygraphviz
from doit.tools import create_folder, run_once
PROJECTS_PATH = 'projects'
def module_to_dot(dependencies, targets):
graph = pygraphviz.AGraph(strict=False, directed=True)
for dep in dependencies:
filepath = pathlib.Path(dep)
source = filepath.stem
with filepath.open() as fh:
for line in fh:
sink = line.strip()
if sink:
graph.add_edge(source, sink)
graph.write(targets[0])
def task_create_projects():
"Create the projects directory"
return {
'actions': [
(create_folder, [PROJECTS_PATH])
],
'targets': [
PROJECTS_PATH
],
'uptodate': [run_once]
}
def task_git():
"""Clone the repo"""
return {
'actions': [
f'git clone --depth 1 https://github.com/requests/requests.git {PROJECTS_PATH}/requests'
],
'targets': [
f'{PROJECTS_PATH}/requests/requests/models.py'
],
'uptodate': [run_once]
}
def task_imports():
"""find imports from a python module"""
return {
'file_dep': [f'{PROJECTS_PATH}/requests/requests/models.py'],
'targets': ['requests.models.deps'],
'actions': ['python -m import_deps %(dependencies)s > %(targets)s'],
'clean': True
}
def task_dot():
"""generate a graphviz's dot graph from module imports"""
return {
'file_dep': ['requests.models.deps'],
'targets': ['requests.models.dot'],
'actions': [module_to_dot],
'clean': True
}
def task_draw():
"""generate image from a dot file"""
return {
'file_dep': ['requests.models.dot'],
'targets': ['requests.models.png'],
'actions': ['dot -Tpng %(dependencies)s -o %(targets)s'],
'clean': True
}