From 7aac05803708e4adeba2eeff2080c796a4044c2f Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Sat, 9 Jun 2018 10:52:40 +0100 Subject: [PATCH 1/3] [#31] Move to rst for README - hopefully Fix display of README badges on PyPI --- .gitignore | 2 - CHANGELOG.md | 6 +- DEVELOPING.md | 7 +- README.md | 207 ----------------------------------------- README.rst | 225 +++++++++++++++++++++++++++++++++++++++++++++ pyzbar/__init__.py | 2 +- setup.py | 1 - 7 files changed, 232 insertions(+), 218 deletions(-) delete mode 100644 README.md create mode 100644 README.rst diff --git a/.gitignore b/.gitignore index 224aed7..419d130 100644 --- a/.gitignore +++ b/.gitignore @@ -4,9 +4,7 @@ build dist .tox -README.rst .coverage htmlcov *dll MANIFEST.in - diff --git a/CHANGELOG.md b/CHANGELOG.md index 516e3c2..f34d8aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ +### v0.1.8 + +* #31 README badges no longer displaying on PyPI + ### v0.1.7 -Fix display of images in README +* Fix display of images in README ### v0.1.6 diff --git a/DEVELOPING.md b/DEVELOPING.md index 4863527..271d740 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -41,18 +41,13 @@ frozen binary. ``` 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` wheels will + Create source and wheel builds. The `win32` and `win_amd64` wheels will contain the appropriate `zbar.dll` and its dependencies. - Including just the DLLs we want is pain... - ``` - pandoc --from=markdown --to=rst README.md -o README.rst rm -rf build dist MANIFEST.in pyzbar.egg-info cp MANIFEST.in.all MANIFEST.in ./setup.py bdist_wheel diff --git a/README.md b/README.md deleted file mode 100644 index 330e1d9..0000000 --- a/README.md +++ /dev/null @@ -1,207 +0,0 @@ -# pyzbar - -[![Python Versions](https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5%2C%203.6-blue.svg)](https://github.com/NaturalHistoryMuseum/pyzbar) -[![PyPI version](https://badge.fury.io/py/pyzbar.svg)](https://pypi.python.org/pypi/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) - -Read one-dimensional barcodes and QR codes from Python 2 and 3 using the -[zbar](http://zbar.sourceforge.net/) library. - -* Pure python -* Works with PIL / Pillow images, OpenCV / numpy `ndarray`s, and raw bytes -* Decodes locations of barcodes -* No dependencies, other than the zbar library itself -* Tested on Python 2.7, and Python 3.4 to 3.6 - -The older [zbar](https://sourceforge.net/p/zbar/code/ci/default/tree/python/) -package is stuck in Python 2.x-land. -The [zbarlight](https://github.com/Polyconseil/zbarlight/) package doesn't -provide support for Windows and depends upon Pillow. - -## 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. - -Mac OS X: - -``` -brew install zbar -``` - -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=b'Foramenifera', type='CODE128', - rect=Rect(left=37, top=550, width=324, height=76), - polygon=[ - Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626), - Point(x=361, y=550) - ] - ) - Decoded( - data=b'Rana temporaria', type='CODE128', - rect=Rect(left=4, top=0, width=390, height=76), - polygon=[ - Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76), - Point(x=394, y=0) - ] - ) -] -``` - -It also accepts instances of `numpy.ndarray`, which might come from loading -images using [OpenCV](http://opencv.org/). - -``` ->>> import cv2 ->>> decode(cv2.imread('pyzbar/tests/code128.png')) -[ - Decoded( - data=b'Foramenifera', type='CODE128', - rect=Rect(left=37, top=550, width=324, height=76), - polygon=[ - Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626), - Point(x=361, y=550) - ] - ) - Decoded( - data=b'Rana temporaria', type='CODE128', - rect=Rect(left=4, top=0, width=390, height=76), - polygon=[ - Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76), - Point(x=394, y=0) - ] - ) -] -``` - -You can also provide a tuple `(pixels, width, height)`, where the image data -is eight bits-per-pixel. - -``` ->>> image = cv2.imread('pyzbar/tests/code128.png') ->>> height, width = image.shape[:2] - ->>> # 8 bpp by considering just the blue channel ->>> decode((image[:, :, 0].astype('uint8').tobytes(), width, height)) -[ - Decoded( - data=b'Foramenifera', type='CODE128', - rect=Rect(left=37, top=550, width=324, height=76), - polygon=[ - Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626), - Point(x=361, y=550) - ] - ) - Decoded( - data=b'Rana temporaria', type='CODE128', - rect=Rect(left=4, top=0, width=390, height=76), - polygon=[ - Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76), - Point(x=394, y=0) - ] - ) -] - ->>> # 8 bpp by converting image to greyscale ->>> grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) ->>> decode((grey.tobytes(), width, height)) -[ - Decoded( - data=b'Foramenifera', type='CODE128', - rect=Rect(left=37, top=550, width=324, height=76), - polygon=[ - Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626), - Point(x=361, y=550) - ] - ) - Decoded( - data=b'Rana temporaria', type='CODE128', - rect=Rect(left=4, top=0, width=390, height=76), - polygon=[ - Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76), - Point(x=394, y=0) - ] - ) -] - ->>> # If you don't provide 8 bpp ->>> decode((image.tobytes(), width, height)) -Traceback (most recent call last): - File "", line 1, in - File "/Users/lawh/projects/pyzbar/pyzbar/pyzbar.py", line 102, in decode - raise PyZbarError('Unsupported bits-per-pixel [{0}]'.format(bpp)) -pyzbar.pyzbar_error.PyZbarError: Unsupported bits-per-pixel [24] -``` - -The default behaviour is to decode all symbol types. You can look for just your -symbol types - -``` ->>> from pyzbar.pyzbar import ZBarSymbol ->>> # Look for just qrcode ->>> decode(Image.open('pyzbar/tests/qrcode.png'), symbols=[ZBarSymbol.QRCODE]) -[ - Decoded( - data=b'Thalassiodracon', type='QRCODE', - rect=Rect(left=27, top=27, width=145, height=145), - polygon=[ - Point(x=27, y=27), Point(x=27, y=172), Point(x=172, y=172), - Point(x=172, y=27) - ] - ) -] - - ->>> # If we look for just code128, the qrcodes in the image will not be detected ->>> decode(Image.open('pyzbar/tests/qrcode.png'), symbols=[ZBarSymbol.CODE128]) -[] -``` - -## Bounding boxes and polygons - -The blue and pink boxes show `rect` and `polygon`, respectively, for barcodes in -`pyzbar/tests/qrcode.png` -(see [bounding_box_and_polygon.py](https://github.com/NaturalHistoryMuseum/pyzbar/blob/master/bounding_box_and_polygon.py)). - -![Two barcodes with bounding boxes and polygons](https://github.com/NaturalHistoryMuseum/pyzbar/raw/master/bounding_box_and_polygon.png) - -## Windows error message -If you see an ugly `ImportError` when importing `pyzbar` on Windows you will -most likely need the -[Visual C++ Redistributable Packages for Visual Studio 2013](https://www.microsoft.com/en-US/download/details.aspx?id=40784). -Install `vcredist_x64.exe` if using 64-bit Python, `vcredist_x86.exe` if using -32-bit Python. - -## Contributors - -* Alex (@globophobe) - first implementation of barcode locations - -## 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`). diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..a666227 --- /dev/null +++ b/README.rst @@ -0,0 +1,225 @@ +pyzbar +====== + +.. image:: https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5%2C%203.6-blue.svg + :target: https://github.com/NaturalHistoryMuseum/pyzbar + +.. image:: https://badge.fury.io/py/pyzbar.svg + :target: https://pypi.python.org/pypi/pyzbar + +.. image:: https://travis-ci.org/NaturalHistoryMuseum/pyzbar.svg?branch=master + :target: https://travis-ci.org/NaturalHistoryMuseum/pyzbar + +.. image:: https://coveralls.io/repos/github/NaturalHistoryMuseum/pyzbar/badge.svg?branch=master + :target: https://coveralls.io/github/NaturalHistoryMuseum/pyzbar?branch=master + +Read one-dimensional barcodes and QR codes from Python 2 and 3 using the +`zbar `__ library. + +- Pure python +- Works with PIL / Pillow images, OpenCV / numpy ``ndarray``\ s, and raw bytes +- Decodes locations of barcodes +- No dependencies, other than the zbar library itself +- Tested on Python 2.7, and Python 3.4 to 3.6 + +The older `zbar `__ +package is stuck in Python 2.x-land. +The `zbarlight `__ package does not +provide support for Windows and depends upon Pillow. + +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. + +Mac OS X: + +:: + + brew install zbar + +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=b'Foramenifera', type='CODE128', + rect=Rect(left=37, top=550, width=324, height=76), + polygon=[ + Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626), + Point(x=361, y=550) + ] + ) + Decoded( + data=b'Rana temporaria', type='CODE128', + rect=Rect(left=4, top=0, width=390, height=76), + polygon=[ + Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76), + Point(x=394, y=0) + ] + ) + ] + +It also accepts instances of ``numpy.ndarray``, which might come from loading +images using `OpenCV `__. + +:: + + >>> import cv2 + >>> decode(cv2.imread('pyzbar/tests/code128.png')) + [ + Decoded( + data=b'Foramenifera', type='CODE128', + rect=Rect(left=37, top=550, width=324, height=76), + polygon=[ + Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626), + Point(x=361, y=550) + ] + ) + Decoded( + data=b'Rana temporaria', type='CODE128', + rect=Rect(left=4, top=0, width=390, height=76), + polygon=[ + Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76), + Point(x=394, y=0) + ] + ) + ] + +You can also provide a tuple ``(pixels, width, height)``, where the image data +is eight bits-per-pixel. + +:: + + >>> image = cv2.imread('pyzbar/tests/code128.png') + >>> height, width = image.shape[:2] + + >>> # 8 bpp by considering just the blue channel + >>> decode((image[:, :, 0].astype('uint8').tobytes(), width, height)) + [ + Decoded( + data=b'Foramenifera', type='CODE128', + rect=Rect(left=37, top=550, width=324, height=76), + polygon=[ + Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626), + Point(x=361, y=550) + ] + ) + Decoded( + data=b'Rana temporaria', type='CODE128', + rect=Rect(left=4, top=0, width=390, height=76), + polygon=[ + Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76), + Point(x=394, y=0) + ] + ) + ] + + >>> # 8 bpp by converting image to greyscale + >>> grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) + >>> decode((grey.tobytes(), width, height)) + [ + Decoded( + data=b'Foramenifera', type='CODE128', + rect=Rect(left=37, top=550, width=324, height=76), + polygon=[ + Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626), + Point(x=361, y=550) + ] + ) + Decoded( + data=b'Rana temporaria', type='CODE128', + rect=Rect(left=4, top=0, width=390, height=76), + polygon=[ + Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76), + Point(x=394, y=0) + ] + ) + ] + + >>> # If you don't provide 8 bpp + >>> decode((image.tobytes(), width, height)) + Traceback (most recent call last): + File "", line 1, in + File "/Users/lawh/projects/pyzbar/pyzbar/pyzbar.py", line 102, in decode + raise PyZbarError('Unsupported bits-per-pixel [{0}]'.format(bpp)) + pyzbar.pyzbar_error.PyZbarError: Unsupported bits-per-pixel [24] + +The default behaviour is to decode all symbol types. You can look for just your +symbol types + +:: + + >>> from pyzbar.pyzbar import ZBarSymbol + >>> # Look for just qrcode + >>> decode(Image.open('pyzbar/tests/qrcode.png'), symbols=[ZBarSymbol.QRCODE]) + [ + Decoded( + data=b'Thalassiodracon', type='QRCODE', + rect=Rect(left=27, top=27, width=145, height=145), + polygon=[ + Point(x=27, y=27), Point(x=27, y=172), Point(x=172, y=172), + Point(x=172, y=27) + ] + ) + ] + + + >>> # If we look for just code128, the qrcodes in the image will not be detected + >>> decode(Image.open('pyzbar/tests/qrcode.png'), symbols=[ZBarSymbol.CODE128]) + [] + +Bounding boxes and polygons +--------------------------- + +The blue and pink boxes show ``rect`` and ``polygon``, respectively, for +barcodes in ``pyzbar/tests/qrcode.png`` (see +`bounding_box_and_polygon.py `__). + +.. figure:: https://github.com/NaturalHistoryMuseum/pyzbar/raw/master/bounding_box_and_polygon.png + :alt: Two barcodes with bounding boxes and polygons + +Windows error message +--------------------- + +If you see an ugly ``ImportError`` when importing ``pyzbar`` on Windows +you will most likely need the `Visual C++ Redistributable Packages for Visual +Studio 2013 +`__. +Install ``vcredist_x64.exe`` if using 64-bit Python, ``vcredist_x86.exe`` if +using 32-bit Python. + +Contributors +------------ + +- Alex (@globophobe) - first implementation of barcode locations + +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``). diff --git a/pyzbar/__init__.py b/pyzbar/__init__.py index 38c39cd..333ed65 100644 --- a/pyzbar/__init__.py +++ b/pyzbar/__init__.py @@ -1,3 +1,3 @@ """Read one-dimensional barcodes and QR codes from Python 2 and 3.""" -__version__ = '0.1.7' +__version__ = '0.1.8' diff --git a/setup.py b/setup.py index 1ed4fb1..8443f42 100755 --- a/setup.py +++ b/setup.py @@ -14,7 +14,6 @@ def readme(): try: - # README.rst is generated from README.md (see DEVELOPING.md) with open('README.rst') as f: return f.read() except: From 755c52aae7d98950f89eeae861fa2fe6b8624427 Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Sat, 9 Jun 2018 12:52:45 +0100 Subject: [PATCH 2/3] [#31] Long description content type --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 8443f42..d33f421 100755 --- a/setup.py +++ b/setup.py @@ -29,6 +29,7 @@ def readme(): 'license': 'MIT', 'description': pyzbar.__doc__, 'long_description': readme(), + 'long_description_content_type': 'text/x-rst', 'packages': ['pyzbar', 'pyzbar.scripts', 'pyzbar.tests'], 'test_suite': 'pyzbar.tests', 'scripts': ['pyzbar/scripts/{0}.py'.format(script) for script in SCRIPTS], From 3457aec8a7037c0c0561cd21f0edabc22fdb2ba3 Mon Sep 17 00:00:00 2001 From: Lawrence Hudson Date: Sat, 9 Jun 2018 12:52:57 +0100 Subject: [PATCH 3/3] [#31] Correct TestPyPI link --- DEVELOPING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DEVELOPING.md b/DEVELOPING.md index 271d740..e642d4d 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -63,7 +63,7 @@ pip install wheel rm -rf build MANIFEST.in pyzbar.egg-info ``` -3. Release to pypitest (see https://wiki.python.org/moin/TestPyPI for details) +3. Release to TestPyPI (see https://packaging.python.org/guides/using-testpypi/) ``` mkvirtualenv pypi @@ -71,7 +71,7 @@ pip install wheel twine upload -r pypitest dist/* ``` -4. Test the release to pypitest +4. Test the release to TestPyPI * Check https://test.pypi.org/project/pyzbar/