From 83b562b4250618b99e3dc960a8f6398269007b45 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 11 Nov 2024 00:14:03 +0100 Subject: [PATCH 1/8] Normalize package name --- pyproject.toml | 2 +- src/mopidy_mpd/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fb5a72a..fc5504a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] -name = "Mopidy-MPD" +name = "mopidy-mpd" description = "Mopidy extension for controlling Mopidy from MPD clients" readme = "README.rst" requires-python = ">= 3.11" diff --git a/src/mopidy_mpd/__init__.py b/src/mopidy_mpd/__init__.py index 3cb7ad4..af98c35 100644 --- a/src/mopidy_mpd/__init__.py +++ b/src/mopidy_mpd/__init__.py @@ -3,7 +3,7 @@ from mopidy import config, ext -__version__ = version("Mopidy-MPD") +__version__ = version("mopidy-mpd") class Extension(ext.Extension): From a23ac6c3edba59a474a4e932af58f120177cbc8f Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 11 Nov 2024 00:15:25 +0100 Subject: [PATCH 2/8] Test on Python 3.13 --- .github/workflows/ci.yml | 9 ++++++--- pyproject.toml | 1 + tox.ini | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 444f36e..031c66f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,15 +18,18 @@ jobs: - name: "Test: Python 3.12" python: "3.12" tox: py312 + - name: "Test: Python 3.13" + python: "3.13" + tox: py313 coverage: true - name: "Lint: pyright" - python: "3.12" + python: "3.13" tox: pyright - name: "Lint: ruff lint" - python: "3.12" + python: "3.13" tox: ruff-lint - name: "Lint: ruff format" - python: "3.12" + python: "3.13" tox: ruff-format name: ${{ matrix.name }} diff --git a/pyproject.toml b/pyproject.toml index fc5504a..37f03b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ classifiers = [ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Topic :: Multimedia :: Sound/Audio :: Players", ] dynamic = ["version"] diff --git a/tox.ini b/tox.ini index a9bd6f1..d8b4e6d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py311, py312, typing, ruff-lint, ruff-format +envlist = py311, py312, py313, typing, ruff-lint, ruff-format [testenv] sitepackages = true From ccf0b1f5095327ddd32fc87fc02895a4a84ad776 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 11 Nov 2024 00:18:09 +0100 Subject: [PATCH 3/8] Migrate tox.ini to pyproject.toml --- .github/workflows/ci.yml | 12 ++++++------ pyproject.toml | 31 ++++++++++++++++++++++++++++++- tox.ini | 23 ----------------------- 3 files changed, 36 insertions(+), 30 deletions(-) delete mode 100644 tox.ini diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 031c66f..53e9e9b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,23 +14,23 @@ jobs: include: - name: "Test: Python 3.11" python: "3.11" - tox: py311 + tox: "3.11" - name: "Test: Python 3.12" python: "3.12" - tox: py312 + tox: "3.12" - name: "Test: Python 3.13" python: "3.13" - tox: py313 + tox: "3.13" coverage: true - name: "Lint: pyright" python: "3.13" - tox: pyright + tox: "pyright" - name: "Lint: ruff lint" python: "3.13" - tox: ruff-lint + tox: "ruff-lint" - name: "Lint: ruff format" python: "3.13" - tox: ruff-format + tox: "ruff-format" name: ${{ matrix.name }} runs-on: ubuntu-22.04 diff --git a/pyproject.toml b/pyproject.toml index 37f03b0..e7b70f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ dependencies = [ lint = ["ruff"] test = ["pytest", "pytest-cov"] typing = ["pygobject-stubs", "pyright"] -dev = ["mopidy-mpd[lint,test,typing]", "tox"] +dev = ["mopidy-mpd[lint,test,typing]", "tox >= 4.21"] [project.urls] Source = "https://github.com/mopidy/mopidy-mpd" @@ -122,3 +122,32 @@ ignore = [ [tool.setuptools_scm] + + +[tool.tox] +requires = ["tox >= 4.21"] +env_list = ["3.11", "3.12", "3.13", "pyright", "ruff-lint", "ruff-format"] + +[tool.tox.env_run_base] +deps = [".[test]"] +commands = [ + [ + "pytest", + "--basetemp={envtmpdir}", + "--cov=mopidy_mpd", + "--cov-report=term-missing", + "{posargs}", + ], +] + +[tool.tox.env.pyright] +deps = [".[typing]"] +commands = [["pyright", "{posargs:src}"]] + +[tool.tox.env.ruff-lint] +deps = [".[lint]"] +commands = [["ruff", "check", "{posargs:.}"]] + +[tool.tox.env.ruff-format] +deps = [".[lint]"] +commands = [["ruff", "format", "--check", "{posargs:.}"]] diff --git a/tox.ini b/tox.ini deleted file mode 100644 index d8b4e6d..0000000 --- a/tox.ini +++ /dev/null @@ -1,23 +0,0 @@ -[tox] -envlist = py311, py312, py313, typing, ruff-lint, ruff-format - -[testenv] -sitepackages = true -deps = .[test] -commands = - python -m pytest \ - --basetemp={envtmpdir} \ - --cov=mopidy_mpd --cov-report=term-missing \ - {posargs} - -[testenv:pyright] -deps = .[typing] -commands = python -m pyright src - -[testenv:ruff-lint] -deps = .[lint] -commands = python -m ruff check . - -[testenv:ruff-format] -deps = .[lint] -commands = python -m ruff format --check . From 2b51f42dc54baf941ceae756e166810c561fc0eb Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 11 Nov 2024 00:21:45 +0100 Subject: [PATCH 4/8] Set min versions for dev deps --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e7b70f8..059cf6c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,8 +30,8 @@ dependencies = [ ] [project.optional-dependencies] -lint = ["ruff"] -test = ["pytest", "pytest-cov"] +lint = ["ruff >= 0.5"] +test = ["pytest >= 7.2", "pytest-cov >= 4.0"] typing = ["pygobject-stubs", "pyright"] dev = ["mopidy-mpd[lint,test,typing]", "tox >= 4.21"] From f14007764e84ccb4afcd2e90ff7a9700725e1f93 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 11 Nov 2024 00:22:07 +0100 Subject: [PATCH 5/8] Format with ruff --- src/mopidy_mpd/context.py | 8 ++++---- src/mopidy_mpd/exceptions.py | 1 - src/mopidy_mpd/network.py | 2 -- src/mopidy_mpd/protocol/stored_playlists.py | 6 ++---- tests/dummy_audio.py | 1 - tests/dummy_backend.py | 1 - tests/protocol/test_regression.py | 6 ------ 7 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/mopidy_mpd/context.py b/src/mopidy_mpd/context.py index 107bcbe..cb4f204 100644 --- a/src/mopidy_mpd/context.py +++ b/src/mopidy_mpd/context.py @@ -65,14 +65,14 @@ def __init__( # noqa: PLR0913 @overload def browse( self, path: str | None, *, recursive: bool, lookup: Literal[True] - ) -> Generator[tuple[str, pykka.Future[dict[Uri, list[Track]]] | None], Any, None]: - ... + ) -> Generator[ + tuple[str, pykka.Future[dict[Uri, list[Track]]] | None], Any, None + ]: ... @overload def browse( self, path: str | None, *, recursive: bool, lookup: Literal[False] - ) -> Generator[tuple[str, Ref | None], Any, None]: - ... + ) -> Generator[tuple[str, Ref | None], Any, None]: ... def browse( # noqa: C901, PLR0912 self, diff --git a/src/mopidy_mpd/exceptions.py b/src/mopidy_mpd/exceptions.py index 39675a5..7a95c03 100644 --- a/src/mopidy_mpd/exceptions.py +++ b/src/mopidy_mpd/exceptions.py @@ -5,7 +5,6 @@ class MpdAckError(MopidyException): - """See fields on this class for available MPD error codes""" ACK_ERROR_NOT_LIST = 1 diff --git a/src/mopidy_mpd/network.py b/src/mopidy_mpd/network.py index d69041c..f961b40 100644 --- a/src/mopidy_mpd/network.py +++ b/src/mopidy_mpd/network.py @@ -60,7 +60,6 @@ def get_socket_address(host: str, port: int) -> tuple[str, int | None]: class ShouldRetrySocketCallError(Exception): - """Indicate that attempted socket call should be retried""" @@ -433,7 +432,6 @@ def __str__(self) -> str: class LineProtocol(pykka.ThreadingActor): - """ Base class for handling line based protocols. diff --git a/src/mopidy_mpd/protocol/stored_playlists.py b/src/mopidy_mpd/protocol/stored_playlists.py index 8bf43c3..92c33a9 100644 --- a/src/mopidy_mpd/protocol/stored_playlists.py +++ b/src/mopidy_mpd/protocol/stored_playlists.py @@ -29,15 +29,13 @@ def _check_playlist_name(name: str) -> None: @overload def _get_playlist( context: MpdContext, name: str, *, must_exist: Literal[True] -) -> Playlist: - ... +) -> Playlist: ... @overload def _get_playlist( context: MpdContext, name: str, *, must_exist: Literal[False] -) -> Playlist | None: - ... +) -> Playlist | None: ... def _get_playlist( diff --git a/tests/dummy_audio.py b/tests/dummy_audio.py index d5be9d1..70f4c81 100644 --- a/tests/dummy_audio.py +++ b/tests/dummy_audio.py @@ -4,7 +4,6 @@ tests of the core and backends. """ - import pykka from mopidy import audio diff --git a/tests/dummy_backend.py b/tests/dummy_backend.py index d4c9b6d..356b52e 100644 --- a/tests/dummy_backend.py +++ b/tests/dummy_backend.py @@ -4,7 +4,6 @@ used in tests of the frontends. """ - import pykka from mopidy import backend from mopidy.models import Playlist, Ref, SearchResult diff --git a/tests/protocol/test_regression.py b/tests/protocol/test_regression.py index e9c6c53..2922ffe 100644 --- a/tests/protocol/test_regression.py +++ b/tests/protocol/test_regression.py @@ -12,7 +12,6 @@ def mock_shuffle(foo): class IssueGH17RegressionTest(protocol.BaseTestCase): - """ The issue: http://github.com/mopidy/mopidy/issues/17 @@ -54,7 +53,6 @@ def test(self): class IssueGH18RegressionTest(protocol.BaseTestCase): - """ The issue: http://github.com/mopidy/mopidy/issues/18 @@ -97,7 +95,6 @@ def test(self): class IssueGH22RegressionTest(protocol.BaseTestCase): - """ The issue: http://github.com/mopidy/mopidy/issues/22 @@ -136,7 +133,6 @@ def test(self): class IssueGH69RegressionTest(protocol.BaseTestCase): - """ The issue: https://github.com/mopidy/mopidy/issues/69 @@ -193,7 +189,6 @@ def test(self): class IssueGH137RegressionTest(protocol.BaseTestCase): - """ The issue: https://github.com/mopidy/mopidy/issues/137 @@ -244,7 +239,6 @@ def test(self, last_modified_mock): class IssueGH1348RegressionTest(protocol.BaseTestCase): - """ The issue: http://github.com/mopidy/mopidy/issues/1348 """ From 44db5f63349abffb8b2306e0282e834812696ccc Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 11 Nov 2024 00:22:48 +0100 Subject: [PATCH 6/8] Fix ruff lints --- src/mopidy_mpd/context.py | 2 +- src/mopidy_mpd/dispatcher.py | 5 +---- src/mopidy_mpd/network.py | 2 +- src/mopidy_mpd/protocol/__init__.py | 2 +- src/mopidy_mpd/protocol/current_playlist.py | 4 ++-- src/mopidy_mpd/protocol/status.py | 4 +--- src/mopidy_mpd/translator.py | 2 +- tests/network/test_connection.py | 2 +- tests/network/test_lineprotocol.py | 9 ++++----- tests/network/test_server.py | 4 ++-- tests/network/test_utils.py | 4 ++-- tests/path_utils.py | 2 +- tests/protocol/__init__.py | 4 ++-- tests/protocol/test_authentication.py | 2 +- tests/protocol/test_command_list.py | 14 +++++++------- tests/protocol/test_connection.py | 1 - tests/protocol/test_idle.py | 1 - tests/protocol/test_music_db.py | 2 +- tests/protocol/test_reflection.py | 2 +- tests/protocol/test_regression.py | 6 +++--- tests/protocol/test_stored_playlists.py | 2 +- tests/test_actor.py | 1 + tests/test_context.py | 10 +++++----- tests/test_dispatcher.py | 2 +- tests/test_exceptions.py | 1 + tests/test_status.py | 5 ++--- tests/test_translator.py | 2 +- 27 files changed, 45 insertions(+), 52 deletions(-) diff --git a/src/mopidy_mpd/context.py b/src/mopidy_mpd/context.py index cb4f204..317e32c 100644 --- a/src/mopidy_mpd/context.py +++ b/src/mopidy_mpd/context.py @@ -48,7 +48,7 @@ class MpdContext: #: Mapping of URIs to MPD names. uri_map: MpdUriMapper - def __init__( # noqa: PLR0913 + def __init__( self, config: types.Config, core: CoreProxy, diff --git a/src/mopidy_mpd/dispatcher.py b/src/mopidy_mpd/dispatcher.py index 795e5a3..698e8ac 100644 --- a/src/mopidy_mpd/dispatcher.py +++ b/src/mopidy_mpd/dispatcher.py @@ -97,10 +97,7 @@ def handle_idle(self, subsystem: str) -> None: if not subsystems: return - response: list[str] = [] - for subsystem in subsystems: - response.append(f"changed: {subsystem}") - response.append("OK") + response = [*[f"changed: {s}" for s in subsystems], "OK"] self.subsystem_events = set() self.subsystem_subscriptions = set() self.session.send_lines(response) diff --git a/src/mopidy_mpd/network.py b/src/mopidy_mpd/network.py index f961b40..2e60988 100644 --- a/src/mopidy_mpd/network.py +++ b/src/mopidy_mpd/network.py @@ -220,7 +220,7 @@ def number_of_connections(self) -> int: return len(pykka.ActorRegistry.get_by_class(self.protocol)) def reject_connection(self, sock: socket.socket, addr: SocketAddress) -> None: - # FIXME provide more context in logging? + # TODO: provide more context in logging? logger.warning("Rejected connection from %s", format_address(addr)) with contextlib.suppress(OSError): sock.close() diff --git a/src/mopidy_mpd/protocol/__init__.py b/src/mopidy_mpd/protocol/__init__.py index 05842f0..87ba052 100644 --- a/src/mopidy_mpd/protocol/__init__.py +++ b/src/mopidy_mpd/protocol/__init__.py @@ -204,7 +204,7 @@ def call( class Handler: - def __init__( # noqa: PLR0913 + def __init__( self, *, name: str, diff --git a/src/mopidy_mpd/protocol/current_playlist.py b/src/mopidy_mpd/protocol/current_playlist.py index 76c3558..dad7e6d 100644 --- a/src/mopidy_mpd/protocol/current_playlist.py +++ b/src/mopidy_mpd/protocol/current_playlist.py @@ -285,7 +285,7 @@ def plchanges(context: MpdContext, version: int) -> protocol.Result: - Calls ``plchanges "-1"`` two times per second to get the entire playlist. """ - # XXX Naive implementation that returns all tracks as changed + # TODO: Naive implementation that returns all tracks as changed tracklist_version = context.core.tracklist.get_version().get() if version < tracklist_version: @@ -328,7 +328,7 @@ def plchangesposid(context: MpdContext, version: int) -> protocol.Result: To detect songs that were deleted at the end of the playlist, use ``playlistlength`` returned by status command. """ - # XXX Naive implementation that returns all tracks as changed + # TODO: Naive implementation that returns all tracks as changed if int(version) != context.core.tracklist.get_version().get(): result = [] for position, (tlid, _) in enumerate( diff --git a/src/mopidy_mpd/protocol/status.py b/src/mopidy_mpd/protocol/status.py index 7d059b6..ed95c63 100644 --- a/src/mopidy_mpd/protocol/status.py +++ b/src/mopidy_mpd/protocol/status.py @@ -110,12 +110,10 @@ def idle(context: MpdContext, *args: str) -> protocol.Result: context.session.prevent_timeout = True return None - response = [] + response: protocol.ResultList = [("changed", subsystem) for subsystem in active] context.dispatcher.subsystem_events = set() context.dispatcher.subsystem_subscriptions = set() - for subsystem in active: - response.append(f"changed: {subsystem}") return response diff --git a/src/mopidy_mpd/translator.py b/src/mopidy_mpd/translator.py index 4457d37..4b9b912 100644 --- a/src/mopidy_mpd/translator.py +++ b/src/mopidy_mpd/translator.py @@ -16,7 +16,7 @@ logger = logging.getLogger(__name__) -def track_to_mpd_format( # noqa: C901, PLR0912 +def track_to_mpd_format( # noqa: C901, PLR0912, PLR0915 obj: Track | TlTrack, tagtypes: set[str], *, diff --git a/tests/network/test_connection.py b/tests/network/test_connection.py index 426a7fd..9398472 100644 --- a/tests/network/test_connection.py +++ b/tests/network/test_connection.py @@ -6,8 +6,8 @@ import pykka from gi.repository import GLib -from mopidy_mpd import network, uri_mapper +from mopidy_mpd import network, uri_mapper from tests import any_int, any_unicode diff --git a/tests/network/test_lineprotocol.py b/tests/network/test_lineprotocol.py index ca41e5b..e7da259 100644 --- a/tests/network/test_lineprotocol.py +++ b/tests/network/test_lineprotocol.py @@ -3,7 +3,6 @@ from unittest.mock import Mock, sentinel from mopidy_mpd import network - from tests import any_unicode @@ -234,12 +233,12 @@ def test_decode_calls_decode_on_string(self): def test_decode_plain_ascii(self): result = network.LineProtocol.decode(self.mock, b"abc") assert result == "abc" - assert str == type(result) + assert isinstance(result, str) def test_decode_utf8(self): result = network.LineProtocol.decode(self.mock, "æøå".encode()) assert result == "æøå" - assert str == type(result) + assert isinstance(result, str) def test_decode_invalid_data(self): string = Mock() @@ -257,12 +256,12 @@ def test_encode_calls_encode_on_string(self): def test_encode_plain_ascii(self): result = network.LineProtocol.encode(self.mock, "abc") assert result == b"abc" - assert bytes == type(result) + assert isinstance(result, bytes) def test_encode_utf8(self): result = network.LineProtocol.encode(self.mock, "æøå") assert "æøå".encode() == result - assert bytes == type(result) + assert isinstance(result, bytes) def test_encode_invalid_data(self): string = Mock() diff --git a/tests/network/test_server.py b/tests/network/test_server.py index d838082..d37ee4c 100644 --- a/tests/network/test_server.py +++ b/tests/network/test_server.py @@ -6,8 +6,8 @@ from gi.repository import GLib from mopidy.core import CoreProxy -from mopidy_mpd import network, uri_mapper +from mopidy_mpd import network, uri_mapper from tests import any_int @@ -263,7 +263,7 @@ def test_accept_connection_recoverable_error(self): with self.assertRaises(network.ShouldRetrySocketCallError): network.Server.accept_connection(self.mock) - # FIXME decide if this should be allowed to propegate + # TODO: decide if this should be allowed to propegate def test_accept_connection_unrecoverable_error(self): sock = Mock(spec=socket.socket) self.mock.server_socket = sock diff --git a/tests/network/test_utils.py b/tests/network/test_utils.py index 6903c96..f0fe193 100644 --- a/tests/network/test_utils.py +++ b/tests/network/test_utils.py @@ -9,13 +9,13 @@ class FormatHostnameTest(unittest.TestCase): @patch("mopidy_mpd.network.has_ipv6", True) def test_format_hostname_prefixes_ipv4_addresses_when_ipv6_available(self): network.has_ipv6 = True - assert network.format_hostname("0.0.0.0") == "::ffff:0.0.0.0" + assert network.format_hostname("0.0.0.0") == "::ffff:0.0.0.0" # noqa: S104 assert network.format_hostname("1.0.0.1") == "::ffff:1.0.0.1" @patch("mopidy_mpd.network.has_ipv6", False) def test_format_hostname_does_nothing_when_only_ipv4_available(self): network.has_ipv6 = False - assert network.format_hostname("0.0.0.0") == "0.0.0.0" + assert network.format_hostname("0.0.0.0") == "0.0.0.0" # noqa: S104 class FormatAddressTest(unittest.TestCase): diff --git a/tests/path_utils.py b/tests/path_utils.py index 4113a25..beecf9b 100644 --- a/tests/path_utils.py +++ b/tests/path_utils.py @@ -1,7 +1,7 @@ import os -# FIXME replace with mock usage in tests. +# TODO: replace with mock usage in tests. class Mtime: def __init__(self): self.fake = None diff --git a/tests/protocol/__init__.py b/tests/protocol/__init__.py index d3c0d20..9c14de1 100644 --- a/tests/protocol/__init__.py +++ b/tests/protocol/__init__.py @@ -4,8 +4,8 @@ import pykka from mopidy import core -from mopidy_mpd import session, uri_mapper +from mopidy_mpd import session, uri_mapper from tests import dummy_audio, dummy_backend, dummy_mixer @@ -73,7 +73,7 @@ def send_request(self, request): return self.connection.response def assertNoResponse(self): # noqa: N802 - assert [] == self.connection.response + assert self.connection.response == [] def assertInResponse(self, value): # noqa: N802 assert ( diff --git a/tests/protocol/test_authentication.py b/tests/protocol/test_authentication.py index 4e879fc..dbea475 100644 --- a/tests/protocol/test_authentication.py +++ b/tests/protocol/test_authentication.py @@ -4,7 +4,7 @@ class AuthenticationActiveTest(protocol.BaseTestCase): def get_config(self): config = super().get_config() - config["mpd"]["password"] = "topsecret" + config["mpd"]["password"] = "topsecret" # noqa: S105 return config def test_authentication_with_valid_password_is_accepted(self): diff --git a/tests/protocol/test_command_list.py b/tests/protocol/test_command_list.py index e9abcbe..cde500b 100644 --- a/tests/protocol/test_command_list.py +++ b/tests/protocol/test_command_list.py @@ -4,7 +4,7 @@ class CommandListsTest(protocol.BaseTestCase): def test_command_list_begin(self): response = self.send_request("command_list_begin") - assert [] == response + assert response == [] def test_command_list_end(self): self.send_request("command_list_begin") @@ -19,7 +19,7 @@ def test_command_list_with_ping(self): self.send_request("command_list_begin") assert self.dispatcher.command_list_receiving assert not self.dispatcher.command_list_ok - assert [] == self.dispatcher.command_list + assert self.dispatcher.command_list == [] self.send_request("ping") assert "ping" in self.dispatcher.command_list @@ -28,7 +28,7 @@ def test_command_list_with_ping(self): self.assertInResponse("OK") assert not self.dispatcher.command_list_receiving assert not self.dispatcher.command_list_ok - assert [] == self.dispatcher.command_list + assert self.dispatcher.command_list == [] def test_command_list_with_error_returns_ack_with_correct_index(self): self.send_request("command_list_begin") @@ -39,13 +39,13 @@ def test_command_list_with_error_returns_ack_with_correct_index(self): def test_command_list_ok_begin(self): response = self.send_request("command_list_ok_begin") - assert [] == response + assert response == [] def test_command_list_ok_with_ping(self): self.send_request("command_list_ok_begin") assert self.dispatcher.command_list_receiving assert self.dispatcher.command_list_ok - assert [] == self.dispatcher.command_list + assert self.dispatcher.command_list == [] self.send_request("ping") assert "ping" in self.dispatcher.command_list @@ -55,8 +55,8 @@ def test_command_list_ok_with_ping(self): self.assertInResponse("OK") assert not self.dispatcher.command_list_receiving assert not self.dispatcher.command_list_ok - assert [] == self.dispatcher.command_list + assert self.dispatcher.command_list == [] - # FIXME this should also include the special handling of idle within a + # TODO: this should also include the special handling of idle within a # command list. That is that once a idle/noidle command is found inside a # commad list, the rest of the list seems to be ignored. diff --git a/tests/protocol/test_connection.py b/tests/protocol/test_connection.py index df742e7..a418ff9 100644 --- a/tests/protocol/test_connection.py +++ b/tests/protocol/test_connection.py @@ -1,7 +1,6 @@ from unittest.mock import patch from mopidy_mpd.protocol import tagtype_list - from tests import protocol diff --git a/tests/protocol/test_idle.py b/tests/protocol/test_idle.py index da607f6..c1860d2 100644 --- a/tests/protocol/test_idle.py +++ b/tests/protocol/test_idle.py @@ -1,7 +1,6 @@ from unittest.mock import patch from mopidy_mpd.protocol.status import SUBSYSTEMS - from tests import protocol diff --git a/tests/protocol/test_music_db.py b/tests/protocol/test_music_db.py index be45e0d..031ff54 100644 --- a/tests/protocol/test_music_db.py +++ b/tests/protocol/test_music_db.py @@ -2,8 +2,8 @@ from unittest import mock from mopidy.models import Album, Artist, Playlist, Ref, SearchResult, Track -from mopidy_mpd.protocol import music_db, stored_playlists +from mopidy_mpd.protocol import music_db, stored_playlists from tests import protocol # TODO: split into more modules for faster parallel tests? diff --git a/tests/protocol/test_reflection.py b/tests/protocol/test_reflection.py index a60268e..512fecb 100644 --- a/tests/protocol/test_reflection.py +++ b/tests/protocol/test_reflection.py @@ -46,7 +46,7 @@ def test_urlhandlers(self): class ReflectionWhenNotAuthedTest(protocol.BaseTestCase): def get_config(self): config = super().get_config() - config["mpd"]["password"] = "topsecret" + config["mpd"]["password"] = "topsecret" # noqa: S105 return config def test_commands_show_less_if_auth_required_and_not_authed(self): diff --git a/tests/protocol/test_regression.py b/tests/protocol/test_regression.py index 2922ffe..172a434 100644 --- a/tests/protocol/test_regression.py +++ b/tests/protocol/test_regression.py @@ -2,8 +2,8 @@ from unittest import mock from mopidy.models import Playlist, Ref, Track -from mopidy_mpd.protocol import stored_playlists +from mopidy_mpd.protocol import stored_playlists from tests import protocol @@ -252,7 +252,7 @@ def test(self): # Create an other playlist which isn't in the map self.send_request('playlistadd "testing2" "dummy:a"') - assert ["OK"] == self.send_request('rm "testing2"') + assert self.send_request('rm "testing2"') == ["OK"] playlists = self.backend.playlists.as_list().get() - assert ["testing1"] == [ref.name for ref in playlists] + assert [ref.name for ref in playlists] == ["testing1"] diff --git a/tests/protocol/test_stored_playlists.py b/tests/protocol/test_stored_playlists.py index 8eb96e6..75d04eb 100644 --- a/tests/protocol/test_stored_playlists.py +++ b/tests/protocol/test_stored_playlists.py @@ -1,8 +1,8 @@ from unittest import mock from mopidy.models import Playlist, Track -from mopidy_mpd.protocol import stored_playlists +from mopidy_mpd.protocol import stored_playlists from tests import protocol diff --git a/tests/test_actor.py b/tests/test_actor.py index cb8b563..c76dde8 100644 --- a/tests/test_actor.py +++ b/tests/test_actor.py @@ -1,6 +1,7 @@ from unittest import mock import pytest + from mopidy_mpd import actor # NOTE: Should be kept in sync with all events from mopidy.core.listener diff --git a/tests/test_context.py b/tests/test_context.py index 6d4c9ec..235704b 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -5,23 +5,23 @@ from mopidy.backend import BackendProxy from mopidy.core import Core, CoreProxy from mopidy.models import Ref + from mopidy_mpd import uri_mapper from mopidy_mpd.context import MpdContext - from tests import dummy_backend -@pytest.fixture() +@pytest.fixture def a_track() -> Ref: return Ref.track(uri="dummy:/a", name="a") -@pytest.fixture() +@pytest.fixture def b_track() -> Ref: return Ref.track(uri="dummy:/foo/b", name="b") -@pytest.fixture() +@pytest.fixture def backend_to_browse(a_track: Ref, b_track: Ref) -> BackendProxy: backend = cast(BackendProxy, dummy_backend.create_proxy()) backend.library.dummy_browse_result = { @@ -36,7 +36,7 @@ def backend_to_browse(a_track: Ref, b_track: Ref) -> BackendProxy: return backend -@pytest.fixture() +@pytest.fixture def mpd_context(backend_to_browse: BackendProxy) -> MpdContext: core = cast( CoreProxy, diff --git a/tests/test_dispatcher.py b/tests/test_dispatcher.py index 4b7d591..c4cc7dd 100644 --- a/tests/test_dispatcher.py +++ b/tests/test_dispatcher.py @@ -3,10 +3,10 @@ import pykka from mopidy.core import Core, CoreProxy + from mopidy_mpd import uri_mapper from mopidy_mpd.dispatcher import MpdDispatcher from mopidy_mpd.exceptions import MpdAckError - from tests import dummy_backend diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 97c49c8..a7b3dae 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -1,6 +1,7 @@ import unittest import pytest + from mopidy_mpd.exceptions import ( MpdAckError, MpdNoCommandError, diff --git a/tests/test_status.py b/tests/test_status.py index 9c132aa..eeb3c4a 100644 --- a/tests/test_status.py +++ b/tests/test_status.py @@ -5,17 +5,16 @@ from mopidy import core from mopidy.core import PlaybackState from mopidy.models import Track + from mopidy_mpd import dispatcher, uri_mapper from mopidy_mpd.protocol import status - from tests import dummy_audio, dummy_backend, dummy_mixer PAUSED = PlaybackState.PAUSED PLAYING = PlaybackState.PLAYING STOPPED = PlaybackState.STOPPED -# FIXME migrate to using protocol.BaseTestCase instead of status.stats -# directly? +# TODO: migrate to using protocol.BaseTestCase instead of status.stats directly? class StatusHandlerTest(unittest.TestCase): diff --git a/tests/test_translator.py b/tests/test_translator.py index 6828c38..8797df5 100644 --- a/tests/test_translator.py +++ b/tests/test_translator.py @@ -1,9 +1,9 @@ import unittest from mopidy.models import Album, Artist, Playlist, TlTrack, Track + from mopidy_mpd import translator from mopidy_mpd.protocol import tagtype_list - from tests import path_utils From 609938a9997218b3f73173a32297eb2f002080d9 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 11 Nov 2024 00:33:57 +0100 Subject: [PATCH 7/8] Enable all ruff rules --- pyproject.toml | 55 +++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 059cf6c..af22c59 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,51 +57,27 @@ reportPrivateImportUsage = false target-version = "py311" [tool.ruff.lint] -select = [ - "A", # flake8-builtins - "ANN", # flake8-annotations - "ARG", # flake8-unused-arguments - "B", # flake8-bugbear - "C4", # flake8-comprehensions - "C90", # mccabe - "D", # pydocstyle - "DTZ", # flake8-datetimez - "E", # pycodestyle - "ERA", # eradicate - "F", # pyflakes - "FBT", # flake8-boolean-trap - "I", # isort - "INP", # flake8-no-pep420 - "ISC", # flake8-implicit-str-concat - "N", # pep8-naming - "PGH", # pygrep-hooks - "PIE", # flake8-pie - "PLC", # pylint convention - "PLE", # pylint error - "PLR", # pylint refactor - "PLW", # pylint warning - "PT", # flake8-pytest-style - "PTH", # flake8-use-pathlib - "Q", # flake8-quotes - "RET", # flake8-return - "RSE", # flake8-raise - "RUF", # ruff - "SIM", # flake8-simplify - "SLF", # flake8-self - "T20", # flake8-print - "TCH", # flake8-type-checking - "TID", # flake8-tidy-imports - "TRY", # tryceratops - "UP", # pyupgrade - "W", # pycodestyle -] +select = ["ALL"] ignore = [ "ANN101", # missing-type-self "ANN102", # missing-type-cls "ANN401", # any-type "D", # pydocstyle - "ISC001", # single-line-implicit-string-concatenation + "EM101", # raw-string-in-exception # TODO + "EM102", # f-string-in-exception # TODO + "FIX001", # line-contains-fixme + "FIX002", # line-contains-todo + "G004", # logging-f-string + "S101", # assert # TODO + "TD002", # missing-todo-author + "TD003", # missing-todo-link + "TD004", # missing-todo-colon # TODO + "TD005", # missing-todo-description # TODO "TRY003", # raise-vanilla-args + # + # These rules interfere with `ruff format` + "COM812", # missing-trailing-comma + "ISC001", # single-line-implicit-string-concatenation ] [tool.ruff.lint.per-file-ignores] @@ -116,6 +92,7 @@ ignore = [ "PLR0913", # too-many-arguments "PLR2004", # magic-value-comparison "PT027", # pytest-unittest-raises-assertion + "S101", # assert "SLF001", # private-member-access "TRY002", # raise-vanilla-class ] From 812ac613b02ce8ef95d4cd498016b77d427228c7 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 11 Nov 2024 00:49:27 +0100 Subject: [PATCH 8/8] Replace NoReturn with Never type --- src/mopidy_mpd/network.py | 6 +++--- src/mopidy_mpd/session.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mopidy_mpd/network.py b/src/mopidy_mpd/network.py index 2e60988..ecf0ff0 100644 --- a/src/mopidy_mpd/network.py +++ b/src/mopidy_mpd/network.py @@ -8,7 +8,7 @@ import socket import sys import threading -from typing import TYPE_CHECKING, Any, NoReturn +from typing import TYPE_CHECKING, Any, Never import pykka from gi.repository import GLib # pyright: ignore[reportMissingModuleSource] @@ -524,7 +524,7 @@ def encode(self, line: str) -> bytes: self.encoding, ) self.stop() - return NoReturn + return Never def decode(self, line: bytes) -> str: """ @@ -541,7 +541,7 @@ def decode(self, line: bytes) -> str: self.encoding, ) self.stop() - return NoReturn + return Never def join_lines(self, lines: list[str]) -> str: if not lines: diff --git a/src/mopidy_mpd/session.py b/src/mopidy_mpd/session.py index 05dc88c..63bc3ef 100644 --- a/src/mopidy_mpd/session.py +++ b/src/mopidy_mpd/session.py @@ -1,7 +1,7 @@ from __future__ import annotations import logging -from typing import TYPE_CHECKING, NoReturn, TypedDict +from typing import TYPE_CHECKING, Never, TypedDict from mopidy_mpd import dispatcher, formatting, network, protocol, types from mopidy_mpd.protocol import tagtype_list @@ -86,7 +86,7 @@ def decode(self, line: bytes) -> str: "supplied by client was not valid." ) self.stop() - return NoReturn + return Never def close(self) -> None: self.stop()