Skip to content

Commit ad7e983

Browse files
authored
Merge pull request #13 from jakirkham/add_py2_lzma
Support LZMA on Python 2 via backports.lzma
2 parents 7a3a3b9 + 992943b commit ad7e983

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
language: python
22

3+
sudo: false
4+
5+
addons:
6+
apt:
7+
packages:
8+
- liblzma-dev
9+
310
python:
411
- 2.7
512
- 3.4

numcodecs/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525

2626
from numcodecs.version import version as __version__
2727
from numcodecs.registry import get_codec, register_codec
28-
from numcodecs.compat import PY2
2928

3029
from numcodecs.zlib import Zlib
3130
register_codec(Zlib)
3231

3332
from numcodecs.bz2 import BZ2
3433
register_codec(BZ2)
3534

36-
if not PY2:
35+
try:
3736
from numcodecs.lzma import LZMA
3837
register_codec(LZMA)
38+
except ImportError: # pragma: no cover
39+
pass
3940

4041
try:
4142
from numcodecs import blosc as _blosc

numcodecs/lzma.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
from __future__ import absolute_import, print_function, division
33

44

5+
_lzma = None
56
try:
67
import lzma as _lzma
78
except ImportError: # pragma: no cover
8-
pass
9-
else:
9+
try:
10+
from backports import lzma as _lzma
11+
except ImportError:
12+
pass
13+
14+
15+
if _lzma:
1016

1117
import numpy as np
1218
from numcodecs.abc import Codec

numcodecs/tests/test_lzma.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
from __future__ import absolute_import, print_function, division
33

44

5-
from numcodecs.compat import PY2
5+
_lzma = None
6+
try:
7+
import lzma as _lzma
8+
except ImportError: # pragma: no cover
9+
try:
10+
from backports import lzma as _lzma
11+
except ImportError:
12+
pass
613

714

8-
if not PY2:
15+
if _lzma:
916

10-
import lzma as _lzma
1117
import itertools
1218
import numpy as np
1319
from numcodecs.lzma import LZMA

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ envlist = py27, py34, py35, docs
1010
setenv =
1111
PYTHONHASHSEED = 42
1212
commands =
13+
py27: pip install -U backports.lzma
1314
python setup.py build_ext --inplace
1415
py27: nosetests -v numcodecs
1516
py34,py35: nosetests -v --with-coverage --cover-erase --cover-min-percentage=100 --cover-package=numcodecs --with-doctest --doctest-options=+NORMALIZE_WHITESPACE numcodecs

0 commit comments

Comments
 (0)