forked from sebastien/extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
167 lines (134 loc) · 3.87 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
PYTHON=python
PATH_SOURCES_PY=src/py
PYTHON_MODULES=$(patsubst src/py/%,%,$(wildcard src/py/*))
SOURCES_BIN:=$(wildcard bin/*)
SOURCES_PY:=$(wildcard $(PATH_SOURCES_PY)/*.py $(PATH_SOURCES_PY)/*/*.py $(PATH_SOURCES_PY)/*/*/*.py $(PATH_SOURCES_PY)/*/*/*/*.py)
MODULES_PY:=$(filter-out %/__main__,$(filter-out %/__init__,$(SOURCES_PY:$(PATH_SOURCES_PY)/%.py=%)))
PATH_LOCAL_PY=$(firstword $(shell python -c "import sys,pathlib;sys.stdout.write(' '.join([_ for _ in sys.path if _.startswith(str(pathlib.Path.home()))] ))"))
PATH_LOCAL_BIN=$(HOME)/.local/bin
REQUIRE_PY=flake8 bandit mypy
PREP_ALL=$(REQUIRE_PY:%=build/require-py-%.task)
# Commands
BANDIT=python -m bandit
FLAKE8=python -m flake8
MYPY=python -m mypy
MYPYC=mypyc
cmd-check=if ! $$(which $1 &> /dev/null ); then echo "ERR Could not find command $1"; exit 1; fi; $1
.PHONY: prep
prep: $(PREP_ALL)
@
.PHONY: run
run:
@
.PHONY: ci
ci: check test
@
.PHONY: audit
audit: check-bandit
@echo "=== $@"
# NOTE: The compilation seems to create many small modules instead of a big single one
.PHONY: compile
compile:
@echo "=== $@"
echo "Compiling $(MODULES_PY): $(SOURCES_PY)"
# NOTE: Output is going to be like 'extra/__init__.cpython-310-x86_64-linux-gnu.so'
mkdir -p "build"
$(foreach M,$(MODULES_PY),mkdir -p build/$M;)
env -C build MYPYPATH=$(realpath .)/src/py mypyc -p extra
.PHONY: check
check: check-bandit check-flakes check-strict
echo "=== $@"
.PHONY: check-compiled
check-compiled:
@
echo "=== $@"
COMPILED=$$(PYTHONPATH=build python -c "import extra;print(extra)")
echo "Extra compiled at: $$COMPILED"
.PHONY: check-bandit
check-bandit: $(PREP_ALL)
@echo "=== $@"
$(BANDIT) -r -s B101 src/py/coda
.PHONY: check-flakes
check-flakes: $(PREP_ALL)
@echo "=== $@"
$(FLAKE8) --ignore=E1,E203,E302,E401,E501,E704,E741,E266,F821,W $(SOURCES_PY)
.PHONY: check-mypyc
check-mypyc: $(PREP_ALL)
@$(call cmd-check,mypyc) $(SOURCES_PY)
.PHONY: check-strict
check-strict: $(PREP_ALL)
@
count_ok=0
count_err=0
files_err=
for item in $(SOURCES_PY); do
if $(MYPY) --strict $$item; then
count_ok=$$(($$count_ok+1))
else
count_err=$$(($$count_err+1))
files_err+=" $$item"
fi
done
summary="OK $$count_ok ERR $$count_err TOTAL $$(($$count_err + $$count_ok))"
if [ "$$count_err" != "0" ]; then
for item in $$files_err; do
echo "ERR $$item"
done
echo "EOS FAIL $$summary"
exit 1
else
echo "EOS OK $$summary"
fi
.PHONY: lint
lint: check-flakes
@
.PHONY: format
format:
@black $(SOURCES_PY)
.PHONY: install
install:
@for file in $(SOURCES_BIN); do
echo "Installing $(PATH_LOCAL_BIN)/$$(basename $$file)"
ln -sfr $$file "$(PATH_LOCAL_BIN)/$$(basename $$file)"
mkdir -p "$(PATH_LOCAL_BIN)"
done
if [ ! -e "$(PATH_LOCAL_PY)" ]; then
mkdir -p "$(PATH_LOCAL_PY)"
fi
if [ -d "$(PATH_LOCAL_PY)" ]; then
for module in $(PYTHON_MODULES); do
echo "Installing $(PATH_LOCAL_PY)/$$module"
ln -sfr src/py/$$module "$(PATH_LOCAL_PY)"/$$module
done
else
echo "No local Python module path found: $(PATH_LOCAL_PY)"
fi
.PHONY: try-install
try-uninstall:
@for file in $(SOURCES_BIN); do
unlink $(PATH_LOCAL_BIN)/$$(basename $$file)
done
if [ -s "$(PATH_LOCAL_PY)" ]; then
for module in $(PYTHON_MODULES); do
unlink "$(PATH_LOCAL_PY)"/$$module
done
fi
build/require-py-%.task:
@
if $(PYTHON) -mpip install --user --upgrade '$*'; then
mkdir -p "$(dir $@)"
touch "$@"
fi
data/csic_2010-normalTrafficTraining.txt:
curl -o "$@" 'https://gitlab.fing.edu.uy/gsi/web-application-attacks-datasets/-/raw/master/csic_2010/normalTrafficTest.txt?inline=false'
data/csic_2010-anomalousTrafficTraining.txt:
curl -o "$@" 'https://gitlab.fing.edu.uy/gsi/web-application-attacks-datasets/-/raw/master/csic_2010/anomalousTrafficTest.txt?inline=false'
print-%:
$(info $*=$($*))
.ONESHELL:
# EOF
#