Skip to content

Commit

Permalink
Updated pdm, dev dependencies, and pre-commit pinned versions (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
francis-clairicia authored Nov 10, 2024
1 parent 90a4e9c commit 92b2be9
Show file tree
Hide file tree
Showing 20 changed files with 326 additions and 302 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-tox/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ runs:
- uses: pdm-project/setup-pdm@2f3a9be7ac56a6e5c1ea605f8e9d0f0500363705 # v4
id: pdm
with:
version: '2.19.3'
version: '2.20.1'
python-version: ${{ inputs.python-version }}
cache: true
cache-restore-exact-match: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ concurrency:
cancel-in-progress: true

env:
PDM_VERSION: '2.19.3' # Used by FreeBSD VM
PDM_VERSION: '2.20.1' # Used by FreeBSD VM

jobs:
type-hinting:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ concurrency:

env:
PYTEST_VERBOSE_FLAG: ${{ inputs.verbose && '-v' || '' }}
PDM_VERSION: '2.19.3' # Used by FreeBSD VM
PDM_VERSION: '2.20.1' # Used by FreeBSD VM

jobs:
tests:
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ci:

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
rev: v3.19.0
hooks:
- id: pyupgrade
args: ['--py311-plus']
Expand All @@ -32,21 +32,21 @@ repos:
- id: flake8
args: ['--config', '.flake8']
additional_dependencies: [
'flake8-dunder-all @ git+https://github.com/francis-clairicia/[email protected]'
'git+https://github.com/francis-clairicia/[email protected]'
]
- repo: https://github.com/PyCQA/bandit
rev: '1.7.10'
hooks:
- id: bandit
args: ['-c', '.bandit.yml']
- repo: https://github.com/aio-libs/sort-all
rev: 'v1.2.0'
rev: 'v1.3.0'
hooks:
- id: sort-all
types: [] # Overwrite with empty in order to fallback to types_or
types_or: [python, pyi]
- repo: https://github.com/pdm-project/pdm
rev: '2.19.3'
rev: '2.20.1'
hooks:
- id: pdm-lock-check
- id: pdm-export
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build:
python: "3.11"
jobs:
post_create_environment:
- pip install --no-cache-dir pdm==2.19.3
- pip install --no-cache-dir pdm==2.20.1
- pdm config check_update false
- pdm use -f $READTHEDOCS_VIRTUALENV_PATH
post_install:
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### System Requirements

- CPython >= 3.11.0
- [PDM](https://pdm-project.org/latest/#installation) >= 2.19
- [PDM](https://pdm-project.org/latest/#installation) >= 2.20
- The [Rust Toolchain](https://rustup.rs/)

### Virtual environment
Expand Down
2 changes: 1 addition & 1 deletion benchmark_server/servers/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ outcome==1.3.0.post0
pycparser==2.22
sniffio==1.3.1
sortedcontainers==2.4.0
trio==0.26.2
trio==0.27.0
uvloop==0.21.0; os_name == "posix"
547 changes: 286 additions & 261 deletions pdm.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ format = [
"black>=22.6.0",
]
mypy = [
"mypy~=1.11,!=1.12.0", # mypy 1.12 breaks all the type inference for the callbacks and the context managers.
"mypy~=1.13",
]
types-msgpack = [
"msgpack-types>=0.5.0",
]
flake8 = [
"flake8>=7.0,<8",
"flake8-dunder-all @ git+https://github.com/francis-clairicia/[email protected]",
"git+https://github.com/francis-clairicia/[email protected]",
]
bandit = [
"bandit>=1.7.5,<2",
Expand All @@ -103,12 +103,12 @@ test = [
"pytest~=8.3",
"pytest-xdist~=3.3",
"pytest-mock~=3.10",
"pytest-cov~=5.0",
"pytest-cov~=6.0",
"pytest-asyncio~=0.24.0",
"trove-classifiers>=2023.11.9",
# "pytest-retry~=1.6",
# Temporary use VCS to get the modifications added on main (c.f. https://github.com/str0zzapreti/pytest-retry/pull/39)
"pytest-retry @ git+https://github.com/str0zzapreti/pytest-retry.git@bb465fff6f01f3f90a77229468f7e08a3bdbce20",
"git+https://github.com/str0zzapreti/pytest-retry.git@bb465fff6f01f3f90a77229468f7e08a3bdbce20",
]
test-ssl = [
"trustme~=1.0",
Expand All @@ -128,7 +128,7 @@ doc = [
]
micro-benchmark = [
"pytest~=8.3",
"pytest-benchmark[histogram]~=4.0",
"pytest-benchmark[histogram]~=5.0",
]
benchmark-servers = [
"build~=1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/easynetwork/lowlevel/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def prepend_argument(
func: Callable[Concatenate[_T_Arg, _P], _T_Return] | None = None,
) -> Callable[[Callable[Concatenate[_T_Arg, _P], _T_Return]], Callable[_P, _T_Return]] | Callable[_P, _T_Return]:
def decorator(func: Callable[Concatenate[_T_Arg, _P], _T_Return], /) -> Callable[_P, _T_Return]:
return functools.partial(func, arg)
return functools.partial(func, arg) # type: ignore[call-arg]

if func is not None:
return decorator(func)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ async def sleep(self, delay: float) -> None:

async def sleep_forever(self) -> NoReturn:
await self.__trio.sleep_forever()
raise AssertionError("Expected code to be unreachable")

def create_task_group(self) -> TaskGroup:
from .tasks import TaskGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def send_all_from_iterable(self, iterable_of_data: Iterable[bytes | bytear
if not supports_async_socket_sendmsg(socket):
return await super().send_all_from_iterable(iterable_of_data)

buffers: deque[memoryview] = deque(map(memoryview, iterable_of_data))
buffers: deque[memoryview] = deque(map(memoryview, iterable_of_data)) # type: ignore[arg-type]
del iterable_of_data

if not buffers:
Expand Down
2 changes: 1 addition & 1 deletion src/easynetwork/lowlevel/api_sync/transports/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def send_all_from_iterable(self, iterable_of_data: Iterable[bytes | bytearray |
if not _utils.supports_socket_sendmsg(socket):
return super().send_all_from_iterable(iterable_of_data, timeout)

buffers: deque[memoryview] = deque(map(memoryview, iterable_of_data))
buffers: deque[memoryview] = deque(map(memoryview, iterable_of_data)) # type: ignore[arg-type]
del iterable_of_data

def try_sendmsg() -> int:
Expand Down
2 changes: 1 addition & 1 deletion src/easynetwork/lowlevel/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def _setup_func(self, func: Callable[_P, _T]) -> Callable[_P, _T]:
if self.__handle_contexts:
ctx = contextvars.copy_context()
ctx.run(sniffio.current_async_library_cvar.set, None)
func = functools.partial(ctx.run, func)
func = functools.partial(ctx.run, func) # type: ignore[call-arg]
return func

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ async def test____serve____task_group(

# Act
task_group: AsyncIOTaskGroup | None
async with AsyncIOTaskGroup() if external_group else contextlib.nullcontext() as task_group: # type: ignore[attr-defined]
async with AsyncIOTaskGroup() if external_group else contextlib.nullcontext() as task_group:
with pytest.raises(asyncio.CancelledError):
await socket.serve(datagram_received_cb, task_group)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ async def test____serve____default(

# Act
task_group: AsyncIOTaskGroup | None
async with AsyncIOTaskGroup() if external_group else contextlib.nullcontext() as task_group: # type: ignore[attr-defined]
async with AsyncIOTaskGroup() if external_group else contextlib.nullcontext() as task_group:
with pytest.raises(asyncio.CancelledError):
await listener.serve(handler, task_group)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ async def test____serve____default(

# Act
task_group: TaskGroup | None
async with trio_backend.create_task_group() if external_group else contextlib.nullcontext() as task_group: # type: ignore[attr-defined]
async with trio_backend.create_task_group() if external_group else contextlib.nullcontext() as task_group:
with pytest.raises(trio.Cancelled):
await listener.serve(handler, task_group)

Expand Down
10 changes: 5 additions & 5 deletions tests/unit_test/test_async/test_trio_backend/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def mock_trio_tcp_socket(cls, mock_trio_tcp_socket: MagicMock, mocker: MockerFix
# therefore the mocker's autospec will consider sendmsg() unknown on these ones.
mock_trio_tcp_socket.sendmsg = mocker.AsyncMock(
spec=lambda *args: None,
side_effect=lambda buffers, *args: sum(map(len, map(memoryview, buffers))),
side_effect=lambda buffers, *args: sum(map(len, map(lambda v: memoryview(v), buffers))),
)
return mock_trio_tcp_socket

Expand Down Expand Up @@ -297,7 +297,7 @@ def sendmsg_side_effect(buffers: Iterable[ReadableBuffer]) -> int:

buffers = list(buffers)
chunks.append(list(map(bytes, buffers)))
return sum(map(len, map(memoryview, buffers)))
return sum(map(len, map(lambda v: memoryview(v), buffers)))

mock_trio_socket_stream.socket.sendmsg.side_effect = sendmsg_side_effect

Expand All @@ -321,7 +321,7 @@ async def test____send_all_from_iterable____nb_buffers_greather_than_SC_IOV_MAX(
def sendmsg_side_effect(buffers: Iterable[ReadableBuffer]) -> int:
buffers = list(buffers)
chunks.append(list(map(bytes, buffers)))
return sum(map(len, map(memoryview, buffers)))
return sum(map(len, map(lambda v: memoryview(v), buffers)))

mock_trio_socket_stream.socket.sendmsg.side_effect = sendmsg_side_effect

Expand All @@ -347,7 +347,7 @@ async def test____send_all_from_iterable____adjust_leftover_buffer(
def sendmsg_side_effect(buffers: Iterable[ReadableBuffer]) -> int:
buffers = list(buffers)
chunks.append(list(map(bytes, buffers)))
return min(sum(map(len, map(memoryview, buffers))), 3)
return min(sum(map(len, map(lambda v: memoryview(v), buffers))), 3)

mock_trio_socket_stream.socket.sendmsg.side_effect = sendmsg_side_effect

Expand Down Expand Up @@ -626,7 +626,7 @@ async def test____serve____default(

# Act
task_group: TaskGroup | None
async with trio_backend.create_task_group() if external_group else contextlib.nullcontext() as task_group: # type: ignore[attr-defined]
async with trio_backend.create_task_group() if external_group else contextlib.nullcontext() as task_group:
with pytest.raises(trio.Cancelled):
await listener.serve(handler, task_group)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def mock_tcp_socket(mock_tcp_socket: MagicMock, socket_fileno: int, mocker: Mock
# therefore the mocker's autospec will consider sendmsg() unknown on these ones.
mock_tcp_socket.sendmsg = mocker.MagicMock(
spec=lambda *args: None,
side_effect=lambda buffers, *args: sum(map(len, map(memoryview, buffers))),
side_effect=lambda buffers, *args: sum(map(len, map(lambda v: memoryview(v), buffers))),
)
return mock_tcp_socket

Expand Down Expand Up @@ -307,7 +307,7 @@ def test____send_all_from_iterable____use_socket_sendmsg_when_available(
def sendmsg_side_effect(buffers: Iterable[ReadableBuffer]) -> int:
buffers = list(buffers)
chunks.append(list(map(bytes, buffers)))
return sum(map(len, map(memoryview, buffers)))
return sum(map(len, map(lambda v: memoryview(v), buffers)))

mock_tcp_socket.sendmsg.side_effect = sendmsg_side_effect

Expand All @@ -332,7 +332,7 @@ def test____send_all_from_iterable____nb_buffers_greather_than_SC_IOV_MAX(
def sendmsg_side_effect(buffers: Iterable[ReadableBuffer]) -> int:
buffers = list(buffers)
chunks.append(list(map(bytes, buffers)))
return sum(map(len, map(memoryview, buffers)))
return sum(map(len, map(lambda v: memoryview(v), buffers)))

mock_tcp_socket.sendmsg.side_effect = sendmsg_side_effect

Expand All @@ -358,7 +358,7 @@ def test____send_all_from_iterable____adjust_leftover_buffer(
def sendmsg_side_effect(buffers: Iterable[ReadableBuffer]) -> int:
buffers = list(buffers)
chunks.append(list(map(bytes, buffers)))
return min(sum(map(len, map(memoryview, buffers))), 3)
return min(sum(map(len, map(lambda v: memoryview(v), buffers))), 3)

mock_tcp_socket.sendmsg.side_effect = sendmsg_side_effect

Expand Down Expand Up @@ -395,7 +395,7 @@ def sendmsg_side_effect(buffers: Iterable[ReadableBuffer]) -> int:
raise to_raise.pop(0)
buffers = list(buffers)
chunks.append(list(map(bytes, buffers)))
return sum(map(len, map(memoryview, buffers)))
return sum(map(len, map(lambda v: memoryview(v), buffers)))

mock_tcp_socket.sendmsg.side_effect = sendmsg_side_effect

Expand Down
16 changes: 8 additions & 8 deletions tests/unit_test/test_tools/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def test____supports_socket_sendmsg____have_sendmsg_method(
mock_socket = mock_socket_factory()
mock_socket.sendmsg = mocker.MagicMock(
spec=lambda *args: None,
side_effect=lambda buffers, *args: sum(map(len, map(memoryview, buffers))),
side_effect=lambda buffers, *args: sum(map(len, map(lambda v: memoryview(v), buffers))),
)

# Act & Assert
Expand Down Expand Up @@ -539,7 +539,7 @@ def test____iter_bytes____iterate_over_bytes_returning_one_byte() -> None:

def test____adjust_leftover_buffer____consume_whole_buffer() -> None:
# Arrange
buffers: deque[memoryview] = deque(map(memoryview, [b"abc", b"de", b"fgh"]))
buffers: deque[memoryview] = deque(map(lambda v: memoryview(v), [b"abc", b"de", b"fgh"]))

# Act
adjust_leftover_buffer(buffers, 8)
Expand All @@ -550,24 +550,24 @@ def test____adjust_leftover_buffer____consume_whole_buffer() -> None:

def test____adjust_leftover_buffer____remove_some_buffers() -> None:
# Arrange
buffers: deque[memoryview] = deque(map(memoryview, [b"abc", b"de", b"fgh"]))
buffers: deque[memoryview] = deque(map(lambda v: memoryview(v), [b"abc", b"de", b"fgh"]))

# Act
adjust_leftover_buffer(buffers, 5)

# Assert
assert list(buffers) == list(map(memoryview, [b"fgh"]))
assert list(buffers) == [b"fgh"]


def test____adjust_leftover_buffer____partial_buffer_remove() -> None:
# Arrange
buffers: deque[memoryview] = deque(map(memoryview, [b"abc", b"de", b"fgh"]))
buffers: deque[memoryview] = deque(map(lambda v: memoryview(v), [b"abc", b"de", b"fgh"]))

# Act
adjust_leftover_buffer(buffers, 4)

# Assert
assert list(buffers) == list(map(memoryview, [b"e", b"fgh"]))
assert list(buffers) == [b"e", b"fgh"]


def test____adjust_leftover_buffer____handle_view_with_different_item_sizes() -> None:
Expand All @@ -576,13 +576,13 @@ def test____adjust_leftover_buffer____handle_view_with_different_item_sizes() ->

item = array.array("i", [56, 23, 45, -4])

buffers: deque[memoryview] = deque(map(memoryview, [item]))
buffers: deque[memoryview] = deque([memoryview(item)])

# Act
adjust_leftover_buffer(buffers, item.itemsize * 2)

# Assert
assert list(buffers) == list(map(memoryview, [bytes(item[2:])]))
assert list(buffers) == [bytes(item[2:])]


def test____is_socket_connected____getpeername_returns(mock_tcp_socket: MagicMock) -> None:
Expand Down

0 comments on commit 92b2be9

Please sign in to comment.