Skip to content

Commit 7a761bd

Browse files
authored
Merge pull request #289 from bertsky/py38
make Python 3.8 work
2 parents ec5347f + 4de0f5c commit 7a761bd

File tree

4 files changed

+66
-14
lines changed

4 files changed

+66
-14
lines changed

.circleci/config.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@ jobs:
66
steps:
77
- checkout
88
- setup_remote_docker # https://circleci.com/docs/2.0/building-docker-images/
9-
- run: make docker-maximum-cuda DOCKER_PARALLEL=-j3
10-
- run:
11-
name: persist image
12-
command: docker image save ocrd/all:maximum-cuda > ocrd-all-maximum.tar
13-
no_output_timeout: 30m
14-
# can be downloaded from CircleCI.com and imported via "docker image load"
15-
- store_artifacts:
16-
path: ocrd-all-maximum.tar
17-
destination: artifacts
9+
- run: make docker-maximum-cuda
10+
- when:
11+
# takes too long for 1h1m CircleCI timeout overall
12+
condition: false
13+
steps:
14+
- run:
15+
name: persist image
16+
command: |
17+
sudo apt install pigz
18+
docker image save ocrd/all:maximum-cuda | pigz --fast > ocrd-all-maximum.tar.gz
19+
no_output_timeout: 30m
20+
# can be downloaded from CircleCI.com and imported via "docker image load"
21+
- store_artifacts:
22+
path: ocrd-all-maximum.tar.gz
23+
destination: artifacts
1824
deploy:
1925
docker:
2026
- image: circleci/buildpack-deps:stretch

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ ENV OCRD_MODULES="${OCRD_MODULES}"
6868
# (defaults to no extra options)
6969
ARG PIP_OPTIONS=""
7070

71+
# allow passing build-time parameter for Python version
72+
# (defaults to python3 in all modules)
73+
ARG PYTHON=python3
74+
7175
# build in parallel to speed up (but risk running into clashes
7276
# when not all dependencies have been correctly explicated):
7377
ARG PARALLEL=""

Makefile

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ PKG_CONFIG_PATH := $(VIRTUAL_ENV)/lib/pkgconfig:$(PKG_CONFIG_PATH)
5353
endif
5454
export PKG_CONFIG_PATH
5555

56+
SHELL = /bin/bash
57+
5658
OCRD_EXECUTABLES = $(BIN)/ocrd # add more CLIs below
5759
CUSTOM_DEPS = unzip wget python3-venv parallel git less # add more packages for deps-ubuntu below (or modules as preqrequisites)
5860

@@ -245,6 +247,7 @@ ifeq (0,$(MAKELEVEL))
245247
cor-asv-ann-check:
246248
$(MAKE) check OCRD_MODULES=cor-asv-ann VIRTUAL_ENV=$(SUB_VENV)/headless-tf1
247249
else
250+
$(pip_install_tf1nvidia)
248251
$(pip_install)
249252
endif
250253
endif
@@ -276,6 +279,7 @@ ifeq (0,$(MAKELEVEL))
276279
cor-asv-fst-check:
277280
$(MAKE) check OCRD_MODULES=cor-asv-fst VIRTUAL_ENV=$(SUB_VENV)/headless-tf1
278281
else
282+
$(pip_install_tf1nvidia)
279283
. $(ACTIVATE_VENV) && $(MAKE) -C $< deps
280284
$(pip_install)
281285
endif
@@ -292,6 +296,7 @@ ifeq (0,$(MAKELEVEL))
292296
ocrd_keraslm-check:
293297
$(MAKE) check OCRD_MODULES=ocrd_keraslm VIRTUAL_ENV=$(SUB_VENV)/headless-tf1
294298
else
299+
$(pip_install_tf1nvidia)
295300
$(pip_install)
296301
endif
297302
endif
@@ -362,6 +367,7 @@ ifeq (0,$(MAKELEVEL))
362367
ocrd_segment-check:
363368
$(MAKE) check OCRD_MODULES=ocrd_segment VIRTUAL_ENV=$(SUB_VENV)/headless-tf1
364369
else
370+
$(pip_install_tf1nvidia)
365371
$(pip_install)
366372
endif
367373
endif
@@ -481,10 +487,10 @@ OCRD_ANYBASEOCR += $(BIN)/ocrd-anybaseocr-textline
481487
OCRD_ANYBASEOCR += $(BIN)/ocrd-anybaseocr-layout-analysis
482488
$(call multirule,$(OCRD_ANYBASEOCR)): ocrd_anybaseocr
483489
ifeq (0,$(MAKELEVEL))
484-
$(MAKE) -B -o $< $(notdir $(OCRD_ANYBASEOCR)) VIRTUAL_ENV=$(SUB_VENV)/headless-tf21
485-
$(call delegate_venv,$(OCRD_ANYBASEOCR),$(SUB_VENV)/headless-tf21)
490+
$(MAKE) -B -o $< $(notdir $(OCRD_ANYBASEOCR)) VIRTUAL_ENV=$(SUB_VENV)/headless-tf2
491+
$(call delegate_venv,$(OCRD_ANYBASEOCR),$(SUB_VENV)/headless-tf2)
486492
ocrd_anybaseocr-check:
487-
$(MAKE) check OCRD_MODULES=ocrd_anybaseocr VIRTUAL_ENV=$(SUB_VENV)/headless-tf21
493+
$(MAKE) check OCRD_MODULES=ocrd_anybaseocr VIRTUAL_ENV=$(SUB_VENV)/headless-tf2
488494
else
489495
cd $< ; $(MAKE) patch-pix2pixhd
490496
$(pip_install)
@@ -528,6 +534,7 @@ ifeq (0,$(MAKELEVEL))
528534
sbb_binarization-check:
529535
$(MAKE) check OCRD_MODULES=sbb_binarization VIRTUAL_ENV=$(SUB_VENV)/headless-tf1
530536
else
537+
$(pip_install_tf1nvidia)
531538
$(pip_install)
532539
endif
533540
endif
@@ -546,6 +553,7 @@ ifeq (0,$(MAKELEVEL))
546553
sbb_textline_detector-check:
547554
$(MAKE) check OCRD_MODULES=sbb_textline_detector VIRTUAL_ENV=$(SUB_VENV)/headless-tf1
548555
else
556+
$(pip_install_tf1nvidia)
549557
$(pip_install)
550558
endif
551559
endif
@@ -564,6 +572,7 @@ ifeq (0,$(MAKELEVEL))
564572
eynollah-check:
565573
$(MAKE) check OCRD_MODULES=eynollah VIRTUAL_ENV=$(SUB_VENV)/headless-tf1
566574
else
575+
$(pip_install_tf1nvidia)
567576
$(pip_install)
568577
endif
569578
endif
@@ -601,6 +610,31 @@ define pip_install
601610
. $(ACTIVATE_VENV) && cd $< && $(SEMPIP) $(PIP) install $(PIP_OPTIONS_E) . && touch -c $@
602611
endef
603612

613+
# Workaround for missing prebuilt versions of TF<2 for Python==3.8
614+
# todo: find another solution for 3.9, 3.10 etc
615+
# Nvidia has them, but under a different name, so let's rewrite that:
616+
define pip_install_tf1nvidia =
617+
. $(ACTIVATE_VENV) && if ! $(PYTHON) -c "import sys; sys.exit(sys.version_info.major==3 and sys.version_info.minor==8)" && ! $(PIP) show -q tensorflow-gpu; then \
618+
$(PIP) install nvidia-pyindex && \
619+
pushd $$(mktemp -d) && \
620+
$(PIP) download --no-deps nvidia-tensorflow && \
621+
for name in nvidia_tensorflow-*.whl; do name=$${name%.whl}; done && \
622+
$(PYTHON) -m wheel unpack $$name.whl && \
623+
for name in nvidia_tensorflow-*/; do name=$${name%/}; done && \
624+
newname=$${name/nvidia_tensorflow/tensorflow_gpu} &&\
625+
sed -i s/nvidia_tensorflow/tensorflow_gpu/g $$name/$$name.dist-info/METADATA && \
626+
sed -i s/nvidia_tensorflow/tensorflow_gpu/g $$name/$$name.dist-info/RECORD && \
627+
sed -i s/nvidia_tensorflow/tensorflow_gpu/g $$name/tensorflow_core/tools/pip_package/setup.py && \
628+
pushd $$name && for path in $$name*; do mv $$path $${path/$$name/$$newname}; done && popd && \
629+
$(PYTHON) -m wheel pack $$name && \
630+
$(PIP) install $$newname*.whl && popd && rm -fr $$OLDPWD; fi && \
631+
$(PIP) install imageio==2.4.1 && \
632+
$(PIP) install "tifffile<2022"
633+
endef
634+
# last recipe 2 lines:
635+
# - preempt conflict over numpy between scikit-image and tensorflow
636+
# - preempt conflict over numpy between tifffile and tensorflow
637+
604638
# pattern for recursive make:
605639
# $(executables...): module...
606640
# ifeq (0,$(MAKELEVEL))
@@ -794,13 +828,20 @@ clean-tesseract:
794828
deps-ubuntu:
795829
apt-get update
796830
apt-get -y install git parallel
831+
ifneq ($(suffix $(PYTHON)),)
832+
# install specific Python version in system via PPA
833+
apt-get install -y software-properties-common
834+
add-apt-repository -y ppa:deadsnakes/ppa
835+
apt-get update
836+
apt-get install -y --no-install-recommends $(notdir $(PYTHON))-dev $(notdir $(PYTHON))-venv
837+
endif
797838
$(MAKE) deps-ubuntu-modules
798839
chown -R --reference=$(CURDIR) .git $(OCRD_MODULES)
799840
# prevent the sem commands during above module updates from imposing sudo perms on HOME:
800841
chown -R --reference=$(HOME) $(HOME)/.parallel
801842

802843
deps-ubuntu-modules:
803-
set -e; for dir in $^; do $(MAKE) -C $$dir deps-ubuntu; done
844+
set -e; for dir in $^; do $(MAKE) -C $$dir deps-ubuntu PYTHON=$(PYTHON) PIP=$(PIP); done
804845
apt-get -y install $(CUSTOM_DEPS)
805846

806847
.PHONY: deps-ubuntu deps-ubuntu-modules
@@ -845,6 +886,7 @@ docker%: Dockerfile $(DOCKER_MODULES)
845886
--build-arg OCRD_MODULES="$(DOCKER_MODULES)" \
846887
--build-arg PIP_OPTIONS="$(PIP_OPTIONS)" \
847888
--build-arg PARALLEL="$(DOCKER_PARALLEL)" \
889+
--build-arg PYTHON="$(PYTHON)" \
848890
-t $(DOCKER_TAG):$(or $(*:-%=%),latest) .
849891

850892

0 commit comments

Comments
 (0)