-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
253 lines (204 loc) · 7.38 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
export
SHELL = /bin/bash
PYTHON = python
PIP = pip
LOG_LEVEL = INFO
PYTHONIOENCODING=utf8
TESTDIR = tests
SPHINX_APIDOC =
BUILD_ORDER = ocrd_utils ocrd_models ocrd_modelfactory ocrd_validators ocrd
FIND_VERSION = grep version= ocrd_utils/setup.py|grep -Po "([0-9ab]+\.?)+"
# BEGIN-EVAL makefile-parser --make-help Makefile
help:
@echo ""
@echo " Targets"
@echo ""
@echo " deps-ubuntu Dependencies for deployment in an ubuntu/debian linux"
@echo " deps-test Install test python deps via pip"
@echo " install (Re)install the tool"
@echo " install-dev Install with pip install -e"
@echo " uninstall Uninstall the tool"
@echo " generate-page Regenerate python code from PAGE XSD"
@echo " spec Copy JSON Schema, OpenAPI from OCR-D/spec"
@echo " assets Setup test assets"
@echo " test Run all unit tests"
@echo " docs Build documentation"
@echo " docs-clean Clean docs"
@echo " docs-coverage Calculate docstring coverage"
@echo " docker Build docker image"
@echo " docker-cuda Build docker GPU / CUDA image"
@echo " cuda-ubuntu Install native CUDA toolkit in different versions"
@echo " pypi Build wheels and source dist and twine upload them"
@echo ""
@echo " Variables"
@echo ""
@echo " DOCKER_TAG Docker tag. Default: '$(DOCKER_TAG)'."
@echo " DOCKER_BASE_IMAGE Docker base image. Default: '$(DOCKER_BASE_IMAGE)'."
@echo " DOCKER_ARGS Additional arguments to docker build. Default: '$(DOCKER_ARGS)'"
@echo " PIP_INSTALL pip install command. Default: $(PIP_INSTALL)"
# END-EVAL
# Docker tag. Default: '$(DOCKER_TAG)'.
DOCKER_TAG = ocrd/core
# Docker base image. Default: '$(DOCKER_BASE_IMAGE)'.
DOCKER_BASE_IMAGE = ubuntu:18.04
# Additional arguments to docker build. Default: '$(DOCKER_ARGS)'
DOCKER_ARGS =
# pip install command. Default: $(PIP_INSTALL)
PIP_INSTALL = pip install
# Dependencies for deployment in an ubuntu/debian linux
deps-ubuntu:
apt-get install -y python3 imagemagick libgeos-dev
# Install test python deps via pip
deps-test:
$(PIP) install -U pip
$(PIP) install -r requirements_test.txt
# (Re)install the tool
install:
$(PIP) install -U pip wheel setuptools fastentrypoints
for mod in $(BUILD_ORDER);do (cd $$mod ; $(PIP_INSTALL) .);done
@# workaround for shapely#1598
$(PIP) install --no-binary shapely --force-reinstall shapely
# Install with pip install -e
install-dev: uninstall
$(MAKE) install PIP_INSTALL="pip install -e"
# Uninstall the tool
uninstall:
for mod in $(BUILD_ORDER);do pip uninstall -y $$mod;done
# Regenerate python code from PAGE XSD
generate-page: GDS_PAGE = ocrd_models/ocrd_models/ocrd_page_generateds.py
generate-page: GDS_PAGE_USER = ocrd_models/ocrd_page_user_methods.py
generate-page: repo/assets
generateDS \
-f \
--root-element='PcGts' \
-o $(GDS_PAGE) \
--silence \
--export "write etree" \
--disable-generatedssuper-lookup \
--user-methods=$(GDS_PAGE_USER) \
ocrd_validators/ocrd_validators/page.xsd
# hack to prevent #451: enum keys will be strings
sed -i 's/(Enum):$$/(str, Enum):/' $(GDS_PAGE)
# hack to ensure output has pc: prefix
@#sed -i "s/namespaceprefix_=''/namespaceprefix_='pc:'/" $(GDS_PAGE)
sed -i 's/_nsprefix_ = None/_nsprefix_ = "pc"/' $(GDS_PAGE)
# hack to ensure child nodes also have pc: prefix...
sed -i 's/.*_nsprefix_ = child_.prefix$$//' $(GDS_PAGE)
# replace the need for six since we target python 3.6+
sed -i 's/from six.moves/from itertools/' $(GDS_PAGE)
#
# Repos
#
.PHONY: repos always-update
repos: repo/assets repo/spec
# Update OCR-D/assets and OCR-D/spec resp.
repo/assets repo/spec: always-update
git submodule sync --recursive $@
if git submodule status --recursive $@ | grep -qv '^ '; then \
git submodule update --init --recursive $@ && \
touch $@; \
fi
#
# Spec
#
.PHONY: spec
# Copy JSON Schema, OpenAPI from OCR-D/spec
spec: repo/spec
cp repo/spec/ocrd_tool.schema.yml ocrd_validators/ocrd_validators/ocrd_tool.schema.yml
cp repo/spec/bagit-profile.yml ocrd_validators/ocrd_validators/bagit-profile.yml
#
# Assets
#
# Setup test assets
assets: repo/assets
rm -rf $(TESTDIR)/assets
mkdir -p $(TESTDIR)/assets
cp -r repo/assets/data/* $(TESTDIR)/assets
#
# Tests
#
.PHONY: test
# Run all unit tests
test: assets
HOME=$(CURDIR)/ocrd_utils $(PYTHON) -m pytest --continue-on-collection-errors -k TestLogging $(TESTDIR)
HOME=$(CURDIR) $(PYTHON) -m pytest --continue-on-collection-errors -k TestLogging $(TESTDIR)
$(PYTHON) -m pytest --continue-on-collection-errors --durations=10 --ignore=$(TESTDIR)/test_logging.py --ignore-glob="$(TESTDIR)/**/*bench*.py" $(TESTDIR)
benchmark:
$(PYTHON) -m pytest $(TESTDIR)/model/test_ocrd_mets_bench.py
benchmark-extreme:
$(PYTHON) -m pytest $(TESTDIR)/model/*bench*.py
test-profile:
$(PYTHON) -m cProfile -o profile $$(which pytest)
$(PYTHON) analyze_profile.py
coverage: assets
coverage erase
make test PYTHON="coverage run"
coverage report
coverage html
#
# Documentation
#
.PHONY: docs
# Build documentation
docs:
for mod in $(BUILD_ORDER);do sphinx-apidoc -f -M -e \
-o docs/api/$$mod $$mod/$$mod \
'ocrd_models/ocrd_models/ocrd_page_generateds.py' \
;done
cd docs ; $(MAKE) html
docs-push: gh-pages docs
cp -r docs/build/html/* gh-pages
cd gh-pages; git add . && git commit -m 'Updated docs $$(date)' && git push
# Clean docs
docs-clean:
cd gh-pages ; rm -rf *
cd docs ; rm -rf _build api/ocrd api/ocrd_*
# Calculate docstring coverage
docs-coverage:
for mod in $(BUILD_ORDER);do docstr-coverage $$mod/$$mod -e '.*(ocrd_page_generateds|/ocrd/cli/).*';done
for mod in $(BUILD_ORDER);do echo "# $$mod"; docstr-coverage -v1 $$mod/$$mod -e '.*(ocrd_page_generateds|/ocrd/cli/).*'|sed 's/^/\t/';done
gh-pages:
git clone --branch gh-pages https://github.com/OCR-D/core gh-pages
#
# Clean up
#
pyclean:
rm -f **/*.pyc
find . -name '__pycache__' -exec rm -rf '{}' \;
rm -rf .pytest_cache
#
# Docker
#
.PHONY: docker docker-cuda
# Build docker image
docker docker-cuda:
docker build -t $(DOCKER_TAG) --build-arg BASE_IMAGE=$(DOCKER_BASE_IMAGE) $(DOCKER_ARGS) .
# Build docker GPU / CUDA image
docker-cuda: DOCKER_BASE_IMAGE = nvidia/cuda:11.3.1-cudnn8-runtime-ubuntu18.04
docker-cuda: DOCKER_TAG = ocrd/core-cuda
docker-cuda: DOCKER_ARGS += --build-arg FIXUP="make cuda-ubuntu cuda-ldconfig"
#
# CUDA
#
.PHONY: cuda-ubuntu cuda-ldconfig
# Install native CUDA toolkit in different versions
cuda-ubuntu: cuda-ldconfig
apt-get -y install --no-install-recommends cuda-runtime-10-0 cuda-runtime-10-1 cuda-runtime-10-2 cuda-runtime-11-0 cuda-runtime-11-1 cuda-runtime-11-3 libcudnn7
cuda-ldconfig: /etc/ld.so.conf.d/cuda.conf
ldconfig
/etc/ld.so.conf.d/cuda.conf:
@echo > $@
@echo /usr/local/cuda-10.0/lib64 >> $@
@echo /usr/local/cuda-10.0/targets/x86_64-linux/lib >> $@
@echo /usr/local/cuda-10.1/lib64 >> $@
@echo /usr/local/cuda-10.1/targets/x86_64-linux/lib >> $@
@echo /usr/local/cuda-10.2/lib64 >> $@
@echo /usr/local/cuda-10.2/targets/x86_64-linux/lib >> $@
@echo /usr/local/cuda-11.0/lib64 >> $@
@echo /usr/local/cuda-11.0/targets/x86_64-linux/lib >> $@
@echo /usr/local/cuda-11.1/lib64 >> $@
@echo /usr/local/cuda-11.1/targets/x86_64-linux/lib >> $@
# Build wheels and source dist and twine upload them
pypi: uninstall install
for mod in $(BUILD_ORDER);do (cd $$mod; $(PYTHON) setup.py sdist bdist_wheel);done
version=`$(FIND_VERSION)`; twine upload ocrd*/dist/ocrd*$$version*{tar.gz,whl}