Make zstd optional

This commit is contained in:
Darren Eberly
2021-02-21 15:40:44 -05:00
parent bdf206d740
commit 6df9b4af61
2 changed files with 16 additions and 2 deletions

View File

@@ -10,8 +10,9 @@ See:
import base64
import gzip
import importlib.util
import sys
import zlib
import zstd
from pathlib import Path
from typing import Any, Callable, List, Optional, Union
from typing import cast as type_cast
@@ -24,6 +25,12 @@ from . import tiled_object
from .common_types import Color, OrderedPair, Size
from .util import parse_color
zstd_spec = importlib.util.find_spec("zstd")
if zstd_spec:
import zstd # pylint: disable=import-outside-toplevel
else:
zstd = None # pylint: disable=invalid-name
@attr.s(auto_attribs=True, kw_only=True)
class Layer:
@@ -244,6 +251,11 @@ def _decode_tile_layer_data(
unzipped_data = zlib.decompress(unencoded_data)
elif compression == "gzip":
unzipped_data = gzip.decompress(unencoded_data)
elif compression == "zstd" and zstd is None:
raise ValueError(
"zstd compression support is not installed."
"To install use 'pip install pytiled-parser[zstd]'"
)
elif compression == "zstd":
unzipped_data = zstd.decompress(unencoded_data)
else:

View File

@@ -28,7 +28,6 @@ setup_requires =
setuptools >= 40.6
pip >= 10
install_requires =
zstd == 1.4.8.1
attrs
typing-extensions
@@ -38,6 +37,9 @@ include =
pytiled_parser.*
[options.extras_require]
zstd =
zstd == 1.4.8.1
dev =
pytest
pytest-cov