diff --git a/dev-requirements.txt b/dev-requirements.txt index 2f724a5c99a..86674d51e80 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -15,7 +15,7 @@ pytest-cov coverage[toml] # code-linting -ruff ==0.5.5 +ruff ==0.5.7 # typing mypy ==1.10.1 diff --git a/pyproject.toml b/pyproject.toml index f71fbfe2ad7..21bd4345839 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -229,6 +229,7 @@ select = [ ] ignore = [ "A003", # builtin-attribute-shadowing + "A005", # builtin-module-shadowing "C408", # unnecessary-collection-call "ISC003", # explicit-string-concatenation "PLC1901", # compare-to-empty-string @@ -256,6 +257,12 @@ known-first-party = ["streamlink", "streamlink_cli"] lines-after-imports = 2 combine-as-imports = true +[tool.ruff.lint.flake8-builtins] +builtins-ignorelist = [ + "BaseExceptionGroup", # compat import from exceptiongroup pkg + "ExceptionGroup", # compat import from exceptiongroup pkg +] + [tool.ruff.lint.flake8-tidy-imports] ban-relative-imports = "all" diff --git a/setup.py b/setup.py index b7c78b544c0..6a3fe610c47 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import sys from os import path -from sys import argv, exit, version_info from textwrap import dedent @@ -9,12 +8,12 @@ def format_msg(text, *args, **kwargs): return dedent(text).strip(" \n").format(*args, **kwargs) -CURRENT_PYTHON = version_info[:2] +CURRENT_PYTHON = sys.version_info[:2] REQUIRED_PYTHON = (3, 8) # This check and everything above must remain compatible with older Python versions if CURRENT_PYTHON < REQUIRED_PYTHON: - exit(format_msg(""" + sys.exit(format_msg(""" ======================================================== Unsupported Python version ======================================================== @@ -27,15 +26,15 @@ def format_msg(text, *args, **kwargs): """, *(REQUIRED_PYTHON + CURRENT_PYTHON))) # Explicitly disable running tests via setuptools -if "test" in argv: - exit(format_msg(""" +if "test" in sys.argv: + sys.exit(format_msg(""" Running `python setup.py test` has been deprecated since setuptools 41.5.0. Streamlink requires pytest for collecting and running tests, via one of these commands: `pytest` or `python -m pytest` (see the pytest docs for more infos about this) """)) -def is_wheel_for_windows(): +def is_wheel_for_windows(argv): if "bdist_wheel" in argv: names = ["win32", "win-amd64", "cygwin"] length = len(argv) @@ -51,7 +50,7 @@ def is_wheel_for_windows(): "console_scripts": ["streamlink=streamlink_cli.main:main"], } -if is_wheel_for_windows(): +if is_wheel_for_windows(sys.argv): entry_points["gui_scripts"] = ["streamlinkw=streamlink_cli.main:main"] diff --git a/src/streamlink/plugin/api/validate/__init__.py b/src/streamlink/plugin/api/validate/__init__.py index ca7a264f1a4..864367a90b3 100644 --- a/src/streamlink/plugin/api/validate/__init__.py +++ b/src/streamlink/plugin/api/validate/__init__.py @@ -1,4 +1,4 @@ -# ruff: noqa: A001, I001 +# ruff: noqa: A001, A004, I001 # order the module members logically (autodoc_member_order == "bysource") from streamlink.plugin.api.validate._validate import ( diff --git a/src/streamlink/stream/hls/hls.py b/src/streamlink/stream/hls/hls.py index 6c7c1c78f61..cb5915694c0 100644 --- a/src/streamlink/stream/hls/hls.py +++ b/src/streamlink/stream/hls/hls.py @@ -7,7 +7,7 @@ from urllib.parse import urlparse from requests import Response -from requests.exceptions import ChunkedEncodingError, ConnectionError, ContentDecodingError, InvalidSchema +from requests.exceptions import ChunkedEncodingError, ConnectionError, ContentDecodingError, InvalidSchema # noqa: A004 from streamlink.buffers import RingBuffer from streamlink.exceptions import StreamError diff --git a/src/streamlink_cli/__init__.py b/src/streamlink_cli/__init__.py index 499a6a1f45f..cee809f546a 100644 --- a/src/streamlink_cli/__init__.py +++ b/src/streamlink_cli/__init__.py @@ -1,5 +1,5 @@ from signal import SIGINT, SIGTERM, signal -from sys import exit +from sys import exit # noqa: A004 def _exit(*_): diff --git a/tests/stream/dash/test_manifest.py b/tests/stream/dash/test_manifest.py index 56839ac95be..72f236a85a8 100644 --- a/tests/stream/dash/test_manifest.py +++ b/tests/stream/dash/test_manifest.py @@ -291,7 +291,7 @@ def test_dynamic_segment_list_continued(self, caplog: pytest.LogCaptureFixture): ("http://test/14.m4s", 14), ("http://test/15.m4s", 15), ], "Queues the init segment and the correct number of segments from the live-edge" - assert mpd.timelines[("0", "0", "0")] == 16, "Remembers the next segment number" + assert mpd.timelines["0", "0", "0"] == 16, "Remembers the next segment number" assert [(record.name, record.levelname, record.message) for record in caplog.records] == [] # regular continuation @@ -304,7 +304,7 @@ def test_dynamic_segment_list_continued(self, caplog: pytest.LogCaptureFixture): ("http://test/17.m4s", 17), ("http://test/18.m4s", 18), ], "All segments from the remembered segment number were queued" - assert mpd.timelines[("0", "0", "0")] == 19, "Remembers the next segment number" + assert mpd.timelines["0", "0", "0"] == 19, "Remembers the next segment number" assert [(record.name, record.levelname, record.message) for record in caplog.records] == [] # regular continuation with a different offset @@ -320,7 +320,7 @@ def test_dynamic_segment_list_continued(self, caplog: pytest.LogCaptureFixture): ("http://test/23.m4s", 23), ("http://test/24.m4s", 24), ], "All segments from the remembered segment number were queued" - assert mpd.timelines[("0", "0", "0")] == 25, "Remembers the next segment number" + assert mpd.timelines["0", "0", "0"] == 25, "Remembers the next segment number" assert [(record.name, record.levelname, record.message) for record in caplog.records] == [] # skipped multiple segments @@ -340,7 +340,7 @@ def test_dynamic_segment_list_continued(self, caplog: pytest.LogCaptureFixture): ("http://test/38.m4s", 38), ("http://test/39.m4s", 39), ], "All segments from the remembered segment number were queued" - assert mpd.timelines[("0", "0", "0")] == 40, "Remembers the next segment number" + assert mpd.timelines["0", "0", "0"] == 40, "Remembers the next segment number" assert [(record.name, record.levelname, record.message) for record in caplog.records] == [ ( "streamlink.stream.dash.manifest", @@ -368,7 +368,7 @@ def test_dynamic_segment_list_continued(self, caplog: pytest.LogCaptureFixture): ("http://test/49.m4s", 49), ("http://test/50.m4s", 50), ], "All segments from the remembered segment number were queued" - assert mpd.timelines[("0", "0", "0")] == 51, "Remembers the next segment number" + assert mpd.timelines["0", "0", "0"] == 51, "Remembers the next segment number" assert [(record.name, record.levelname, record.message) for record in caplog.records] == [ ( "streamlink.stream.dash.manifest",