-
Notifications
You must be signed in to change notification settings - Fork 0
/
dodo.py
124 lines (102 loc) · 3.14 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# -*- coding: utf-8 -*-
# pydoit tast file
# see https://pydoit.org/
# run from this dir with `doit`, or `doit list`, `doit help` etc. (pip install doit 1st)
import pathlib
import pygraphviz
from import_deps import PyModule, ModuleSet
def task_install():
"""Install dukit in editable mode"""
return {
"actions": ["pip install -e ."],
"verbosity": 2
}
def task_prospector():
"""Run prospector static analysis"""
return {
"file_dep": ["dukit.prospector.yaml"],
"actions": [
'prospector --profile %(dependencies)s -o grouped:%(targets)s',
],
"targets": ["prospector.log"],
"verbosity": 2
}
def task_mz_test():
"""mz_test"""
return {
"file_dep": ["examples/magnetization/mz_test.py"],
"actions": [
"python3 %(dependencies)s"
],
"verbosity": 2
}
def task_mz_polys():
"""mz_test"""
return {
"file_dep": ["examples/magnetization/mz_draw_polys.py"],
"actions": [
"python3 %(dependencies)s"
],
"verbosity": 2
}
def task_cprof():
"""Run cProfile on mz_test"""
return {
"file_dep": ["examples/magnetization/mz_test.py"],
"actions": [
"python3 -m cProfile -o %(targets)s %(dependencies)s"],
"targets": ["output.prof"]
}
def task_snakeviz():
"""Run snakeviz on profiled mz_test"""
return {
"file_dep": ["output.prof"],
"actions": ["snakeviz %(dependencies)s"],
}
def task_docs():
"""Build docs"""
return {
"actions": [
"pdoc3 --output-dir docs/ " +
"--html --template-dir docs/ --force --skip-errors src/dukit/"],
}
# === START IMPORT GRAPHING
def task_imports():
"""find imports from a python module"""
def get_imports(pkg_modules, module_path):
module = pkg_modules.by_path[module_path]
imports = pkg_modules.get_imports(module, return_fqn=True)
return {'modules': list(sorted(imports))}
base_path = pathlib.Path("src/dukit")
pkg_modules = ModuleSet(base_path.glob('**/*.py'))
for name, module in pkg_modules.by_name.items():
yield {
'name': name,
'file_dep': [module.path],
'actions': [(get_imports, (pkg_modules, module.path))],
}
def task_dot():
"""generate a graphviz's dot graph from module imports"""
def module_to_dot(imports, targets):
graph = pygraphviz.AGraph(strict=False, directed=True)
graph.node_attr['color'] = 'black'
graph.node_attr['style'] = 'solid'
for source, sinks in imports.items():
for sink in sinks:
graph.add_edge(source, sink)
graph.write(targets[0])
return {
'targets': ['dukit.dot'],
'actions': [module_to_dot],
'getargs': {'imports': ('imports', 'modules')},
'clean': True,
}
def task_draw():
"""generate image from a dot file"""
return {
'file_dep': ['dukit.dot'],
'targets': ['dukit.png'],
'actions': ['dot -Tpng %(dependencies)s -o %(targets)s'],
'clean': True,
}
# === END IMPORT GRAPHING