Skip to content

Commit 6df9b4a

Browse files
committed
Make zstd optional
1 parent bdf206d commit 6df9b4a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pytiled_parser/layer.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
import base64
1212
import gzip
13+
import importlib.util
14+
import sys
1315
import zlib
14-
import zstd
1516
from pathlib import Path
1617
from typing import Any, Callable, List, Optional, Union
1718
from typing import cast as type_cast
@@ -24,6 +25,12 @@
2425
from .common_types import Color, OrderedPair, Size
2526
from .util import parse_color
2627

28+
zstd_spec = importlib.util.find_spec("zstd")
29+
if zstd_spec:
30+
import zstd # pylint: disable=import-outside-toplevel
31+
else:
32+
zstd = None # pylint: disable=invalid-name
33+
2734

2835
@attr.s(auto_attribs=True, kw_only=True)
2936
class Layer:
@@ -244,6 +251,11 @@ def _decode_tile_layer_data(
244251
unzipped_data = zlib.decompress(unencoded_data)
245252
elif compression == "gzip":
246253
unzipped_data = gzip.decompress(unencoded_data)
254+
elif compression == "zstd" and zstd is None:
255+
raise ValueError(
256+
"zstd compression support is not installed."
257+
"To install use 'pip install pytiled-parser[zstd]'"
258+
)
247259
elif compression == "zstd":
248260
unzipped_data = zstd.decompress(unencoded_data)
249261
else:

setup.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ setup_requires =
2828
setuptools >= 40.6
2929
pip >= 10
3030
install_requires =
31-
zstd == 1.4.8.1
3231
attrs
3332
typing-extensions
3433

@@ -38,6 +37,9 @@ include =
3837
pytiled_parser.*
3938

4039
[options.extras_require]
40+
zstd =
41+
zstd == 1.4.8.1
42+
4143
dev =
4244
pytest
4345
pytest-cov

0 commit comments

Comments
 (0)