Skip to content

Commit

Permalink
Revamps Makfile, fixes #156
Browse files Browse the repository at this point in the history
- revamps Makefile
- simplifies .travis.yml
- ditch tox
  • Loading branch information
AndreMiras committed Dec 24, 2019
1 parent 77bd2b3 commit 4bf505b
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 110 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ venv/
.pytest_cache/
.tox/
bin/
*.pyc
**/__pycache__
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
- TAG=pywallet-linux DOCKERFILE=dockerfiles/Dockerfile-linux COMMAND='make test'
- TAG=pywallet-android DOCKERFILE=dockerfiles/Dockerfile-android COMMAND='buildozer android debug'

install:
before_script:
- docker build --tag=$TAG --file=$DOCKERFILE --build-arg TRAVIS .

script:
Expand Down
187 changes: 141 additions & 46 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,58 +1,153 @@
VENV_NAME=venv
ACTIVATE_PATH=$(VENV_NAME)/bin/activate
PIP=`. $(ACTIVATE_PATH); which pip`
TOX=`which tox`
GARDEN=$(VENV_NAME)/bin/garden
PYTHON=$(VENV_NAME)/bin/python
SYSTEM_DEPENDENCIES=virtualenv build-essential libpython3.6-dev \
libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev \
cmake python-numpy tox wget curl libssl-dev libzbar-dev \
xclip xsel
OS=$(shell lsb_release -si)
TMPDIR ?= /tmp
DOWNLOAD_DIR = $(TMPDIR)/downloads
KM_REPOSITORY=https://raw.githubusercontent.com/AndreMiras/km
KM_BRANCH=develop
OPENCV_MAKEFILE_NAME=Makefile.opencv
OPENCV_MAKEFILE_URL=$(KM_REPOSITORY)/$(KM_BRANCH)/attachments/$(OPENCV_MAKEFILE_NAME)


all: system_dependencies virtualenv

$(VENV_NAME):
test -d $(VENV_NAME) || virtualenv -p python3 $(VENV_NAME)
. $(VENV_NAME)/bin/activate
$(PIP) install Cython==0.26.1
$(PIP) install -r requirements/requirements.txt
$(GARDEN) install qrcode
$(GARDEN) install xcamera

virtualenv: $(VENV_NAME)
VIRTUAL_ENV ?= venv
ACTIVATE_PATH=$(VIRTUAL_ENV)/bin/activate
PIP=$(VIRTUAL_ENV)/bin/pip
PYTHON_MAJOR_VERSION=3
PYTHON_MINOR_VERSION=7
PYTHON_VERSION=$(PYTHON_MAJOR_VERSION).$(PYTHON_MINOR_VERSION)
PYTHON_MAJOR_MINOR=$(PYTHON_MAJOR_VERSION)$(PYTHON_MINOR_VERSION)
PYTHON_WITH_VERSION=python$(PYTHON_VERSION)
PYTHON=$(VIRTUAL_ENV)/bin/python
ISORT=$(VIRTUAL_ENV)/bin/isort
FLAKE8=$(VIRTUAL_ENV)/bin/flake8
PYTEST=$(VIRTUAL_ENV)/bin/pytest
COVERAGE=$(VIRTUAL_ENV)/bin/coverage
TWINE=`which twine`
SOURCES=src/
DOCKER_IMAGE_LINUX=andremiras/pywallet-linux
DOCKER_IMAGE_ANDROID=andremiras/pywallet-android
DOCKER_VOLUME=/tmp/.X11-unix:/tmp/.X11-unix
SYSTEM_DEPENDENCIES_BASE= \
libpython$(PYTHON_VERSION)-dev \
python$(PYTHON_VERSION)
SYSTEM_DEPENDENCIES_LINUX= \
build-essential \
libgl1 \
libzbar0 \
python$(PYTHON_MAJOR_VERSION)-virtualenv \
tox
SYSTEM_DEPENDENCIES_ANDROID= \
autoconf \
automake \
cmake \
gettext \
libffi-dev \
libltdl-dev \
git \
libssl-dev \
libtool \
openjdk-8-jdk-headless \
patch \
pkg-config \
python$(PYTHON_MAJOR_VERSION)-pip \
python$(PYTHON_MAJOR_VERSION)-setuptools \
unzip \
zlib1g-dev \
zip
ifndef CI
DOCKER_DEVICE=--device=/dev/video0:/dev/video0
DOCKER_IT=-it
endif

all: virtualenv

system_dependencies:
ifeq ($(OS), Ubuntu)
sudo apt install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES)
endif
apt update -qq > /dev/null && sudo apt -qq install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES_BASE)

$(DOWNLOAD_DIR):
mkdir --parents $(DOWNLOAD_DIR)
system_dependencies/linux: system_dependencies
apt update -qq > /dev/null && sudo apt -qq install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES_LINUX)

opencv_build: $(DOWNLOAD_DIR)
curl --location --progress-bar $(OPENCV_MAKEFILE_URL) \
--output $(DOWNLOAD_DIR)/$(OPENCV_MAKEFILE_NAME)
make --file $(DOWNLOAD_DIR)/$(OPENCV_MAKEFILE_NAME) VENV_NAME=$(VENV_NAME)
system_dependencies/android: system_dependencies
apt update -qq > /dev/null && sudo apt -qq install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES_ANDROID)

opencv_deploy: opencv_build virtualenv
make --file $(DOWNLOAD_DIR)/$(OPENCV_MAKEFILE_NAME) opencv_deploy VENV_NAME=$(VENV_NAME)
$(VIRTUAL_ENV):
virtualenv --python $(PYTHON_WITH_VERSION) $(VIRTUAL_ENV)
$(PIP) install Cython==0.28.6
$(PIP) install -r requirements.txt

opencv: opencv_deploy
virtualenv: $(VIRTUAL_ENV)

clean:
rm -rf $(VENV_NAME) .tox/ $(OPENCV_BASENAME)
run: virtualenv
$(PYTHON) src/main.py

test:
$(TOX)
pytest: virtualenv
$(COVERAGE) erase
$(COVERAGE) run -m unittest discover --start-directory=src/
$(COVERAGE) report

test: pytest lint
@if test -n "$$CI"; then make uitest; fi; \

uitest:
. $(ACTIVATE_PATH) && \
$(PYTHON) -m kivyunittest --folder src/tests/ui/ --pythonpath src/

lint/isort-check: virtualenv
$(ISORT) --check-only --recursive --diff $(SOURCES)

lint/isort-fix: virtualenv
$(ISORT) --recursive $(SOURCES)

lint/flake8: virtualenv
$(FLAKE8) $(SOURCES)

lint/mypy: virtualenv
# $(MYPY) --ignore-missing-imports $(shell find src/pywallet/ -name "*.py")

lint: lint/isort-check lint/flake8 lint/mypy

release/clean:
rm -rf dist/ build/

release/build: release/clean clean
$(PYTHON) setup.py sdist bdist_wheel
$(TWINE) check dist/*

release/upload:
$(TWINE) upload dist/*

clean:
rm -rf .pytest_cache/
find . -type d -name "__pycache__" -exec rm -r {} +
find . -type d -name "*.egg-info" -exec rm -r {} +

clean/venv: clean
rm -rf $(VIRTUAL_ENV)

buildozer/android/debug:
@if test -n "$$CI"; then sed 's/log_level = [0-9]/log_level = 1/' -i buildozer.spec; fi; \
buildozer android debug

docker/pull/linux:
docker pull $(DOCKER_IMAGE_LINUX):latest

docker/pull/android:
docker pull $(DOCKER_IMAGE_ANDROID):latest

docker/build/linux:
docker build --cache-from=$(DOCKER_IMAGE_LINUX) --tag=$(DOCKER_IMAGE_LINUX) --file=dockerfiles/Dockerfile-linux .

docker/build/android:
docker build --cache-from=$(DOCKER_IMAGE_ANDROID) --tag=$(DOCKER_IMAGE_ANDROID) --file=dockerfiles/Dockerfile-android .

docker/push/linux:
docker push $(DOCKER_IMAGE_LINUX)

docker/push/android:
docker push $(DOCKER_IMAGE_ANDROID)

docker/push: docker/push/linux docker/push/android

docker/run/test/linux:
docker run --env-file dockerfiles/env.list -v $(DOCKER_VOLUME) $(DOCKER_DEVICE) $(DOCKER_IT) --rm $(DOCKER_IMAGE_LINUX) make test

docker/run/test/android:
docker run --env-file dockerfiles/env.list $(DOCKER_IMAGE_ANDROID) make buildozer/android/debug

docker/run/app:
docker run --env-file dockerfiles/env.list -v $(DOCKER_VOLUME) $(DOCKER_DEVICE) -it --rm $(DOCKER_IMAGE_LINUX) make run

docker/run/shell/linux:
docker run --env-file dockerfiles/env.list -v $(DOCKER_VOLUME) $(DOCKER_DEVICE) -it --rm $(DOCKER_IMAGE_LINUX)

docker/run/shell/android:
docker run --env-file dockerfiles/env.list -v $(DOCKER_VOLUME) $(DOCKER_DEVICE) -it --rm $(DOCKER_IMAGE_ANDROID)
45 changes: 30 additions & 15 deletions dockerfiles/Dockerfile-linux
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Build with:
# docker build --tag=pywallet-linux --file=dockerfiles/Dockerfile-linux .
# Run with:
# docker run pywallet-linux /bin/sh -c 'make test'
# Or using the entry point shortcut:
# docker run pywallet-linux 'make test'
# Or for interactive shell:
# docker run -it --rm pywallet-linux
Expand All @@ -12,24 +10,41 @@
# - setup caching (for apt, and pip)
FROM ubuntu:18.04

ENV USER="user"
ENV HOME_DIR="/home/${USER}"
ENV WORK_DIR="${HOME_DIR}/app"

# configure locale
RUN apt update -qq > /dev/null && apt install --yes --no-install-recommends \
RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends \
locales && \
locale-gen en_US.UTF-8
locale-gen en_US.UTF-8 && \
rm -rf /var/lib/apt/lists/*
ENV LANG="en_US.UTF-8" \
LANGUAGE="en_US.UTF-8" \
LC_ALL="en_US.UTF-8"

# install system dependencies
RUN apt update -qq > /dev/null && apt install --yes --no-install-recommends \
make lsb-release sudo
# install minimal system dependencies
RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends \
make \
sudo \
&& rm -rf /var/lib/apt/lists/*

# prepare non root env, with sudo access and no password
RUN useradd --create-home --home-dir ${HOME_DIR} --shell /bin/bash ${USER} && \
usermod -append --groups sudo ${USER} && \
echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
mkdir ${WORK_DIR} && \
chown ${USER}:${USER} -R ${WORK_DIR}

# install kivy system dependencies
# https://kivy.org/docs/installation/installation-linux.html#dependencies-with-sdl2
RUN apt install --yes --no-install-recommends \
libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev
USER ${USER}
WORKDIR ${WORK_DIR}

# install system dependencies
COPY Makefile requirements.txt ${WORK_DIR}/
RUN sudo make system_dependencies/linux && \
make virtualenv && \
sudo rm ${WORK_DIR}/requirements.txt ${WORK_DIR}/Makefile && \
sudo rm -rf /var/lib/apt/lists/* && \
mkdir ~/.config

WORKDIR /app
COPY . /app
RUN make
ENTRYPOINT ["./dockerfiles/start.sh"]
COPY . ${WORK_DIR}
9 changes: 9 additions & 0 deletions dockerfiles/env.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# used by coveralls.io, refs:
# https://coveralls-python.readthedocs.io/en/latest/usage/tox.html#travisci
CI
TRAVIS
TRAVIS_BRANCH
TRAVIS_JOB_ID
TRAVIS_PULL_REQUEST
# used for running UI tests
DISPLAY
15 changes: 14 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
-r requirements/requirements.txt
coverage==4.4.1
flake8==3.3.0
isort==4.2.5
kivyunittest==0.1.8
eth-hash==0.1.1
eth-utils==1.4.1
https://github.com/AndreMiras/garden.layoutmargin/archive/20180517.tar.gz#egg=layoutmargin
https://github.com/AndreMiras/garden.zbarcam/archive/20190303.zip#egg=zbarcam
https://github.com/AndreMiras/KivyMD/archive/20181106.tar.gz#egg=kivymd
Kivy==1.11.1
Pillow==5.2.0
qrcode==5.3
raven==6.1.0
web3==4.8.1
10 changes: 0 additions & 10 deletions requirements/requirements.txt

This file was deleted.

6 changes: 0 additions & 6 deletions requirements/test_requirements.txt

This file was deleted.

31 changes: 0 additions & 31 deletions tox.ini

This file was deleted.

0 comments on commit 4bf505b

Please sign in to comment.