Skip to content

Commit

Permalink
add BarCodeReader.zxing_version and BarCodeReader.zxing_version_info,…
Browse files Browse the repository at this point in the history
… and call it v0.13

Also, remove obsolete Python versions from .travis.yml, and migrate to openjdk-8-jre.
  • Loading branch information
dlenski committed Aug 3, 2021
1 parent 4cdc8f3 commit 8b4b2ae
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ The `BarCodeReader` class is used to decode images:
```python
>>> import zxing
>>> reader = zxing.BarCodeReader()
>>> print(reader.zxing_version, reader.zxing_version_info)
3.4.1 (3, 4, 1)
>>> barcode = reader.decode("test/barcodes/QR_CODE-easy.png")
>>> print(barcode)
BarCode(raw='This should be QR_CODE', parsed='This should be QR_CODE', format='QR_CODE', type='TEXT', points=[(15.0, 87.0), (15.0, 15.0), (87.0, 15.0), (75.0, 75.0)])
Expand Down
8 changes: 8 additions & 0 deletions test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ def setup_reader():
if test_reader is None:
test_reader = zxing.BarCodeReader()


@with_setup(setup_reader)
def test_version():
global test_reader
assert test_reader.zxing_version is not None
assert '.'.join(map(str, test_reader.zxing_version_info)) == test_reader.zxing_version


@with_setup(setup_reader)
def _check_decoding(filename, expected_format, expected_raw, extra={}):
global test_reader
Expand Down
9 changes: 9 additions & 0 deletions zxing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from urllib.parse import quote
from enum import Enum
import pathlib
import zipfile

from .version import __version__
import subprocess as sp, re, os
Expand All @@ -24,13 +25,21 @@ class BarCodeReader(object):

def __init__(self, classpath=None, java=None):
self.java = java or 'java'
self.zxing_version = self.zxing_version_info = None
if classpath:
self.classpath = classpath if isinstance(classpath, str) else ':'.join(classpath)
elif "ZXING_CLASSPATH" in os.environ:
self.classpath = os.environ.get("ZXING_CLASSPATH","")
else:
self.classpath = os.path.join(os.path.dirname(__file__), 'java', '*')

with zipfile.ZipFile(os.path.join(os.path.dirname(__file__), 'java', 'core.jar')) as c:
for line in c.open('META-INF/MANIFEST.MF'):
if line.startswith(b'Bundle-Version: '):
self.zxing_version = line.split(b' ', 1)[1].strip().decode()
self.zxing_version_info = tuple(int(n) for n in self.zxing_version.split('.'))
break

def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcode=False, products_only=False):
possible_formats = (possible_formats,) if isinstance(possible_formats, str) else possible_formats

Expand Down
2 changes: 1 addition & 1 deletion zxing/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__="0.12"
__version__="0.14"

0 comments on commit 8b4b2ae

Please sign in to comment.