Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
quicklizard99 committed Nov 8, 2016
0 parents commit f75a50c
Show file tree
Hide file tree
Showing 21 changed files with 1,421 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .coveragerc
@@ -0,0 +1,10 @@
[run]
omit = */site-packages/*

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

if __name__ *== *.__main__.:
9 changes: 9 additions & 0 deletions .gitignore
@@ -0,0 +1,9 @@
*.py[co]
*.egg-info/
.DS_Store
build
dist
.tox
README.rst
.coverage
dll*
23 changes: 23 additions & 0 deletions .travis.yml
@@ -0,0 +1,23 @@
language:
- python

sudo:
- required

python:
- "2.7"
- "3.4"
- "3.5"

before_install:
- sudo apt-get -qq update
- sudo apt-get install -y libzbar0 python-opencv

install:
- pip install tox-travis coveralls

script:
- tox

after_success:
- coveralls
122 changes: 122 additions & 0 deletions DEVELOPING.md
@@ -0,0 +1,122 @@
## Development

```
mkvirtualenv pyzbar
pip install -U pip
pip install -r requirements.pip
nosetests
python -m pyzbar.scripts.read_zbar code128 pylibdmtx/tests/code128.png
```

### Testing python versions

Make a virtual env and install `tox`

```
mkvirtualenv tox
pip install tox
```

If you use non-standard locations for your Python builds, make the interpreters available on the `PATH` before running `tox`.

```
PATH=~/local/python-2.7.12/bin:~/local/python-3.4.5/bin:~/local/python-3.5.2/bin:$PATH
tox
```

### Windows

Save the 32-bit and 64-bit `zbar.dll` files, and their dependencies,
to `zbar-32.dll` and `zbar-64.dll` respectively, in the directories `dlls-32`
and dlls-64/ respectively.
The `load_zbar` function in `wrapper.py` looks for the appropriate `DLL`
on `sys.path`. The appropriate `DLL` is packaged up into the wheel build,
then installed to the root of the virtual env. This strategy allows
the same method to be used when `pylibdmtx` is run from source, as an installed
package and when included in a frozen binary.

## Releasing

1. Install tools.

```
pip install wheel
brew install pandoc
```

2. Build
Generate the `reStructuredText README.rst` from `README.md` and create
source and wheel builds. The `win32` and `win_amd64` will contain the
appropriate `libdmtx.dll`.

```
pandoc --from=markdown --to=rst README.md -o README.rst
rm -rf build dist
./setup.py bdist_wheel
./setup.py bdist_wheel --plat-name=win32
./setup.py bdist_wheel --plat-name=win_amd64
```

3. Release to pypitest (see https://wiki.python.org/moin/TestPyPI for details)

```
mkvirtualenv pypi
pip install twine
twine register -r pypitest dist/pyzbar-0.1.1-py2.py3-none-any.whl
twine upload -r pypitest dist/*
```

4. Test the release to pypitest

* Check https://testpypi.python.org/pypi/pyzbar/

* If you are on Windows

```
set PATH=%PATH%;c:\python35\;c:\python35\scripts
\Python35\Scripts\mkvirtualenv.bat --python=c:\python27\python.exe test1
```

* Install dependencies that are not on testpypi.python.org.
If you are on Python 2.x, these are mandatory

```
pip install enum34 pathlib
```

* Pillow for tests and command-line programs. We can't use the
`pip install pyzbar[scripts]` form here because `Pillow` will not be
on testpypi.python.org

```
pip install Pillow
```

* Install the package itself

```
pip install --index https://testpypi.python.org/simple pyzbar
```

* Test

```
read_zbar --help
read_zbar <path-to-image-with-barcode.png>
```

5. If all is well, release to PyPI

```
twine register dist/pyzbar-0.1.1-py2.py3-none-any.whl
twine upload dist/*
```

* Check https://pypi.python.org/pypi/pyzbar/

* Install!

```
pip install pyzbar[scripts]
```
85 changes: 85 additions & 0 deletions README.md
@@ -0,0 +1,85 @@
# pyzbar

[![Python Versions](https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5-blue.svg)](https://github.com/NaturalHistoryMuseum/pyzbar)
[![PyPI version](https://badge.fury.io/py/pyzbar.svg)](https://badge.fury.io/py/pyzbar)
[![Travis status](https://travis-ci.org/NaturalHistoryMuseum/pyzbar.svg?branch=master)](https://travis-ci.org/NaturalHistoryMuseum/pyzbar)
[![Coverage Status](https://coveralls.io/repos/github/NaturalHistoryMuseum/pyzbar/badge.svg?branch=master)](https://coveralls.io/github/NaturalHistoryMuseum/pyzbar?branch=master)

A `ctypes`-based Python wrapper around the [zbar](http://zbar.sourceforge.net/)
barcode reader.

The
[zbar](https://sourceforge.net/p/zbar/code/ci/default/tree/python/)
wrapper is stuck in Python 2.x-land.
The [zbarlight](https://github.com/Polyconseil/zbarlight/) wrapper doesn't
provide support for Windows and depends upon Pillow.
This `ctypes`-based wrapper brings `zbar` to Python 2.7 and to Python 3.4 or
greater.

## Installation

The `zbar` `DLL`s are included with the Windows Python wheels.
On other operating systems, you will need to install the `zbar` shared library.

On Mac OS X:

```
brew install zbar
```

On Linux:

```
sudo apt-get install libzbar0
```

Install this Python wrapper; use the second form to install dependencies of
the command-line scripts:

```
pip install pyzbar
pip install pyzbar[scripts]
```





## Example usage

The `decode` function accepts instances of `PIL.Image`.

```
>>> from pyzbar.pyzbar import decode
>>> from PIL import Image
>>> decode(Image.open('pyzbar/tests/code128.png'))
[Decoded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
Decoded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]
```

It also accepts instances of `numpy.ndarray`, which might come from loading
images using [OpenCV](http://opencv.org/).

```
>>> import cv2
>>> decode(cv2.imread('pylibdmtx/tests/datamatrix.png'))
[Decoded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
Decoded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]
```

You can also provide a tuple `(pixels, width, height)`

```
>>> image = cv2.imread('pylibdmtx/tests/datamatrix.png')
>>> height, width = image.shape[:2]
>>> decode((image.tobytes(), width, height))
[Decoded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
Decoded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]
```


## License

`pyzbar` is distributed under the MIT license (see `LICENCE.txt`).
The `zbar` shared library is distributed under the GNU Lesser General Public
License, version 2.1 (see `zbar-LICENCE.txt`).
3 changes: 3 additions & 0 deletions pyzbar/__init__.py
@@ -0,0 +1,3 @@
"""A ctypes-based wrapper around the zbar barcode reader."""

__version__ = '0.1.0'

0 comments on commit f75a50c

Please sign in to comment.