Skip to content

Commit

Permalink
simplify LIBVALKEY_AVAILABLE and drop LIBVALKEY_PACK_AVAILABLE
Browse files Browse the repository at this point in the history
The former checked if the module version is >= 1.0, which is always true
for libvalkey Python module as the very first version will be 2.3.2.
Hence it can be simplified to the condition of `libvalkey` Python module
being available.

The latter is also obsolete, as the very first release of libvalkey-py
already contains `pack_command`. Hence, this boolean can be replaced
with `LIBVALKEY_AVAILABLE` where applicable.

Signed-off-by: Mikhail Koviazin <[email protected]>
  • Loading branch information
mkmkme committed Aug 1, 2024
1 parent 1768319 commit 984d6e0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tests/test_encoding.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import valkey
from valkey.connection import Connection
from valkey.utils import LIBVALKEY_PACK_AVAILABLE
from valkey.utils import LIBVALKEY_AVAILABLE

from .conftest import _get_client

Expand Down Expand Up @@ -76,7 +76,7 @@ def test_replace(self, request):


@pytest.mark.skipif(
LIBVALKEY_PACK_AVAILABLE,
LIBVALKEY_AVAILABLE,
reason="Packing via libvalkey does not preserve memoryviews",
)
class TestMemoryviewsAreNotPacked:
Expand Down
3 changes: 1 addition & 2 deletions valkey/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from .utils import (
CRYPTOGRAPHY_AVAILABLE,
LIBVALKEY_AVAILABLE,
LIBVALKEY_PACK_AVAILABLE,
SSL_AVAILABLE,
get_lib_version,
str_if_bytes,
Expand Down Expand Up @@ -258,7 +257,7 @@ def __del__(self):
def _construct_command_packer(self, packer):
if packer is not None:
return packer
elif LIBVALKEY_PACK_AVAILABLE:
elif LIBVALKEY_AVAILABLE:
return LibvalkeyRespSerializer()
else:
return PythonRespSerializer(self._buffer_cutoff, self.encoder.encode)
Expand Down
5 changes: 1 addition & 4 deletions valkey/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
try:
import libvalkey # noqa

# Only support libvalkey >= 1.0:
LIBVALKEY_AVAILABLE = not libvalkey.__version__.startswith("0.")
LIBVALKEY_PACK_AVAILABLE = hasattr(libvalkey, "pack_command")
LIBVALKEY_AVAILABLE = True
except ImportError:
LIBVALKEY_AVAILABLE = False
LIBVALKEY_PACK_AVAILABLE = False

try:
import ssl # noqa
Expand Down

0 comments on commit 984d6e0

Please sign in to comment.