From 18236b1d41af7dc06387a676d57634e2b7382cb5 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 15 Sep 2019 14:25:10 +0200 Subject: [PATCH 01/13] More adaptive virtualenv check, credit @darosior Makes it possible to run from already created/activated virtualenv. Activated virtualenv sets `VIRTUAL_ENV` variable. This variable contains the full path virtualenv directory, refs: https://github.com/kivy-garden/garden.zbarcam/pull/40 Co-authored-by: @darosoir --- Makefile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 9b92db2..263a042 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ -VENV_NAME=venv -PIP=$(VENV_NAME)/bin/pip +VIRTUAL_ENV ?= venv +PIP=$(VIRTUAL_ENV)/bin/pip TOX=`which tox` -GARDEN=$(VENV_NAME)/bin/garden -PYTHON=$(VENV_NAME)/bin/python -ISORT=$(VENV_NAME)/bin/isort -FLAKE8=$(VENV_NAME)/bin/flake8 +GARDEN=$(VIRTUAL_ENV)/bin/garden +PYTHON=$(VIRTUAL_ENV)/bin/python +ISORT=$(VIRTUAL_ENV)/bin/isort +FLAKE8=$(VIRTUAL_ENV)/bin/flake8 TWINE=`which twine` SOURCES=src/ tests/ setup.py setup_meta.py # using full path so it can be used outside the root dir @@ -25,10 +25,10 @@ PYTHON_WITH_VERSION=python$(PYTHON_VERSION) all: system_dependencies virtualenv -venv: - test -d venv || virtualenv -p $(PYTHON_WITH_VERSION) venv +$(VIRTUAL_ENV): + virtualenv -p $(PYTHON_WITH_VERSION) $(VIRTUAL_ENV) -virtualenv: venv +virtualenv: $(VIRTUAL_ENV) $(PIP) install Cython==0.28.6 $(PIP) install -r requirements/requirements.txt @@ -85,4 +85,4 @@ clean: release/clean docs/clean find src/ -type d -name "*.egg-info" -exec rm -r {} + clean/all: clean - rm -rf $(VENV_NAME) .tox/ + rm -rf $(VIRTUAL_ENV) .tox/ From e5be9c54ebea476c45cdddb50e62697f3bb9657f Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 29 Sep 2019 01:15:52 +0200 Subject: [PATCH 02/13] Dockerfile & Makefile improvements - uses `Makefile` as single source of truth for dependencies - adds `docker/build`, `docker/run/test` and other docker targets --- Makefile | 42 ++++++++++++++++++++++++++++++------ dockerfiles/Dockerfile-linux | 24 ++++----------------- dockerfiles/env.list | 9 ++++++++ 3 files changed, 48 insertions(+), 27 deletions(-) create mode 100644 dockerfiles/env.list diff --git a/Makefile b/Makefile index 263a042..e854846 100644 --- a/Makefile +++ b/Makefile @@ -11,20 +11,41 @@ SOURCES=src/ tests/ setup.py setup_meta.py SPHINXBUILD=$(shell realpath venv/bin/sphinx-build) DOCS_DIR=doc SYSTEM_DEPENDENCIES= \ - libpython$(PYTHON_VERSION)-dev \ + build-essential \ + ccache \ + cmake \ + curl \ libsdl2-dev \ + libsdl2-image-dev \ + libsdl2-mixer-dev \ + libsdl2-ttf-dev \ + libpython3.6-dev \ + libpython$(PYTHON_VERSION)-dev \ libzbar-dev \ + lsb-release \ + make \ + pkg-config \ + python3.6 \ + python3.6-dev \ + python$(PYTHON_VERSION) \ + python$(PYTHON_VERSION)-dev \ + sudo \ tox \ virtualenv OS=$(shell lsb_release -si) PYTHON_MAJOR_VERSION=3 -PYTHON_MINOR_VERSION=6 +PYTHON_MINOR_VERSION=7 PYTHON_VERSION=$(PYTHON_MAJOR_VERSION).$(PYTHON_MINOR_VERSION) PYTHON_WITH_VERSION=python$(PYTHON_VERSION) all: system_dependencies virtualenv +system_dependencies: +ifeq ($(OS), Ubuntu) + sudo apt install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES) +endif + $(VIRTUAL_ENV): virtualenv -p $(PYTHON_WITH_VERSION) $(VIRTUAL_ENV) @@ -35,11 +56,6 @@ virtualenv: $(VIRTUAL_ENV) virtualenv/test: virtualenv $(PIP) install -r requirements/requirements-test.txt -system_dependencies: -ifeq ($(OS), Ubuntu) - sudo apt install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES) -endif - run/linux: virtualenv $(PYTHON) src/main.py @@ -86,3 +102,15 @@ clean: release/clean docs/clean clean/all: clean rm -rf $(VIRTUAL_ENV) .tox/ + +docker/build: + docker build --tag=zbarcam-linux --file=dockerfiles/Dockerfile-linux . + +docker/run/test: + docker run --env-file dockerfiles/env.list -v /tmp/.X11-unix:/tmp/.X11-unix zbarcam-linux 'make test' + +docker/run/app: + docker run --env-file dockerfiles/env.list -v /tmp/.X11-unix:/tmp/.X11-unix --device=/dev/video0:/dev/video0 zbarcam-linux 'make run' + +docker/run/shell: + docker run --env-file dockerfiles/env.list -v /tmp/.X11-unix:/tmp/.X11-unix --device=/dev/video0:/dev/video0 -it --rm zbarcam-linux diff --git a/dockerfiles/Dockerfile-linux b/dockerfiles/Dockerfile-linux index 237f39c..822fa4d 100644 --- a/dockerfiles/Dockerfile-linux +++ b/dockerfiles/Dockerfile-linux @@ -26,37 +26,21 @@ ENV LANG="en_US.UTF-8" \ # install system dependencies RUN apt install --yes --no-install-recommends \ - build-essential \ - ccache \ - cmake \ - curl \ - libsdl2-dev \ - libsdl2-image-dev \ - libsdl2-mixer-dev \ - libsdl2-ttf-dev \ - libpython3.6-dev \ - libpython3.7-dev \ - libzbar-dev \ lsb-release \ make \ - pkg-config \ - python3.6 \ - python3.6-dev \ - python3.7 \ - python3.7-dev \ - sudo \ - tox \ - virtualenv + sudo # prepare non root env RUN useradd --create-home --shell /bin/bash ${USER} # with sudo access and no password RUN usermod -append --groups sudo ${USER} RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +# gives access to video so the camera can be accessed within the container +RUN gpasswd --add ${USER} video USER ${USER} WORKDIR ${WORK_DIR} COPY . ${WORK_DIR} -RUN make +RUN sudo make system_dependencies && make virtualenv ENTRYPOINT ["./dockerfiles/start.sh"] diff --git a/dockerfiles/env.list b/dockerfiles/env.list new file mode 100644 index 0000000..732d46e --- /dev/null +++ b/dockerfiles/env.list @@ -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 From 437fe4f5aeef79123b2848ef034cd37951d96500 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 29 Sep 2019 11:03:29 +0200 Subject: [PATCH 03/13] Migrates to xcamera==2019.928 Last version of `xcamera` has built-in permission check support. --- Makefile | 4 +-- buildozer.spec | 2 +- requirements/requirements.txt | 2 +- setup.py | 2 +- src/kivy_garden/zbarcam/utils.py | 23 ---------------- src/kivy_garden/zbarcam/zbarcam.kv | 3 +- src/kivy_garden/zbarcam/zbarcam.py | 44 ++---------------------------- 7 files changed, 8 insertions(+), 72 deletions(-) diff --git a/Makefile b/Makefile index e854846..9531e35 100644 --- a/Makefile +++ b/Makefile @@ -56,11 +56,9 @@ virtualenv: $(VIRTUAL_ENV) virtualenv/test: virtualenv $(PIP) install -r requirements/requirements-test.txt -run/linux: virtualenv +run: virtualenv $(PYTHON) src/main.py -run: run/linux - test: $(TOX) diff --git a/buildozer.spec b/buildozer.spec index 28aed95..16997e2 100644 --- a/buildozer.spec +++ b/buildozer.spec @@ -44,7 +44,7 @@ requirements = Pillow==5.2.0, python3, pyzbar==0.1.8, - xcamera + xcamera==2019.928 # (str) Custom source folders for requirements diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 4fcf674..63affbd 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -4,4 +4,4 @@ numpy==1.16.1 opencv-python==4.1.1.26 Pillow==5.2.0 pyzbar==0.1.8 -xcamera +xcamera==2019.928 diff --git a/setup.py b/setup.py index b11d386..72dcb95 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ def read(fname): 'opencv-python>=4', 'pillow', 'pyzbar', - 'xcamera', + 'xcamera>=2019.928', ], } diff --git a/src/kivy_garden/zbarcam/utils.py b/src/kivy_garden/zbarcam/utils.py index 3164f18..f1f6a53 100644 --- a/src/kivy_garden/zbarcam/utils.py +++ b/src/kivy_garden/zbarcam/utils.py @@ -10,29 +10,6 @@ def is_ios(): return platform == 'ios' -def check_camera_permission(): - """ - Android runtime `CAMERA` permission check. - """ - if not is_android(): - return True - from android.permissions import Permission, check_permission - permission = Permission.CAMERA - return check_permission(permission) - - -def check_request_camera_permission(callback=None): - """ - Android runtime `CAMERA` permission check & request. - """ - had_permission = check_camera_permission() - if not had_permission: - from android.permissions import Permission, request_permissions - permissions = [Permission.CAMERA] - request_permissions(permissions, callback) - return had_permission - - def fix_android_image(pil_image): """ On Android, the image seems mirrored and rotated somehow, refs #32. diff --git a/src/kivy_garden/zbarcam/zbarcam.kv b/src/kivy_garden/zbarcam/zbarcam.kv index 80a5d6e..2a077ff 100644 --- a/src/kivy_garden/zbarcam/zbarcam.kv +++ b/src/kivy_garden/zbarcam/zbarcam.kv @@ -1,10 +1,11 @@ +#:import XCamera kivy_garden.xcamera.XCamera #:import is_android kivy_garden.zbarcam.utils.is_android : Widget: # invert width/height on rotated Android # https://stackoverflow.com/a/45192295/185510 id: proxy - CustomXCamera: + XCamera: id: xcamera play: True resolution: root.resolution diff --git a/src/kivy_garden/zbarcam/zbarcam.py b/src/kivy_garden/zbarcam/zbarcam.py index a138dde..1d85e7e 100644 --- a/src/kivy_garden/zbarcam/zbarcam.py +++ b/src/kivy_garden/zbarcam/zbarcam.py @@ -2,57 +2,17 @@ from collections import namedtuple import PIL -from kivy.clock import Clock, mainthread +from kivy.clock import Clock from kivy.lang import Builder from kivy.properties import ListProperty from kivy.uix.anchorlayout import AnchorLayout -from kivy_garden.xcamera import XCamera from pyzbar import pyzbar -from .utils import check_request_camera_permission, fix_android_image +from .utils import fix_android_image MODULE_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) -class CustomXCamera(XCamera): - """ - Inherits from `kivy_garden.xcamera.XCamera`. - Overrides `_on_index()` to make sure the `kivy.core.camera.Camera` object - is only created if permission are granted on Android. - On other system, it's a noop calling the parent `_on_index()`. - """ - - def __init__(self, **kwargs): - self.register_event_type('on_camera_ready') - super().__init__(**kwargs) - - def _on_index(self, *largs): - """ - Overrides `kivy.uix.camera.Camera._on_index()` to make sure - `camera.open()` is not called unless Android `CAMERA` permission is - granted, refs #12. - """ - @mainthread - def on_permissions_callback(permissions, grant_results): - """ - On camera permission callback calls parent `_on_index()` method. - """ - if all(grant_results): - self._on_index_dispatch(*largs) - if check_request_camera_permission(callback=on_permissions_callback): - self._on_index_dispatch(*largs) - - def _on_index_dispatch(self, *largs): - super()._on_index(*largs) - self.dispatch('on_camera_ready') - - def on_camera_ready(self): - """ - Fired when the camera is ready. - """ - pass - - class ZBarCam(AnchorLayout): """ Widget that use the Camera and zbar to detect qrcode. From 223c67b2e0611b54b923c869d8c7db4c6ca4cfde Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 29 Sep 2019 20:53:32 +0200 Subject: [PATCH 04/13] Disables buildozer build Broken via https://github.com/kivy/python-for-android/pull/1986 --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ec4490e..da39213 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,9 @@ env: - DISPLAY=:99.0 matrix: - TAG=zbarcam-linux DOCKERFILE=dockerfiles/Dockerfile-linux COMMAND='make test' - - TAG=zbarcam-linux DOCKERFILE=dockerfiles/Dockerfile-linux COMMAND='make uitest' - - TAG=zbarcam-android DOCKERFILE=dockerfiles/Dockerfile-android COMMAND='buildozer android debug' + # broken in: + # https://github.com/kivy/python-for-android/pull/1986 + # - TAG=zbarcam-android DOCKERFILE=dockerfiles/Dockerfile-android COMMAND='buildozer android debug' before_install: - sudo apt update -qq > /dev/null From 42f380a86ae0233135cec9766a59617120dff6ec Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 29 Sep 2019 20:55:16 +0200 Subject: [PATCH 05/13] Updates Makefile - improves OS detection when `lsb_release` binary is not available - starts removing dedicated `uitest` target (will be merged in `test`) --- Makefile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 9531e35..7880f7b 100644 --- a/Makefile +++ b/Makefile @@ -29,10 +29,9 @@ SYSTEM_DEPENDENCIES= \ python3.6-dev \ python$(PYTHON_VERSION) \ python$(PYTHON_VERSION)-dev \ - sudo \ tox \ virtualenv -OS=$(shell lsb_release -si) +OS=$(shell lsb_release -si 2>/dev/null || uname) PYTHON_MAJOR_VERSION=3 PYTHON_MINOR_VERSION=7 PYTHON_VERSION=$(PYTHON_MAJOR_VERSION).$(PYTHON_MINOR_VERSION) @@ -62,8 +61,8 @@ run: virtualenv test: $(TOX) -uitest: virtualenv/test - PYTHONPATH=src $(PYTHON) -m unittest discover --top-level-directory=. --start-directory=tests/ui/ +pytest: virtualenv/test + PYTHONPATH=src $(PYTEST) tests/ lint/isort-check: virtualenv/test $(ISORT) --check-only --recursive --diff $(SOURCES) From 3a442dd6b1593520c6c3f0eb9468622044ba1a27 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 29 Sep 2019 20:57:53 +0200 Subject: [PATCH 06/13] Simplifes tox.ini - DRY via the `SOURCES` variable - Drops `Cython` requirement - Drops uitest (to be merged with tests) --- tox.ini | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/tox.ini b/tox.ini index d6b1741..b8e5160 100644 --- a/tox.ini +++ b/tox.ini @@ -2,29 +2,19 @@ envlist = pep8,isort-check,py36,py37 # no setup.py to be ran skipsdist = True -# trick to enable pre-installation of Cython -# https://stackoverflow.com/a/50081741/185510 -indexserver = - preinstall = https://pypi.python.org/simple [testenv] setenv = - KIVY_UNITTEST = 1 PYTHONPATH = {toxinidir}/src/ + SOURCES = src/ tests/ setup.py setup_meta.py passenv = DISPLAY deps = - :preinstall: Cython==0.28.6 -r{toxinidir}/requirements/requirements.txt -r{toxinidir}/requirements/requirements-test.txt -commands = pytest --ignore tests/ui/ tests/ +commands = pytest tests/ [testenv:pep8] -deps = - -r{toxinidir}/requirements/requirements-test.txt -commands = flake8 src/ tests/ setup.py setup_meta.py +commands = flake8 {env:SOURCES} [testenv:isort-check] -deps = - -r{toxinidir}/requirements/requirements-test.txt -commands = - isort --check-only --recursive --diff src/ tests/ setup.py setup_meta.py +commands = isort --check-only --recursive --diff {env:SOURCES} From 8022f7be29c5e6dd6cb9142e31f559c92d45964e Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 29 Sep 2019 20:59:49 +0200 Subject: [PATCH 07/13] Tests revamp - Matches directories structure with package - Uses more readable `assert` over `self.assert*` --- .../{ => kivy_garden/zbarcam}/test_zbarcam.py | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) rename tests/{ => kivy_garden/zbarcam}/test_zbarcam.py (72%) diff --git a/tests/test_zbarcam.py b/tests/kivy_garden/zbarcam/test_zbarcam.py similarity index 72% rename from tests/test_zbarcam.py rename to tests/kivy_garden/zbarcam/test_zbarcam.py index 0c4b035..d9d32fe 100644 --- a/tests/test_zbarcam.py +++ b/tests/kivy_garden/zbarcam/test_zbarcam.py @@ -7,8 +7,11 @@ from kivy_garden.zbarcam import ZBarCam FIXTURE_DIR = os.path.join( - os.path.dirname(os.path.abspath(__file__)), 'fixtures') -# https://github.com/kivy/kivy/blob/1.10.1/doc/sources/faq.rst + os.path.abspath( + os.path.join(__file__, os.pardir, os.pardir, os.pardir, 'fixtures') + ) +) +# https://github.com/kivy/kivy/blob/1.11.1/doc/sources/faq.rst EventLoop.ensure_window() @@ -26,7 +29,7 @@ def test_detect_qrcode_frame_no_qrcode(self): texture = Image(fixture_path).texture code_types = self.zbarcam.code_types symbols = self.zbarcam._detect_qrcode_frame(texture, code_types) - self.assertEqual(symbols, []) + assert symbols == [] def test_detect_qrcode_frame_one_qrcode(self): """ @@ -36,9 +39,9 @@ def test_detect_qrcode_frame_one_qrcode(self): texture = Image(fixture_path).texture code_types = self.zbarcam.code_types symbols = self.zbarcam._detect_qrcode_frame(texture, code_types) - self.assertEqual( - symbols, - [ZBarCam.Symbol(type='QRCODE', data=b'zbarlight test qr code')]) + assert symbols == [ + ZBarCam.Symbol(type='QRCODE', data=b'zbarlight test qr code') + ] def test_detect_qrcode_frame_one_qrcode_one_ean(self): """ @@ -48,12 +51,10 @@ def test_detect_qrcode_frame_one_qrcode_one_ean(self): texture = Image(fixture_path).texture code_types = self.zbarcam.code_types symbols = self.zbarcam._detect_qrcode_frame(texture, code_types) - self.assertEqual( - symbols, [ - ZBarCam.Symbol(type='QRCODE', data=b'zbarlight test qr code'), - ZBarCam.Symbol(type='UPCA', data=b'012345678905') - ] - ) + assert symbols == [ + ZBarCam.Symbol(type='QRCODE', data=b'zbarlight test qr code'), + ZBarCam.Symbol(type='UPCA', data=b'012345678905') + ] def test_detect_qrcode_frame_two_qrcodes(self): """ @@ -64,9 +65,7 @@ def test_detect_qrcode_frame_two_qrcodes(self): code_types = self.zbarcam.code_types symbols = self.zbarcam._detect_qrcode_frame(texture, code_types) Symbol = ZBarCam.Symbol - self.assertEqual( - symbols, [ - Symbol(type='QRCODE', data=b'second zbarlight test qr code'), - Symbol(type='QRCODE', data=b'zbarlight test qr code'), - ] - ) + assert symbols == [ + Symbol(type='QRCODE', data=b'second zbarlight test qr code'), + Symbol(type='QRCODE', data=b'zbarlight test qr code'), + ] From e232a77f7f38b017ea9f3b9a4af2ff223fa59d1d Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 29 Sep 2019 21:03:11 +0200 Subject: [PATCH 08/13] Removes dedicated tests/ui/ folder Theses tests will be merged with other and always be ran. --- tests/ui/README.md | 3 -- tests/ui/__init__.py | 0 tests/ui/test_zbarcam_ui.py | 69 ------------------------------------- 3 files changed, 72 deletions(-) delete mode 100644 tests/ui/README.md delete mode 100644 tests/ui/__init__.py delete mode 100644 tests/ui/test_zbarcam_ui.py diff --git a/tests/ui/README.md b/tests/ui/README.md deleted file mode 100644 index 0d43cdb..0000000 --- a/tests/ui/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# README - -User interface tests. Tests are built on top of [KeyWeeUsr/KivyUnitTest](https://github.com/KeyWeeUsr/KivyUnitTest). diff --git a/tests/ui/__init__.py b/tests/ui/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/ui/test_zbarcam_ui.py b/tests/ui/test_zbarcam_ui.py deleted file mode 100644 index 8016b0d..0000000 --- a/tests/ui/test_zbarcam_ui.py +++ /dev/null @@ -1,69 +0,0 @@ -import os -import time -import unittest -from functools import partial - -import mock -from kivy.clock import Clock -from kivy_garden.zbarcam.zbarcam import ZBarCam - -from main import DemoApp - - -class UITestCase(unittest.TestCase): - - # sleep function that catches `dt` from Clock - def pause(*args): - time.sleep(0.000001) - - def advance_frames(self, count): - """ - Borrowed from Kivy 1.10.0+ /kivy/tests/common.py - GraphicUnitTest.advance_frames() - Makes it possible to to wait for UI to process, refs #110. - """ - from kivy.base import EventLoop - for i in range(count): - EventLoop.idle() - - @staticmethod - def get_camera_class(): - """ - Continuous integration providers don't have a camera available. - """ - if os.environ.get('CI', False): - Camera = None - else: - from kivy.core.camera import Camera - return Camera - - def helper_test_open_application(self, app): - """ - Makes sure the ZBarCam widget is rendered, hence the application - started without crashing. - """ - self.assertEqual(app.root.ids.zbarcam.__class__, ZBarCam) - - # main test function - def run_test(self, app, *args): - Clock.schedule_interval(self.pause, 0.000001) - # lets it finish to init - self.advance_frames(1) - self.helper_test_open_application(app) - # Comment out if you are editing the test, it'll leave the - # Window opened. - app.stop() - - # same named function as the filename(!) - def test_ui_base(self): - # uses the `wraps` parameter to conditionally enable/disable mock - Camera = self.get_camera_class() - with mock.patch('kivy.uix.camera.CoreCamera', wraps=Camera): - app = DemoApp() - p = partial(self.run_test, app) - Clock.schedule_once(p, 0.000001) - app.run() - - -if __name__ == '__main__': - unittest.main() From d0d9a673d29844d0b7129471b788517f029b75a9 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 29 Sep 2019 23:50:07 +0200 Subject: [PATCH 09/13] Setup coverage testing Note that coveralls report is getting posted only on `CI` env set. Also coveralls script needs access to a bunch of CI variables defined via `dockerfiles/env.list`. It also requires access to the `.git/` directory to fetch PR/commit info for coverage stats. --- .dockerignore | 1 - .gitignore | 3 +++ .travis.yml | 2 +- CHANGELOG.md | 5 +++++ Makefile | 7 +++++-- README.md | 1 + requirements.txt | 4 ++-- requirements/{requirements.txt => requirements-base.txt} | 0 requirements/requirements-test.txt | 9 +++++---- src/kivy_garden/zbarcam/__init__.py | 1 - src/main.py | 1 - tests/kivy_garden/zbarcam/test_zbarcam.py | 2 +- tox.ini | 6 ++---- 13 files changed, 25 insertions(+), 17 deletions(-) rename requirements/{requirements.txt => requirements-base.txt} (100%) diff --git a/.dockerignore b/.dockerignore index 38d67d5..9a59c66 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,5 @@ bin/ venv/ -.git/ .buildozer/ .pytest_cache/ .tox/ diff --git a/.gitignore b/.gitignore index 04bdc1f..2dd84ee 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ bin/ build/ dist/ *.egg-info/ +htmlcov/ +.coverage +.coverage.* diff --git a/.travis.yml b/.travis.yml index da39213..1011153 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,4 +25,4 @@ before_script: - sh -e /etc/init.d/xvfb start script: - - travis_wait docker run -e DISPLAY -e CI -v /tmp/.X11-unix:/tmp/.X11-unix $TAG $COMMAND + - travis_wait docker run --env-file dockerfiles/env.list -v /tmp/.X11-unix:/tmp/.X11-unix $TAG $COMMAND diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b1bb3f..4712648 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## [Unrelease] + + - Setup coverage testing + - Bump to `xcamera>=2019.928` + ## [2019.0910] - Use new `xcamera` from PyPI diff --git a/Makefile b/Makefile index 7880f7b..03456bb 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ GARDEN=$(VIRTUAL_ENV)/bin/garden PYTHON=$(VIRTUAL_ENV)/bin/python ISORT=$(VIRTUAL_ENV)/bin/isort FLAKE8=$(VIRTUAL_ENV)/bin/flake8 +PYTEST=$(VIRTUAL_ENV)/bin/pytest TWINE=`which twine` SOURCES=src/ tests/ setup.py setup_meta.py # using full path so it can be used outside the root dir @@ -35,6 +36,7 @@ OS=$(shell lsb_release -si 2>/dev/null || uname) 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) @@ -50,7 +52,7 @@ $(VIRTUAL_ENV): virtualenv: $(VIRTUAL_ENV) $(PIP) install Cython==0.28.6 - $(PIP) install -r requirements/requirements.txt + $(PIP) install -r requirements.txt virtualenv/test: virtualenv $(PIP) install -r requirements/requirements-test.txt @@ -60,9 +62,10 @@ run: virtualenv test: $(TOX) + @if test -n "$$CI"; then .tox/py$(PYTHON_MAJOR_MINOR)/bin/coveralls; fi; \ pytest: virtualenv/test - PYTHONPATH=src $(PYTEST) tests/ + PYTHONPATH=src $(PYTEST) --cov src/ --cov-report html tests/ lint/isort-check: virtualenv/test $(ISORT) --check-only --recursive --diff $(SOURCES) diff --git a/README.md b/README.md index 1db05e4..b7bd045 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # zbarcam [![Build Status](https://travis-ci.org/kivy-garden/zbarcam.svg?branch=develop)](https://travis-ci.org/kivy-garden/zbarcam) +[![Coverage Status](https://coveralls.io/repos/github/kivy-garden/zbarcam/badge.svg?branch=develop)](https://coveralls.io/github/kivy-garden/zbarcam?branch=develop) [![PyPI version](https://badge.fury.io/py/zbarcam.svg)](https://badge.fury.io/py/zbarcam) [![Documentation Status](https://readthedocs.org/projects/zbarcam/badge/?version=latest)](https://zbarcam.readthedocs.io/en/latest/?badge=latest) diff --git a/requirements.txt b/requirements.txt index 7d837a9..e355c8b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ --r requirements/requirements.txt +-r requirements/requirements-base.txt -r requirements/requirements-documentation.txt --r requirements/test_requirements.txt +-r requirements/requirements-test.txt diff --git a/requirements/requirements.txt b/requirements/requirements-base.txt similarity index 100% rename from requirements/requirements.txt rename to requirements/requirements-base.txt diff --git a/requirements/requirements-test.txt b/requirements/requirements-test.txt index f1943ca..09ff3bd 100644 --- a/requirements/requirements-test.txt +++ b/requirements/requirements-test.txt @@ -1,4 +1,5 @@ -isort==4.2.5 -flake8==3.3.0 -mock==2.0.0 -pytest==4.3.0 +coveralls +flake8 +isort +pytest +pytest-cov diff --git a/src/kivy_garden/zbarcam/__init__.py b/src/kivy_garden/zbarcam/__init__.py index f10f37a..7fe813a 100644 --- a/src/kivy_garden/zbarcam/__init__.py +++ b/src/kivy_garden/zbarcam/__init__.py @@ -7,7 +7,6 @@ """ import os - project_dir = os.path.abspath( os.path.join(__file__, os.pardir, os.pardir, os.pardir, os.pardir)) using_pip = os.path.basename(project_dir).startswith('pip-') diff --git a/src/main.py b/src/main.py index ab19071..6db2c13 100755 --- a/src/main.py +++ b/src/main.py @@ -9,7 +9,6 @@ from kivy.app import App from kivy.lang import Builder - DEMO_APP_KV_LANG = """ #:import ZBarCam kivy_garden.zbarcam.ZBarCam #:import ZBarSymbol pyzbar.pyzbar.ZBarSymbol diff --git a/tests/kivy_garden/zbarcam/test_zbarcam.py b/tests/kivy_garden/zbarcam/test_zbarcam.py index d9d32fe..2c7370b 100644 --- a/tests/kivy_garden/zbarcam/test_zbarcam.py +++ b/tests/kivy_garden/zbarcam/test_zbarcam.py @@ -1,7 +1,7 @@ import os import unittest +from unittest import mock -import mock from kivy.base import EventLoop from kivy.core.image import Image from kivy_garden.zbarcam import ZBarCam diff --git a/tox.ini b/tox.ini index b8e5160..1b218a0 100644 --- a/tox.ini +++ b/tox.ini @@ -8,10 +8,8 @@ setenv = PYTHONPATH = {toxinidir}/src/ SOURCES = src/ tests/ setup.py setup_meta.py passenv = DISPLAY -deps = - -r{toxinidir}/requirements/requirements.txt - -r{toxinidir}/requirements/requirements-test.txt -commands = pytest tests/ +deps = -r{toxinidir}/requirements.txt +commands = pytest --cov src/ tests/ [testenv:pep8] commands = flake8 {env:SOURCES} From 508ea0ea372f1448883a7ad2bdbd30a830cb6cc6 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Mon, 30 Sep 2019 05:36:22 +0200 Subject: [PATCH 10/13] Minor Makefile improvements - `git` is needed by `coveralls` - `lsb-release` and `make` are installed upfront - simplifies `virtualenv` target - improves `clean` target - drops unused `garden` binary --- Makefile | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 03456bb..e04103d 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ VIRTUAL_ENV ?= venv PIP=$(VIRTUAL_ENV)/bin/pip TOX=`which tox` -GARDEN=$(VIRTUAL_ENV)/bin/garden PYTHON=$(VIRTUAL_ENV)/bin/python ISORT=$(VIRTUAL_ENV)/bin/isort FLAKE8=$(VIRTUAL_ENV)/bin/flake8 @@ -16,6 +15,7 @@ SYSTEM_DEPENDENCIES= \ ccache \ cmake \ curl \ + git \ libsdl2-dev \ libsdl2-image-dev \ libsdl2-mixer-dev \ @@ -23,8 +23,6 @@ SYSTEM_DEPENDENCIES= \ libpython3.6-dev \ libpython$(PYTHON_VERSION)-dev \ libzbar-dev \ - lsb-release \ - make \ pkg-config \ python3.6 \ python3.6-dev \ @@ -49,11 +47,11 @@ endif $(VIRTUAL_ENV): virtualenv -p $(PYTHON_WITH_VERSION) $(VIRTUAL_ENV) - -virtualenv: $(VIRTUAL_ENV) $(PIP) install Cython==0.28.6 $(PIP) install -r requirements.txt +virtualenv: $(VIRTUAL_ENV) + virtualenv/test: virtualenv $(PIP) install -r requirements/requirements-test.txt @@ -96,9 +94,9 @@ release/upload: $(TWINE) upload dist/* clean: release/clean docs/clean - py3clean src/ - find src/ -type d -name "__pycache__" -exec rm -r {} + - find src/ -type d -name "*.egg-info" -exec rm -r {} + + py3clean . + find . -type d -name "__pycache__" -exec rm -r {} + + find . -type d -name "*.egg-info" -exec rm -r {} + clean/all: clean rm -rf $(VIRTUAL_ENV) .tox/ From 59d0bdd009ee369830e152012ce4f0e2585d4929 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Mon, 14 Oct 2019 17:16:02 +0200 Subject: [PATCH 11/13] Re-enables and fixes buildozer build Disabled earlier in 223c67b and fixed in `buildozer` master branch. Also simplifies and fixes `xvfb` service. --- .travis.yml | 18 ++++-------------- README.md | 2 +- dockerfiles/Dockerfile-android | 22 ++++++++++------------ 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1011153..3f289da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,25 +4,15 @@ language: generic services: - docker + - xvfb env: - global: - - DISPLAY=:99.0 matrix: - TAG=zbarcam-linux DOCKERFILE=dockerfiles/Dockerfile-linux COMMAND='make test' - # broken in: - # https://github.com/kivy/python-for-android/pull/1986 - # - TAG=zbarcam-android DOCKERFILE=dockerfiles/Dockerfile-android COMMAND='buildozer android debug' - -before_install: - - sudo apt update -qq > /dev/null - - sudo apt install --yes --no-install-recommends xvfb - -install: - - docker build --tag=$TAG --file=$DOCKERFILE --build-arg CI . + - TAG=zbarcam-android DOCKERFILE=dockerfiles/Dockerfile-android COMMAND='buildozer android debug' before_script: - - sh -e /etc/init.d/xvfb start + - docker build --tag=$TAG --file=$DOCKERFILE --build-arg CI . script: - - travis_wait docker run --env-file dockerfiles/env.list -v /tmp/.X11-unix:/tmp/.X11-unix $TAG $COMMAND + - travis_wait 30 docker run --env-file dockerfiles/env.list -v /tmp/.X11-unix:/tmp/.X11-unix $TAG $COMMAND diff --git a/README.md b/README.md index b7bd045..98a7f47 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ make system_dependencies Install zbarcam: ```sh -pip install --upgrade zbarcam +pip install zbarcam ``` Then import it in your Python code via: ```python diff --git a/dockerfiles/Dockerfile-android b/dockerfiles/Dockerfile-android index bf9c1b7..3b0c08b 100644 --- a/dockerfiles/Dockerfile-android +++ b/dockerfiles/Dockerfile-android @@ -17,7 +17,7 @@ ENV WORK_DIR="${HOME_DIR}" \ ENV DOCKERFILES_VERSION="v20190902" \ DOCKERFILES_URL="https://raw.githubusercontent.com/AndreMiras/dockerfiles" ENV MAKEFILES_URL="${DOCKERFILES_URL}/${DOCKERFILES_VERSION}/buildozer_android" -ENV BUILDOZER_VERSION="182d13f" +ENV BUILDOZER_VERSION="81c31c4" # configure locale @@ -29,7 +29,7 @@ ENV LANG="en_US.UTF-8" \ LC_ALL="en_US.UTF-8" # install system dependencies -RUN apt install -qq --yes --no-install-recommends \ +RUN apt update -qq > /dev/null && apt install -qq --yes --no-install-recommends \ autoconf \ automake \ ca-certificates \ @@ -54,20 +54,18 @@ RUN apt install -qq --yes --no-install-recommends \ xz-utils \ zip -# prepare non root env -RUN useradd --create-home --shell /bin/bash ${USER} -# with sudo access and no password -RUN usermod -append --groups sudo ${USER} -RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers +# prepare non root env, with sudo access and no password +RUN useradd --create-home --shell /bin/bash ${USER} && \ + usermod -append --groups sudo ${USER} && \ + echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers USER ${USER} WORKDIR ${WORK_DIR} -# install buildozer and dependencies -RUN curl --location --progress-bar ${MAKEFILES_URL}/buildozer.mk --output buildozer.mk -RUN make -f buildozer.mk -# enforces buildozer master until next release -RUN pip3 install --upgrade https://github.com/kivy/buildozer/archive/${BUILDOZER_VERSION}.zip +# install buildozer & dependencies and enforces buildozer master until next release +RUN curl --location --progress-bar ${MAKEFILES_URL}/buildozer.mk --output buildozer.mk && \ + make -f buildozer.mk && \ + pip3 install --upgrade https://github.com/kivy/buildozer/archive/${BUILDOZER_VERSION}.zip COPY . ${WORK_DIR} # limits the amount of logs for Travis From a8f6a59c10afbb7e75f007022da9dd9db4dff0bb Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Mon, 14 Oct 2019 19:47:56 +0200 Subject: [PATCH 12/13] Fixes documentation generation Adds sphinx depenencies and Makefile target dependency. --- CHANGELOG.md | 1 + Makefile | 2 +- requirements/requirements-documentation.txt | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4712648..371f913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Setup coverage testing - Bump to `xcamera>=2019.928` + - Continuous integration improvements ## [2019.0910] diff --git a/Makefile b/Makefile index e04103d..f620f4e 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,7 @@ lint: lint/isort-check lint/flake8 docs/clean: rm -rf $(DOCS_DIR)/build/ -docs: +docs: virtualenv cd $(DOCS_DIR) && SPHINXBUILD=$(SPHINXBUILD) make html release/clean: diff --git a/requirements/requirements-documentation.txt b/requirements/requirements-documentation.txt index b5cb07a..3f3273a 100644 --- a/requirements/requirements-documentation.txt +++ b/requirements/requirements-documentation.txt @@ -1 +1,3 @@ m2r==0.2.1 +Sphinx +sphinx-rtd-theme From 3c9ec0e3fddf01473c96d6b503dca7dc7fcc8c92 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sun, 20 Oct 2019 21:07:47 +0200 Subject: [PATCH 13/13] 2019.1020 --- CHANGELOG.md | 2 +- src/kivy_garden/zbarcam/version.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 371f913..f11bc2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [Unrelease] +## [2019.1020] - Setup coverage testing - Bump to `xcamera>=2019.928` diff --git a/src/kivy_garden/zbarcam/version.py b/src/kivy_garden/zbarcam/version.py index 1e8ec57..ec34387 100644 --- a/src/kivy_garden/zbarcam/version.py +++ b/src/kivy_garden/zbarcam/version.py @@ -1,7 +1,7 @@ -__version__ = '2019.0910' +__version__ = '2019.1020' # The `__version_code__` is used for the F-Droid auto update and should match # the `versionCode` from the `build.gradle` file located in: -# `.buildozer/android/platform/build/dists/zbarcamdemo/` +# `.buildozer/android/platform/build-*/dists/zbarcamdemo__*/build.gradle` # The auto update method used is the `HTTP`, see: # https://f-droid.org/en/docs/Build_Metadata_Reference/#UpdateCheckMode -__version_code__ = 721202810 +__version_code__ = 721202920