Skip to content

Commit

Permalink
build: only require exceptiongroup on py<3.11
Browse files Browse the repository at this point in the history
- Add `python_version<"3.11"` environment marker to `exceptiongroup`:
  It's a no-op package on Python 3.11 and above, so we don't have to
  require it on all Python versions.
- Update compatibility imports
- Update dependency docs
  • Loading branch information
bastimeyer committed May 10, 2024
1 parent c7a0558 commit 63c6d03
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion docs/install.rst
Expand Up @@ -448,7 +448,8 @@ Streamlink defines a `build system <pyproject.toml_>`__ according to `PEP-517`_
- Used for loading the CA bundle extracted from the Mozilla Included CA Certificate List
* - runtime
- `exceptiongroup`_
- Used for ``ExceptionGroup`` handling, to allow writing compatible code on all supported Python versions
- Only required when ``python_version<"3.11"`` |br|
Used for ``ExceptionGroup`` handling
* - runtime
- `isodate`_
- Used for parsing ISO8601 strings
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -56,7 +56,7 @@ dynamic = [
requires-python = ">=3.8"
dependencies = [
"certifi",
"exceptiongroup",
"exceptiongroup ; python_version<'3.11'",
"isodate",
"lxml >=4.6.4,<6",
"pycountry",
Expand Down
10 changes: 8 additions & 2 deletions src/streamlink/compat.py
Expand Up @@ -5,8 +5,12 @@
import warnings
from typing import Any, Callable, Dict, Optional, Tuple

# import exceptiongroup, so it can monkeypatch ExceptionGroup logic on <=py311
import exceptiongroup # noqa: F401

try:
from builtins import BaseExceptionGroup, ExceptionGroup # type: ignore[attr-defined]
except ImportError: # pragma: no cover
from exceptiongroup import BaseExceptionGroup, ExceptionGroup # type: ignore[import]


from streamlink.exceptions import StreamlinkDeprecationWarning

Expand Down Expand Up @@ -72,6 +76,8 @@ def __getattr__(name: str) -> Any:


__all__ = [
"BaseExceptionGroup",
"ExceptionGroup",
"deprecated",
"detect_encoding",
"is_darwin",
Expand Down
2 changes: 1 addition & 1 deletion src/streamlink/plugins/twitch.py
Expand Up @@ -541,7 +541,7 @@ def acquire(
headers: Mapping[str, str],
device_id: str,
) -> Optional[Tuple[str, int]]:
from exceptiongroup import BaseExceptionGroup # noqa: PLC0415, I001
from streamlink.compat import BaseExceptionGroup # noqa: PLC0415
from streamlink.webbrowser.cdp import CDPClient, CDPClientSession, devtools # noqa: PLC0415

url = f"https://www.twitch.tv/{channel}"
Expand Down
2 changes: 1 addition & 1 deletion src/streamlink/webbrowser/webbrowser.py
Expand Up @@ -8,8 +8,8 @@
from typing import AsyncContextManager, AsyncGenerator, Generator, List, Optional, Union

import trio
from exceptiongroup import BaseExceptionGroup

from streamlink.compat import BaseExceptionGroup
from streamlink.utils.path import resolve_executable
from streamlink.webbrowser.exceptions import WebbrowserError

Expand Down
2 changes: 1 addition & 1 deletion tests/webbrowser/cdp/test_client.py
Expand Up @@ -4,9 +4,9 @@

import pytest
import trio
from exceptiongroup import ExceptionGroup
from trio.testing import wait_all_tasks_blocked

from streamlink.compat import ExceptionGroup
from streamlink.session import Streamlink
from streamlink.webbrowser.cdp.client import CDPClient, CDPClientSession, RequestPausedHandler
from streamlink.webbrowser.cdp.connection import CDPConnection, CDPSession
Expand Down
2 changes: 1 addition & 1 deletion tests/webbrowser/cdp/test_connection.py
Expand Up @@ -7,10 +7,10 @@

import pytest
import trio
from exceptiongroup import ExceptionGroup
from trio.testing import MockClock, wait_all_tasks_blocked
from trio_websocket import CloseReason, ConnectionClosed, ConnectionTimeout # type: ignore[import]

from streamlink.compat import ExceptionGroup
from streamlink.webbrowser.cdp.connection import CDPConnection, CDPEventListener, CDPSession
from streamlink.webbrowser.cdp.devtools.target import SessionID, TargetID
from streamlink.webbrowser.cdp.devtools.util import T_JSON_DICT
Expand Down
3 changes: 1 addition & 2 deletions tests/webbrowser/test_webbrowser.py
Expand Up @@ -7,9 +7,8 @@

import pytest
import trio
from exceptiongroup import BaseExceptionGroup

from streamlink.compat import is_win32
from streamlink.compat import BaseExceptionGroup, is_win32
from streamlink.webbrowser.exceptions import WebbrowserError
from streamlink.webbrowser.webbrowser import Webbrowser

Expand Down

0 comments on commit 63c6d03

Please sign in to comment.