-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
180 lines (150 loc) · 5.9 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
168
169
170
171
172
173
174
175
176
177
178
179
.DEFAULT_GOAL = all
# Bash is needed for time, compgen, [[ and other builtin commands
SHELL := /bin/bash -o pipefail
RED := $(shell tput setaf 1)
GREEN := $(shell tput setaf 2)
NOCOLOR := $(shell tput sgr0)
PYTHON := python3
VENVDIR := $(CURDIR)/venv
VENVPIP := $(VENVDIR)/bin/python -m pip
VENVPYTHON := $(VENVDIR)/bin/python
# Module specific parameters
MODULE := emPreverb
MODULE_PARAMS :=
# These targets do not show as possible target with bash completion
__extra-deps:
# Do extra stuff (e.g. compiling, downloading) before building the package
@exit 0
.PHONY: __extra-deps
__clean-extra-deps:
# e.g. @rm -rf stuff
@exit 0
.PHONY: __clean-extra-deps
# From here only generic parts
# Parse version string and create new version. Originally from: https://github.com/mittelholcz/contextfun
# Variable is empty in Travis-CI if not git tag present
TRAVIS_TAG ?= ""
OLDVER := $$(grep -P -o "(?<=__version__ = ')[^']+" $(MODULE)/version.py)
MAJOR := $$(echo $(OLDVER) | sed -r s"/([0-9]+)\.([0-9]+)\.([0-9]+)/\1/")
MINOR := $$(echo $(OLDVER) | sed -r s"/([0-9]+)\.([0-9]+)\.([0-9]+)/\2/")
PATCH := $$(echo $(OLDVER) | sed -r s"/([0-9]+)\.([0-9]+)\.([0-9]+)/\3/")
NEWMAJORVER="$$(( $(MAJOR)+1 )).0.0"
NEWMINORVER="$(MAJOR).$$(( $(MINOR)+1 )).0"
NEWPATCHVER="$(MAJOR).$(MINOR).$$(( $(PATCH)+1 ))"
all: clean venv build install test
@echo
@echo "$(GREEN)Package $(MODULE) is successfully installed into venv and all tests are OK! :)$(NOCOLOR)"
@echo
install-dep-packages:
@echo "Installing needed packages from Aptfile..."
@command -v apt-get >/dev/null 2>&1 || \
(echo >&2 "$(RED)Command 'apt-get' could not be found!$(NOCOLOR)"; exit 1)
# Aptfile can be omited if empty
@[[ ! -f "$(CURDIR)/Aptfile" ]] || \
([[ $$(dpkg -l | grep -wcf $(CURDIR)/Aptfile) -eq $$(cat $(CURDIR)/Aptfile | wc -l) ]] || \
(sudo -E apt-get update && \
sudo -E apt-get -yq --no-install-suggests --no-install-recommends $(travis_apt_get_options) install \
`cat $(CURDIR)/Aptfile`))
@echo
@echo "$(GREEN)2/5 Needed packages are successfully installed!$(NOCOLOR)"
@echo
.PHONY: install-dep-packages
venv:
@echo "Creating virtualenv in $(VENVDIR)...$(NOCOLOR)"
@rm -rf $(VENVDIR)
@$(PYTHON) -m venv $(VENVDIR)
@$(VENVPIP) install wheel
@$(VENVPIP) install -r requirements-dev.txt
@echo
@echo "$(GREEN)1/5 Virtualenv is successfully created!$(NOCOLOR)"
@echo
.PHONY: venv
build: install-dep-packages venv __extra-deps
@echo "Building package..."
@[[ -z $$(compgen -G "dist/*.whl") && -z $$(compgen -G "dist/*.tar.gz") ]] || \
(echo -e "$(RED)dist/*.whl dist/*.tar.gz files exists.\nPlease use 'make clean' before build!$(NOCOLOR)"; \
exit 1)
@$(VENVPYTHON) setup.py sdist bdist_wheel
@echo
@echo "$(GREEN)3/5 Package $(MODULE) is successfully built!$(NOCOLOR)"
@echo
.PHONY: build
install: build
@echo "Installing package to user..."
$(VENVPIP) install --upgrade dist/*.whl
@echo
@echo "$(GREEN)4/5 Package $(MODULE) is successfully installed!$(NOCOLOR)"
@echo
.PHONY: install
test:
@echo "Running tests..."
@[[ $$(compgen -G "$(CURDIR)/tests/inputs/*.in") ]] || (echo "$(RED)No input testfiles found!$(NOCOLOR)"; exit 1)
r=0; \
for test_input in $(CURDIR)/tests/inputs/*.in; do \
test_output=$(CURDIR)/tests/outputs/$$(basename $${test_input%in}out) ; \
echo; \
time (cd /tmp && $(VENVPYTHON) -m $(MODULE) $(MODULE_PARAMS) -i $${test_input} | \
diff -sy --suppress-common-lines - $${test_output} 2>&1 | head -n100) || r=$($$r+$$?); \
done; \
[[ $$r == 0 ]] && echo && echo "$(GREEN)5/5 The test was completed successfully!$(NOCOLOR)" && echo || exit $$r
@echo "Comparing GIT TAG (\"$(TRAVIS_TAG)\") with package version (\"v$(OLDVER)\")..."
@[[ "$(TRAVIS_TAG)" == "v$(OLDVER)" || "$(TRAVIS_TAG)" == "" ]] && \
echo "$(GREEN)OK!$(NOCOLOR)" || \
(echo "$(RED)Versions do not match!$(NOCOLOR)"; exit 1)
.PHONY: test
uninstall:
@echo "Uninstalling..."
@[[ ! -d "$(VENVDIR)" || -z $$($(VENVPIP) list | grep -w $(MODULE)) ]] || $(VENVPIP) uninstall -y $(MODULE)
@echo "$(GREEN)Package $(MODULE) was uninstalled successfully!$(NOCOLOR)"
.PHONY: uninstall
clean: __clean-extra-deps
@rm -rf $(VENVDIR) dist/ build/ $(MODULE).egg-info/
.PHONY: clean
# Do actual release with new version. Originally from: https://github.com/mittelholcz/contextfun
release-major:
@make -s __release NEWVER=$(NEWMAJORVER)
.PHONY: release-major
release-minor:
@make -s __release NEWVER=$(NEWMINORVER)
.PHONY: release-minor
release-patch:
@make -s __release NEWVER=$(NEWPATCHVER)
.PHONY: release-patch
__release:
@[[ ! -z "$(NEWVER)" ]] || \
(echo -e "$(RED)Do not call this target!\nUse 'release-major', 'release-minor' or 'release-patch'!$(NOCOLOR)"; \
exit 1)
@[[ -z $$(git status --porcelain) ]] || (echo "$(RED)Working dir is dirty!$(NOCOLOR)"; exit 1)
@echo "NEW VERSION: $(NEWVER)"
# Clean install, test and tidy up
@make clean uninstall install test uninstall clean
@sed -i -r "s/__version__ = '$(OLDVER)'/__version__ = '$(NEWVER)'/" $(MODULE)/version.py
@git add $(MODULE)/version.py
@git commit -m "Release $(NEWVER)"
@git tag -a "v$(NEWVER)" -m "Release $(NEWVER)"
@git push
@git push --tags
.PHONY: __release
# ===== emPreverb-specific part
MODULE=emPreverb
FILE=11341_prev
INFILE=tests/inputs/$(FILE)
OUTFILE=tests/outputs/$(FILE)
.PHONY: connect_preverbs connect_preverbs_withcompound evaluate
# something like `make test`
connect_preverbs:
cat $(INFILE).in | python3 $(MODULE) > $(OUTFILE).out
# compound field is usually added by `compound` module
# and this module alters its value;
# here, for testing,
# a dummy compound field is added containing "?" value
connect_preverbs_withcompound:
cat $(INFILE)_withcompound.in | python3 $(MODULE) > $(OUTFILE)_withcompound.out
# ----- evaluation on `hungarian-preverb-corpus`
CORPUSREPO=hungarian-preverb-corpus
evaluate:
rm -rf $(CORPUSREPO)
git clone https://github.com/ril-lexknowrep/hungarian-preverb-corpus $(CORPUSREPO)
cd $(CORPUSREPO)/eval_anon && $(SHELL) evaluate.sh
clean-evaluate:
rm -rf $(CORPUSREPO)