Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.12 #2979

Merged
merged 34 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
71c1478
Python 3.12
chayim Oct 5, 2023
7a679c2
Merge branch 'master' into ckpy312
chayim Oct 5, 2023
2a81f8a
removed quote
chayim Oct 18, 2023
296962c
Merge branch 'master' into ckpy312
chayim Oct 18, 2023
8fe9064
invoke upgrade
chayim Oct 18, 2023
c668538
Merge branch 'master' into ckpy312
chayim Jan 1, 2024
88bede2
Merge branch 'master' into ckpy312
chayim Jan 10, 2024
be650f4
ssl context wrapper change for test
chayim Jan 10, 2024
9a5b8e8
removing the |=
chayim Jan 10, 2024
e6487ed
seeing how codeql tls silencing works
chayim Jan 11, 2024
9ddbd87
Merge remote-tracking branch 'origin/master' into ck_py312
gerzse Jul 3, 2024
1a51cb4
Stabilize more tests and fix linters
gerzse Jul 4, 2024
b2a71a9
Stop requiring typing-extensions
gerzse Jul 4, 2024
f55036d
Enable tracemalloc
gerzse Jul 4, 2024
404405a
Better tracemalloc
gerzse Jul 4, 2024
1634946
Handle possible errors at SSL handshake
gerzse Jul 4, 2024
fcd9670
Remove event_loop fixture, as suggested by pytest
gerzse Jul 4, 2024
35efa8e
Fix async tests
gerzse Jul 4, 2024
976ae66
Merge remote-tracking branch 'origin/master' into ck_py312
gerzse Jul 4, 2024
0920116
Fix test results visualization in CI
gerzse Jul 4, 2024
dfa2a9c
More test fixes
gerzse Jul 5, 2024
71d83b3
Enable test profiling
gerzse Jul 5, 2024
663e3de
Fix upload of tests results
gerzse Jul 5, 2024
3668b43
Fix upload of tests results
gerzse Jul 5, 2024
0e62ac3
Fix upload of tests results
gerzse Jul 5, 2024
6b5f241
Fix upload of tests results
gerzse Jul 5, 2024
a595ff7
Remove CI test reporting
gerzse Jul 8, 2024
b9ae081
Speed up cluster slot initialization
gerzse Jul 8, 2024
8387597
Fix CI
gerzse Jul 8, 2024
8b1469d
Remove line profiler, it does not play well with PyPy
gerzse Jul 8, 2024
9aeec4c
Make profiling optional
gerzse Jul 8, 2024
097938a
Improve async cluster connection initialization
gerzse Jul 8, 2024
f6ed3c5
Run uvloop tests in matrix
gerzse Jul 8, 2024
bb73758
Speed up coverage with Python 3.12
gerzse Jul 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exclude =
ignore =
E126
E203
E231
E701
E704
F405
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
max-parallel: 15
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', 'pypy-3.8', 'pypy-3.9']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', 'pypy-3.8', 'pypy-3.9']
test-type: ['standalone', 'cluster']
connection-type: ['hiredis', 'plain']
env:
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.11']
python-version: ['3.8', '3.12']
test-type: ['standalone', 'cluster']
connection-type: ['hiredis', 'plain']
exclude:
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', 'pypy-3.8', 'pypy-3.9']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', 'pypy-3.8', 'pypy-3.9']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ click==8.0.4
flake8-isort==6.0.0
flake8==5.0.4
flynt~=0.69.0
invoke==1.7.3
invoke==2.2.0
mock==4.0.3
packaging>=20.4
pytest
Expand Down
2 changes: 1 addition & 1 deletion redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ def parse_url(url: str) -> ConnectKwargs:
try:
kwargs[name] = parser(value)
except (TypeError, ValueError):
raise ValueError(f"Invalid value for `{name}` in connection URL.")
raise ValueError(f"Invalid value for '{name}' in connection URL.")
else:
kwargs[name] = value

Expand Down
17 changes: 16 additions & 1 deletion redis/commands/graph/query_result.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
from collections import OrderedDict
from distutils.util import strtobool

# from prettytable import PrettyTable
from redis import ResponseError
Expand Down Expand Up @@ -571,3 +570,19 @@ async def parse_array(self, value):
"""
scalar = [await self.parse_scalar(value[i]) for i in range(len(value))]
return scalar


def strtobool(val):
"""
Convert a string representation of truth to true (1) or false (0).
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else.
"""
val = val.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return True
elif val in ("n", "no", "f", "false", "off", "0"):
return False
else:
raise ValueError(f"invalid truth value {val!r}")
2 changes: 1 addition & 1 deletion redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ def parse_url(url):
try:
kwargs[name] = parser(value)
except (TypeError, ValueError):
raise ValueError(f"Invalid value for `{name}` in connection URL.")
raise ValueError(f"Invalid value for '{name}' in connection URL.")
else:
kwargs[name] = value

Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
author_email="oss@redis.com",
python_requires=">=3.8",
install_requires=[
'async-timeout>=4.0.3; python_full_version<"3.11.3"',
'async-timeout>=4.0.3; python_full_version<"3.11.3"; typing-extensions;',
],
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand All @@ -51,11 +51,12 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
],
extras_require={
"hiredis": ["hiredis>=1.0.0"],
"ocsp": ["cryptography>=36.0.1", "pyopenssl==20.0.1", "requests>=2.26.0"],
"ocsp": ["cryptography>=36.0.1", "pyopenssl==23.2.1", "requests>=2.31.0"],
},
)
34 changes: 11 additions & 23 deletions tests/test_asyncio/test_connect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
import re
import socket
import ssl
Expand All @@ -14,9 +13,6 @@

from ..ssl_utils import get_ssl_filename

_logger = logging.getLogger(__name__)


_CLIENT_NAME = "test-suite-client"
_CMD_SEP = b"\r\n"
_SUCCESS_RESP = b"+OK" + _CMD_SEP
Expand Down Expand Up @@ -125,7 +121,7 @@ async def test_tcp_ssl_version_mismatch(tcp_address):
tcp_address,
certfile=certfile,
keyfile=keyfile,
ssl_version=ssl.TLSVersion.TLSv1_2,
maximum_ssl_version=ssl.TLSVersion.TLSv1_2,
)
await conn.disconnect()

Expand All @@ -135,7 +131,8 @@ async def _assert_connect(
server_address,
certfile=None,
keyfile=None,
ssl_version=None,
minimum_ssl_version=ssl.TLSVersion.TLSv1_2,
maximum_ssl_version=ssl.TLSVersion.TLSv1_3,
):
stop_event = asyncio.Event()
finished = asyncio.Event()
Expand All @@ -153,9 +150,8 @@ async def _handler(reader, writer):
elif certfile:
host, port = server_address
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
if ssl_version is not None:
context.minimum_version = ssl_version
context.maximum_version = ssl_version
context.minimum_version = minimum_ssl_version
context.maximum_version = maximum_ssl_version
context.load_cert_chain(certfile=certfile, keyfile=keyfile)
server = await asyncio.start_server(_handler, host=host, port=port, ssl=context)
else:
Expand All @@ -178,23 +174,18 @@ async def _handler(reader, writer):


async def _redis_request_handler(reader, writer, stop_event):
buffer = b""
command = None
command_ptr = None
fragment_length = None
while not stop_event.is_set() or buffer:
_logger.info(str(stop_event.is_set()))
try:
buffer += await asyncio.wait_for(reader.read(1024), timeout=0.5)
except TimeoutError:
continue
while not stop_event.is_set():
buffer = await reader.read(1024)
if not buffer:
continue
break
parts = re.split(_CMD_SEP, buffer)
buffer = parts[-1]
for fragment in parts[:-1]:
for fragment in parts:
fragment = fragment.decode()
_logger.info("Command fragment: %s", fragment)
if not fragment:
continue

if fragment.startswith("*") and command is None:
command = [None for _ in range(int(fragment[1:]))]
Expand All @@ -214,10 +205,7 @@ async def _redis_request_handler(reader, writer, stop_event):
continue

command = " ".join(command)
_logger.info("Command %s", command)
resp = _SUPPORTED_CMDS.get(command, _ERROR_RESP)
_logger.info("Response from %s", resp)
writer.write(resp)
await writer.drain()
command = None
_logger.info("Exit handler")
26 changes: 13 additions & 13 deletions tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pytest
from redis.connection import Connection, SSLConnection, UnixDomainSocketConnection
from redis.exceptions import ConnectionError
from redis.exceptions import RedisError

from .ssl_utils import get_ssl_filename

Expand Down Expand Up @@ -126,16 +126,16 @@
port=port,
client_name=_CLIENT_NAME,
ssl_ca_certs=certfile,
socket_timeout=10,
socket_timeout=3,
ssl_min_version=ssl.TLSVersion.TLSv1_3,
)
with pytest.raises(ConnectionError):
with pytest.raises(RedisError):
_assert_connect(
conn,
tcp_address,
certfile=certfile,
keyfile=keyfile,
ssl_version=ssl.PROTOCOL_TLSv1_2,
maximum_ssl_version=ssl.PROTOCOL_TLSv1_2,
)


Expand Down Expand Up @@ -164,14 +164,16 @@
*args,
certfile=None,
keyfile=None,
ssl_version=ssl.PROTOCOL_TLS,
minimum_ssl_version=ssl.TLSVersion.TLSv1_2,
maximum_ssl_version=ssl.TLSVersion.TLSv1_3,
**kw,
) -> None:
self._ready_event = threading.Event()
self._stop_requested = False
self._certfile = certfile
self._keyfile = keyfile
self._ssl_version = ssl_version
self._minimum_ssl_version = minimum_ssl_version
self._maximum_ssl_version = maximum_ssl_version
super().__init__(*args, **kw)

def service_actions(self):
Expand All @@ -191,13 +193,11 @@
if self._certfile is None:
return super().get_request()
newsocket, fromaddr = self.socket.accept()
connstream = ssl.wrap_socket(
newsocket,
server_side=True,
certfile=self._certfile,
keyfile=self._keyfile,
ssl_version=self._ssl_version,
)
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
context.load_cert_chain(certfile=self._certfile, keyfile=self._keyfile)
context.minimum_version = self._minimum_ssl_version
context.maximum_version = self._maximum_ssl_version
connstream = context.wrap_socket(newsocket, server_side=True)
Dismissed Show dismissed Hide dismissed
return connstream, fromaddr


Expand Down
Loading