Skip to content

Commit

Permalink
Merge branch 'release/2019.0911'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMiras committed Sep 10, 2019
2 parents e259355 + 1599883 commit 9d4f63a
Show file tree
Hide file tree
Showing 25 changed files with 425 additions and 82 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bin/
venv/
.git/
.buildozer/
.pytest_cache/
.tox/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Custom
*.swp

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
sudo: required

language: generic

services:
- docker

env:
global:
- DISPLAY=:99.0
matrix:
- TAG=zbarcam-linux DOCKERFILE=dockerfiles/Dockerfile-linux COMMAND='tox'

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 .

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
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## [20190910]
## [2019.0911]

- Move to new garden layout
- Setup Docker testing
- Split kvlang file from Python code
- Setup Continuous Integration testing, refs #1
- Setup linting, refs #2
- Unit tests `platform_api` module, refs #3
- Publish to PyPI, refs #4
- Introduce `Makefile`, refs #8

## [2019.0910]

- Initial release before revamp
85 changes: 85 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
VENV_NAME=venv
PIP=$(VENV_NAME)/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
TWINE=`which twine`
SOURCES=src/ tests/ setup.py setup_meta.py
# using full path so it can be used outside the root dir
SPHINXBUILD=$(shell realpath venv/bin/sphinx-build)
DOCS_DIR=doc
SYSTEM_DEPENDENCIES= \
libpython$(PYTHON_VERSION)-dev \
libsdl2-dev \
libzbar-dev \
tox \
virtualenv
OS=$(shell lsb_release -si)
PYTHON_MAJOR_VERSION=3
PYTHON_MINOR_VERSION=6
PYTHON_VERSION=$(PYTHON_MAJOR_VERSION).$(PYTHON_MINOR_VERSION)
PYTHON_WITH_VERSION=python$(PYTHON_VERSION)


all: system_dependencies virtualenv

venv:
test -d venv || virtualenv -p $(PYTHON_WITH_VERSION) venv

virtualenv: venv
$(PIP) install Cython==0.28.6
$(PIP) install -r requirements.txt

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 --debug

run: run/linux

test:
$(TOX)

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

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

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

lint: lint/isort-check lint/flake8

docs/clean:
rm -rf $(DOCS_DIR)/build/

docs:
cd $(DOCS_DIR) && SPHINXBUILD=$(SPHINXBUILD) make html

release/clean:
rm -rf dist/ build/

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

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

clean: release/clean docs/clean
py3clean src/
find . -type d -name "__pycache__" -exec rm -r {} +
find . -type d -name "*.egg-info" -exec rm -r {} +

clean/all: clean
rm -rf $(VENV_NAME) .tox/
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# XCamera: Android-optimized camera widget

[![Build Status](https://travis-ci.com/kivy-garden/xcamera.svg?branch=develop)](https://travis-ci.com/kivy-garden/xcamera)
[![PyPI version](https://badge.fury.io/py/xcamera.svg)](https://badge.fury.io/py/xcamera)

XCamera is a widget which extends the standard Kivy Camera widget with more
functionality. In particular:

Expand All @@ -15,6 +18,7 @@ functionality. In particular:
was before.

Screenshot:

![screenshot](/screenshot.png?raw=True "Screenshot")

Notes:
Expand All @@ -32,6 +36,23 @@ Notes:
requests are welcome :)

## Install
```sh
pip install xcamera
```

## Demo
A full working demo is available in [src/main.py](https://github.com/kivy-garden/xcamera/blob/master/src/main.py).
You can run it via:
```sh
make run
```

## Contribute
To play with the project, install system dependencies and Python requirements using the [Makefile](Makefile).
```sh
make
```
garden install xcamera
Then verify everything is OK by running tests.
```sh
make test
```
13 changes: 0 additions & 13 deletions deploy.sh

This file was deleted.

62 changes: 62 additions & 0 deletions dockerfiles/Dockerfile-linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Docker image for installing dependencies on Linux and running tests.
# Build with:
# docker build --tag=xcamera-linux --file=dockerfiles/Dockerfile-linux .
# Run with:
# docker run xcamera-linux /bin/sh -c 'make test'
# Or using the entry point shortcut:
# docker run xcamera-linux 'make test'
# For running UI:
# xhost +"local:docker@"
# docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix xcamera-linux 'make uitest'
# Or for interactive shell:
# docker run -it --rm xcamera-linux
FROM ubuntu:18.04

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

# configure locale
RUN apt update -qq > /dev/null && apt install --yes --no-install-recommends \
locales && \
locale-gen en_US.UTF-8
ENV LANG="en_US.UTF-8" \
LANGUAGE="en_US.UTF-8" \
LC_ALL="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

# 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

USER ${USER}
WORKDIR ${WORK_DIR}
COPY . ${WORK_DIR}

# RUN make
ENTRYPOINT ["./dockerfiles/start.sh"]
10 changes: 10 additions & 0 deletions dockerfiles/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

# if a some command has been passed to container, executes it and exit,
# otherwise runs bash
if [[ $@ ]]; then
eval $@
else
/bin/bash
fi
3 changes: 0 additions & 3 deletions example/android.txt

This file was deleted.

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Kivy==1.11.1
opencv-python==4.1.1.26
3 changes: 3 additions & 0 deletions requirements/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flake8
isort
pytest
40 changes: 40 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os

from setuptools import find_namespace_packages, setup

from src.kivy_garden.xcamera import version


def read(fname):
with open(os.path.join(os.path.dirname(__file__), fname)) as f:
return f.read()


# exposing the params so it can be imported
setup_params = {
'name': 'kivy_garden.xcamera',
'version': version.__version__,
'description': 'Real time Barcode and QR Code scanner Edit',
'long_description': read('README.md'),
'long_description_content_type': 'text/markdown',
'author': 'Antonio Cuni',
'url': 'https://github.com/kivy-garden/xcamera',
'packages': find_namespace_packages(where='src'),
'package_data': {
'kivy_garden.xcamera': ['*.kv'],
'kivy_garden.xcamera.data': ['*.ttf', '*.wav'],
},
'package_dir': {'': 'src'},
'install_requires': [
'kivy',
],
}


def run_setup():
setup(**setup_params)


# makes sure the setup doesn't run at import time
if __name__ == '__main__':
run_setup()
14 changes: 14 additions & 0 deletions setup_meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Creates a distribution alias that just installs kivy_garden.xcamera.
"""
from setuptools import setup

from setup import setup_params

setup_params.update({
'install_requires': ['kivy_garden.xcamera'],
'name': 'xcamera',
})


setup(**setup_params)
15 changes: 15 additions & 0 deletions src/kivy_garden/xcamera/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Exposes `XCamera` directly in `xcamera` rather than `xcamera.xcamera`.
Also note this may break `pip` since all imports within `xcamera.py` would be
required at setup time. This is because `version.py` (same directory) is used
by the `setup.py` file.
Hence we're not exposing `XCamera` if `pip` is detected.
"""
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-')
# only exposes `XCamera` if not within `pip` ongoing install
if not using_pip:
from .xcamera import XCamera # noqa
11 changes: 6 additions & 5 deletions android_api.py → src/kivy_garden/xcamera/android_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from __future__ import absolute_import
from jnius import autoclass, PythonJavaClass, java_method, JavaException
from kivy.logger import Logger

from jnius import JavaException, PythonJavaClass, autoclass, java_method

Camera = autoclass('android.hardware.Camera')
AndroidActivityInfo = autoclass('android.content.pm.ActivityInfo')
AndroidPythonActivity = autoclass('org.renpy.android.PythonActivity')
PORTRAIT = AndroidActivityInfo.SCREEN_ORIENTATION_PORTRAIT
LANDSCAPE = AndroidActivityInfo.SCREEN_ORIENTATION_LANDSCAPE


class ShutterCallback(PythonJavaClass):
__javainterfaces__ = ('android.hardware.Camera$ShutterCallback', )
Expand Down Expand Up @@ -72,13 +75,11 @@ def take_picture(camera_widget, filename, on_success):
Logger.info('Error when calling autofocus: {}'.format(e))


PORTRAIT = AndroidActivityInfo.SCREEN_ORIENTATION_PORTRAIT
LANDSCAPE = AndroidActivityInfo.SCREEN_ORIENTATION_LANDSCAPE

def set_orientation(value):
previous = get_orientation()
AndroidPythonActivity.mActivity.setRequestedOrientation(value)
return previous


def get_orientation():
return AndroidPythonActivity.mActivity.getRequestedOrientation()
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 9d4f63a

Please sign in to comment.