-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
125 lines (104 loc) · 3.31 KB
/
Makefile
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
125
NM := piony
PR := ./$(NM).py
PRF := /tmp/$(NM).prof
PY3 := python3
# Ignore all real files with names of targets.
TARGS := $(shell sed -n 's/^\([-a-z]\+\):.*/\1/p' Makefile|sort -u|xargs)
.PHONY: $(TARGS)
### DEFAULTS ###
# USAGE: make dbg A="[a,b]"
all: test debug-all
dbg: idbg
test: test-exec
style: style-lint
prf: prf-dot
uml: uml-png
cgr: call-graph
# --- MAIN ---
debug: ARGS += -V k
debug-all: ARGS += -V a
app: PYARGS := -O $(PYARGS)
# --- DEBUGGING ---
udbg: PYARGS += -m pudb.run
idbg: PYARGS += -m ipdb
vdbg: PYARGS += -S ~/pkg/Komodo-PythonRemoteDebugging/pydbgp -d localhost:9000
# py3_dbgp
dasm: PYARGS += -m dis
# --- PROFILING ---
# PYARGS += -O -m timeit -n 10
# python -m timeit -s 'text = "sample string"; char = "g"' 'char in text'
time: PY3 := time -v $(PY3)
time: app
time-client:
time bash -c "for i in {1..10}; do time $(PR); echo; done"
trace: PYARGS := -O -m trace --count -C
trace: app
profile: PYARGS += -O -m cProfile $(PRFARGS)
# [-o output_file] [-s sort_order:{line, calls, pcalls, cumulative, cumtime, time, tottime, name } ]
prf-cli prf-gui prf-dot: PRFARGS += -o $(PRF)
prf-cli: PRFARGS += -s cumulative
prf-cli: profile
@$(PY3) -c "import pstats;pstats.Stats('$(PRF)').strip_dirs().sort_stats('cumulative').print_stats()" | vim -R -
# https://docs.python.org/3.4/library/profile.html#instant-user-s-manual
prf-gui: profile
@pyprof2calltree -i $(PRF) -k
prf-dot: profile
@gprof2dot -f pstats $(PRF) | dot -Tpng -o $(PRF:.prof=.png) && sxiv $(PRF:.prof=.png)
prf-mem-total:
@mprof run -T 0.01 -C --python $(PY3) $(PR) && mprof plot
# -s <time> -- for statistics, -t 0/1 -- trace threads, -f callgrind/text -- format
prf-line-total:
@pprofile -f callgrind --out $(PRF) --threads 1 $(PR) && kcachegrind $(PRF)
# For both -mem and -line you need to put decorator @profile on line before
# functions you are insterested in. They are undefined, so remove them after testing.
prf-mem: PYARGS += -m memory_profiler
prf-line:
@kernprof -v -l $(PR)
## {-u -- unbuffered output for vim's :make}
debug debug-all app udbg idbg vdbg dasm profile prf-mem:
$(PY3) -u $(PYARGS) $(PR) $(ARGS) $(A)
### TEST ###
test-dbg: MODARGS += --ipdb --capture=no
test-cov: MODARGS += --cov $(NM) --cov-report term-missing
test-lst: MODARGS += --collect-only
test-dbg test-cov test-lst: test-exec
test-exec: export PYTHONPATH += .
test-exec: export PYTEST_QT_API=pyqt5
test-exec:
py.test $(MODARGS) -- $(shell pwd) # python3 -m pytest my_file_test.py
### STYLE ###
style-lint: export PYTHONPATH += .
style-lint:
@pylint --reports=no --output-format=parseable \
--extension-pkg-whitelist=PyQt5 \
--disable=C0111,C0103,W0613 $(NM)
# W0232,E1101
style-pep: MODARGS += --first --statistics
style-more: MODARGS += --show-source --show-pep8
style-pep style-more:
@pep8 $(PEP8)
uml-png:
pyreverse -A -p $(NM) -o png $(PR) $(NM)
mv -f *.png /tmp
sxiv /tmp/*_piony.png 2>/dev/null
call-graph:
pycallgraph graphviz -- $(PR)
mv -f pycallgraph.png /tmp
sxiv /tmp/pycallgraph.png 2>/dev/null
# Compile resources in ascii binary
# SEE: pyqt4/examples/desktop/systray/systray.py
# res:
# pyrcc5 -o piony_rc.py piony.qrc
### SETUP ###
keys:
xbindkeys -mk
### USAGE ###
# ALT: {-B -- don't write .pyc}
clean:
find . -name "*.pyc" -exec rm {} \;
deploy:
@./scripts/deploy
log:
@./scripts/show-changelog
help:
@echo "Use one of those targets: $(TARGS)"