Skip to content

Commit 8b4b2ae

Browse files
committed
add BarCodeReader.zxing_version and BarCodeReader.zxing_version_info, and call it v0.13
Also, remove obsolete Python versions from .travis.yml, and migrate to openjdk-8-jre.
1 parent 4cdc8f3 commit 8b4b2ae

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ The `BarCodeReader` class is used to decode images:
2121
```python
2222
>>> import zxing
2323
>>> reader = zxing.BarCodeReader()
24+
>>> print(reader.zxing_version, reader.zxing_version_info)
25+
3.4.1 (3, 4, 1)
2426
>>> barcode = reader.decode("test/barcodes/QR_CODE-easy.png")
2527
>>> print(barcode)
2628
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)])

test/test_all.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ def setup_reader():
2626
if test_reader is None:
2727
test_reader = zxing.BarCodeReader()
2828

29+
30+
@with_setup(setup_reader)
31+
def test_version():
32+
global test_reader
33+
assert test_reader.zxing_version is not None
34+
assert '.'.join(map(str, test_reader.zxing_version_info)) == test_reader.zxing_version
35+
36+
2937
@with_setup(setup_reader)
3038
def _check_decoding(filename, expected_format, expected_raw, extra={}):
3139
global test_reader

zxing/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from urllib.parse import quote
1111
from enum import Enum
1212
import pathlib
13+
import zipfile
1314

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

2526
def __init__(self, classpath=None, java=None):
2627
self.java = java or 'java'
28+
self.zxing_version = self.zxing_version_info = None
2729
if classpath:
2830
self.classpath = classpath if isinstance(classpath, str) else ':'.join(classpath)
2931
elif "ZXING_CLASSPATH" in os.environ:
3032
self.classpath = os.environ.get("ZXING_CLASSPATH","")
3133
else:
3234
self.classpath = os.path.join(os.path.dirname(__file__), 'java', '*')
3335

36+
with zipfile.ZipFile(os.path.join(os.path.dirname(__file__), 'java', 'core.jar')) as c:
37+
for line in c.open('META-INF/MANIFEST.MF'):
38+
if line.startswith(b'Bundle-Version: '):
39+
self.zxing_version = line.split(b' ', 1)[1].strip().decode()
40+
self.zxing_version_info = tuple(int(n) for n in self.zxing_version.split('.'))
41+
break
42+
3443
def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcode=False, products_only=False):
3544
possible_formats = (possible_formats,) if isinstance(possible_formats, str) else possible_formats
3645

zxing/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__="0.12"
1+
__version__="0.14"

0 commit comments

Comments
 (0)