Skip to content

Commit

Permalink
Merge branch 'release/20190902'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMiras committed Sep 2, 2019
2 parents ddafb79 + 82e2e63 commit eb648c5
Show file tree
Hide file tree
Showing 35 changed files with 553 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ venv/
.buildozer/
.pytest_cache/
.tox/
opencv*
opencv-*
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ venv/
.tox/
.buildozer/
bin/
opencv-*
build/
dist/
*.egg-info/
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## [20190902]

- Update Cython for Python3.7 support, refs #35
- Make garden.zbarcam a package again, refs #36
- Don't ship opencv directory to APK, refs #37
- Migrate to new garden structure, refs #17
- Publish documentation to readthedocs, refs #18
- Publish to PyPI, refs #19

## [20190303]

- Add Python3.6 support, refs #5
Expand Down
33 changes: 23 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ PIP=$(VENV_NAME)/bin/pip
TOX=`which tox`
GARDEN=$(VENV_NAME)/bin/garden
PYTHON=$(VENV_NAME)/bin/python
# using full path so it can be used outside the root dir
SPHINXBUILD=$(shell realpath venv/bin/sphinx-build)
DOCS_DIR=doc
SYSTEM_DEPENDENCIES= \
build-essential \
cmake \
Expand All @@ -21,13 +24,19 @@ PYTHON_WITH_VERSION=python$(PYTHON_VERSION)
# python3 has a "m" suffix for both include path and library
PYTHON_M=$(PYTHON_WITH_VERSION)
SITE_PACKAGES_DIR=$(VENV_NAME)/lib/$(PYTHON_WITH_VERSION)/site-packages
TMPDIR ?= /tmp
DOWNLOAD_DIR = $(TMPDIR)/downloads
OPENCV_VERSION=4.0.1
OPENCV_ARCHIVE=$(OPENCV_BASENAME).tar.gz
OPENCV_BASENAME=opencv-$(OPENCV_VERSION)
OPENCV_BUILD_LIB_DIR=$(OPENCV_BASENAME)/build/lib
OPENCV_ARCHIVE=$(OPENCV_BASENAME).tar.gz
OPENCV_ARCHIVE_PATH=$(DOWNLOAD_DIR)/$(OPENCV_ARCHIVE)
OPENCV_EXTRACT_PATH=$(DOWNLOAD_DIR)/$(OPENCV_BASENAME)
OPENCV_BUILD_LIB_DIR=$(OPENCV_EXTRACT_PATH)/build/lib
OPENCV_BUILD=$(OPENCV_BUILD_LIB_DIR)/python$(PYTHON_MAJOR_VERSION)/cv2*.so
OPENCV_DEPLOY=$(SITE_PACKAGES_DIR)/cv2*.so
NPROC=`grep -c '^processor' /proc/cpuinfo`


ifeq ($(PYTHON_MAJOR_VERSION), 3)
PYTHON_M := $(PYTHON_M)m
endif
Expand All @@ -38,7 +47,7 @@ all: system_dependencies virtualenv opencv
venv:
test -d venv || virtualenv -p python$(PYTHON_MAJOR_VERSION) venv
. venv/bin/activate
$(PIP) install Cython==0.26.1
$(PIP) install Cython==0.28.6
$(PIP) install -r requirements/requirements.txt
$(GARDEN) install xcamera

Expand All @@ -49,14 +58,15 @@ ifeq ($(OS), Ubuntu)
sudo apt install --yes --no-install-recommends $(SYSTEM_DEPENDENCIES)
endif

$(OPENCV_ARCHIVE):
$(OPENCV_ARCHIVE_PATH):
mkdir -p $(DOWNLOAD_DIR)
curl --location https://github.com/opencv/opencv/archive/$(OPENCV_VERSION).tar.gz \
--progress-bar --output $(OPENCV_ARCHIVE)
--progress-bar --output $(OPENCV_ARCHIVE_PATH)

# The build also relies on virtualenv, because we make references to it.
# Plus numpy is required to build OpenCV Python module.
$(OPENCV_BUILD): $(OPENCV_ARCHIVE) virtualenv
tar -xf $(OPENCV_BASENAME).tar.gz
$(OPENCV_BUILD): $(OPENCV_ARCHIVE_PATH) virtualenv
tar -xf $(OPENCV_ARCHIVE_PATH) --directory $(DOWNLOAD_DIR)
cmake \
-D CMAKE_SHARED_LINKER_FLAGS=-l$(PYTHON_M) \
-D BUILD_SHARED_LIBS=ON \
Expand Down Expand Up @@ -90,20 +100,23 @@ $(OPENCV_BUILD): $(OPENCV_ARCHIVE) virtualenv
-D WITH_JASPER=OFF \
-D WITH_OPENEXR=OFF \
-D WITH_PVAPI=OFF \
-B$(OPENCV_BASENAME)/build -H$(OPENCV_BASENAME)
cmake --build $(OPENCV_BASENAME)/build -- -j$(NPROC)
-B$(OPENCV_EXTRACT_PATH)/build -H$(OPENCV_EXTRACT_PATH)
cmake --build $(OPENCV_EXTRACT_PATH)/build -- -j$(NPROC)

$(OPENCV_DEPLOY): $(OPENCV_BUILD) virtualenv
cp $(OPENCV_BUILD) $(SITE_PACKAGES_DIR)

opencv: $(OPENCV_DEPLOY)

clean:
rm -rf $(VENV_NAME) .tox/ $(OPENCV_BASENAME)
rm -rf $(VENV_NAME) .tox/ $(DOWNLOAD_DIR) $(DOCS_DIR)/build/ dist/ build/

test:
$(TOX)

uitest: virtualenv
$(PIP) install -r requirements/test_requirements.txt
$(PYTHON) -m unittest discover --top-level-directory=. --start-directory=tests/ui/

docs:
cd $(DOCS_DIR) && SPHINXBUILD=$(SPHINXBUILD) make html
14 changes: 14 additions & 0 deletions OpenCV.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,17 @@ make system_dependencies
make opencv
```
It would build OpenCV and deploy it to your virtualenv.

## Troubleshooting

### Makefile `cp: cannot stat 'opencv-4.0.1/build/lib/python3/cv2*.so': No such file or directory`
Log:
```
make[2]: Leaving directory '/tmp/trash/zbarcam/opencv-4.0.1/build'
make[1]: Leaving directory '/tmp/trash/zbarcam/opencv-4.0.1/build'
cp opencv-4.0.1/build/lib/python3/cv2*.so venv/lib/python3.7/site-packages
cp: cannot stat 'opencv-4.0.1/build/lib/python3/cv2*.so': No such file or directory
Makefile:97: recipe for target 'venv/lib/python3.7/site-packages/cv2*.so' failed
make: *** [venv/lib/python3.7/site-packages/cv2*.so] Error 1
```
Most likely you need to `pip install numpy` delete your opencv build and build again.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# garden.zbarcam
# zbarcam

[![Build Status](https://secure.travis-ci.org/kivy-garden/garden.zbarcam.png?branch=develop)](http://travis-ci.org/kivy-garden/garden.zbarcam)
[![Build Status](https://travis-ci.org/kivy-garden/zbarcam.svg?branch=develop)](https://travis-ci.org/kivy-garden/zbarcam)

Real time Barcode and QR Code scanner using the camera.
It's built on top of [Kivy](https://github.com/kivy/kivy) and [pyzbar](https://github.com/NaturalHistoryMuseum/pyzbar).
Expand All @@ -10,7 +10,7 @@ It's built on top of [Kivy](https://github.com/kivy/kivy) and [pyzbar](https://g
## How to use
Simply import and instanciate `ZBarCam` in your kvlang file and access its `symbols` property.
```yaml
#:import ZBarCam kivy.garden.zbarcam
#:import ZBarCam kivy_garden.zbarcam.ZBarCam
#:import ZBarSymbol pyzbar.pyzbar.ZBarSymbol
BoxLayout:
orientation: 'vertical'
Expand All @@ -23,6 +23,7 @@ BoxLayout:
size: self.texture_size[0], 50
text: ', '.join([str(symbol.data) for symbol in zbarcam.symbols])
```
A full working demo is available in [kivy_garden/zbarcam/main.py](kivy_garden/zbarcam/main.py).
## Install
Expand All @@ -34,19 +35,19 @@ sudo apt install libzbar-dev

Install garden requirements:
```sh
garden install xcamera
garden install --upgrade xcamera
```

Install zbarcam:
Via `garden`:
```sh
garden install --upgrade zbarcam
pip install --upgrade https://github.com/kivy-garden/zbarcam/archive/develop.zip
```
Via `pip`:
```sh
pip install --upgrade https://github.com/kivy-garden/garden.zbarcam/archive/develop.zip
Then import it in your Python code via:
```python
from kivy_garden.zbarcam import ZBarCam
```


You may also need to compile/install OpenCV manually, see [OpenCV.md](OpenCV.md).

### Android
Expand All @@ -66,15 +67,15 @@ make uitest
## Troubleshooting

### Install `Unable to import package 'kivy.garden.xcamera.XCamera'`
Missing the `xcamera` dependency, install it with:
```sh
garden install xcamera
```
You're missing the `xcamera` dependency. Install it as described in the install instructions.

### Android `ValueError: Empty module name`
More likely an import issue in your `.kv` file.
Try to `from zbarcam import ZBarCam` in your `main.py` to see the exact error.
It's common to forget `Pillow` in `buildozer.spec` `requirements` section.

### OpenCV related
See [OpenCV.md](OpenCV.md).

## Credits
I borrowed a lot of code from [tito/android-zbar-qrcode](https://github.com/tito/android-zbar-qrcode).
6 changes: 3 additions & 3 deletions buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package.name = zbarcamdemo
package.domain = com.github.andremiras

# (str) Source code where the main.py live
source.dir = .
source.dir = src

# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas
Expand All @@ -22,7 +22,7 @@ source.include_exts = py,png,jpg,kv,atlas
#source.exclude_exts = spec

# (list) List of directory to exclude (let empty to not exclude anything)
source.exclude_dirs = tests, bin, venv, opencv-*
#source.exclude_dirs = tests, bin

# (list) List of exclusions using pattern matching
#source.exclude_patterns = license,images/*/*.jpg
Expand All @@ -32,7 +32,7 @@ source.exclude_dirs = tests, bin, venv, opencv-*

# (str) Application versioning (method 2)
version.regex = __version__ = ['"](.*)['"]
version.filename = %(source.dir)s/zbarcam/version.py
version.filename = %(source.dir)s/kivy_garden/zbarcam/version.py
# (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy
Expand Down
20 changes: 20 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
48 changes: 48 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Generating the Docs
===================

Basic instructions for how to generate the flower docs and upload to github.
This needs to be done in either powershell or linux shell, not windows cmd.

The generated docs can be found at https://kivy-garden.github.io/flower/ after this
process.

Please use these instructions with care and don't copy paste without understanding
what the commands do as they create and delete folders. Make sure the repo is
fully pushed to github before doing this because this **deletes** all local changes.

You may want to do the following commands in a copy of the flower directory.

Install sphinx::

python -m pip install sphinx

In a shell make sure to be in the flower directory. Then::

cd doc
# (in powershell do ./make.bat html)
make html
cd ..

mkdir ~/docs_temp
# copy generated docs to temp path
cp -r doc/build/html/* ~/docs_temp
# gh-pages is the branch for the docs that github will display
git checkout --orphan gh-pages
# **CAUTION** be sure the following commands is executed in the flower directory
# we take no responsibility if you delete all the files in your computer :)
git rm -rf .
# on a linux shell do
rm -fr $(ls -1 --ignore=.git .)
# in powershell instead do
Remove-Item -recurse * -exclude .git
# copy the docs back to the repo
cp -r ~/docs_temp/* .
echo "" > .nojekyll

git add .
git commit -a -m "Docs update"
git push origin gh-pages -f

# Finally, get back to master
git checkout master
35 changes: 35 additions & 0 deletions doc/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
9 changes: 9 additions & 0 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

################
Zbarcam API
################

.. toctree::
:maxdepth: 1

zbarcam.rst
Loading

0 comments on commit eb648c5

Please sign in to comment.