Skip to content

Commit 938ce86

Browse files
committed
add BarCodeReader.zxing_version and BarCodeReader.zxing_version_info, and call it v0.13
Also, migrate from travis-ci.org → travis-ci.com, remove obsolete Python versions from .travis.yml, and use openjdk-8-jre (was openjdk-7-jre).
1 parent 4cdc8f3 commit 938ce86

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ sudo: false
88
language: python
99

1010
python:
11-
- "3.4"
12-
- "3.5"
1311
- "3.6"
1412
- "3.7"
1513
- "3.8"
1614
- "nightly"
1715

1816
before_script:
19-
- sudo apt-get install -qq openjdk-7-jre
17+
- sudo apt-get install -qq openjdk-8-jre
2018

2119
script:
2220
- python setup.py test

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# python-zxing
22

33
[![PyPI](https://img.shields.io/pypi/v/zxing.svg)](https://pypi.python.org/pypi/zxing)
4-
[![Build Status](https://api.travis-ci.org/dlenski/python-zxing.png)](https://travis-ci.org/dlenski/python-zxing)
4+
[![Build Status](https://api.travis-ci.com/dlenski/python-zxing.svg)](https://travis-ci.com/dlenski/python-zxing)
55
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
66

77
This is a wrapper for the [ZXing barcode library](https://github.com/zxing/zxing). (It's a "slightly less quick-and-dirty" fork of [oostendo/python-zxing](https://github.com/oostendo/python-zxing).)
@@ -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.13"

0 commit comments

Comments
 (0)