mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2026-01-06 03:22:43 +01:00
Make zstd optional
This commit is contained in:
@@ -10,8 +10,9 @@ See:
|
|||||||
|
|
||||||
import base64
|
import base64
|
||||||
import gzip
|
import gzip
|
||||||
|
import importlib.util
|
||||||
|
import sys
|
||||||
import zlib
|
import zlib
|
||||||
import zstd
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Callable, List, Optional, Union
|
from typing import Any, Callable, List, Optional, Union
|
||||||
from typing import cast as type_cast
|
from typing import cast as type_cast
|
||||||
@@ -24,6 +25,12 @@ from . import tiled_object
|
|||||||
from .common_types import Color, OrderedPair, Size
|
from .common_types import Color, OrderedPair, Size
|
||||||
from .util import parse_color
|
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)
|
@attr.s(auto_attribs=True, kw_only=True)
|
||||||
class Layer:
|
class Layer:
|
||||||
@@ -244,6 +251,11 @@ def _decode_tile_layer_data(
|
|||||||
unzipped_data = zlib.decompress(unencoded_data)
|
unzipped_data = zlib.decompress(unencoded_data)
|
||||||
elif compression == "gzip":
|
elif compression == "gzip":
|
||||||
unzipped_data = gzip.decompress(unencoded_data)
|
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":
|
elif compression == "zstd":
|
||||||
unzipped_data = zstd.decompress(unencoded_data)
|
unzipped_data = zstd.decompress(unencoded_data)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ setup_requires =
|
|||||||
setuptools >= 40.6
|
setuptools >= 40.6
|
||||||
pip >= 10
|
pip >= 10
|
||||||
install_requires =
|
install_requires =
|
||||||
zstd == 1.4.8.1
|
|
||||||
attrs
|
attrs
|
||||||
typing-extensions
|
typing-extensions
|
||||||
|
|
||||||
@@ -38,6 +37,9 @@ include =
|
|||||||
pytiled_parser.*
|
pytiled_parser.*
|
||||||
|
|
||||||
[options.extras_require]
|
[options.extras_require]
|
||||||
|
zstd =
|
||||||
|
zstd == 1.4.8.1
|
||||||
|
|
||||||
dev =
|
dev =
|
||||||
pytest
|
pytest
|
||||||
pytest-cov
|
pytest-cov
|
||||||
|
|||||||
Reference in New Issue
Block a user