Skip to content

Commit

Permalink
Merge pull request #69 from jodal/tooling
Browse files Browse the repository at this point in the history
Update tooling
  • Loading branch information
jodal authored Nov 10, 2024
2 parents d2a1853 + 812ac61 commit 9c66c58
Show file tree
Hide file tree
Showing 36 changed files with 118 additions and 151 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +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: "3.13"
coverage: true
- name: "Lint: pyright"
python: "3.12"
tox: pyright
python: "3.13"
tox: "pyright"
- name: "Lint: ruff lint"
python: "3.12"
tox: ruff-lint
python: "3.13"
tox: "ruff-lint"
- name: "Lint: ruff format"
python: "3.12"
tox: ruff-format
python: "3.13"
tox: "ruff-format"

name: ${{ matrix.name }}
runs-on: ubuntu-22.04
Expand Down
93 changes: 50 additions & 43 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
Expand All @@ -29,10 +30,10 @@ 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"]
dev = ["mopidy-mpd[lint,test,typing]", "tox >= 4.21"]

[project.urls]
Source = "https://github.com/mopidy/mopidy-mpd"
Expand All @@ -56,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]
Expand All @@ -115,9 +92,39 @@ ignore = [
"PLR0913", # too-many-arguments
"PLR2004", # magic-value-comparison
"PT027", # pytest-unittest-raises-assertion
"S101", # assert
"SLF001", # private-member-access
"TRY002", # raise-vanilla-class
]


[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:.}"]]
2 changes: 1 addition & 1 deletion src/mopidy_mpd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from mopidy import config, ext

__version__ = version("Mopidy-MPD")
__version__ = version("mopidy-mpd")


class Extension(ext.Extension):
Expand Down
10 changes: 5 additions & 5 deletions src/mopidy_mpd/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions src/mopidy_mpd/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/mopidy_mpd/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class MpdAckError(MopidyException):

"""See fields on this class for available MPD error codes"""

ACK_ERROR_NOT_LIST = 1
Expand Down
10 changes: 4 additions & 6 deletions src/mopidy_mpd/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"""


Expand Down Expand Up @@ -221,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()
Expand Down Expand Up @@ -433,7 +432,6 @@ def __str__(self) -> str:


class LineProtocol(pykka.ThreadingActor):

"""
Base class for handling line based protocols.
Expand Down Expand Up @@ -526,7 +524,7 @@ def encode(self, line: str) -> bytes:
self.encoding,
)
self.stop()
return NoReturn
return Never

def decode(self, line: bytes) -> str:
"""
Expand All @@ -543,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:
Expand Down
2 changes: 1 addition & 1 deletion src/mopidy_mpd/protocol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def call(


class Handler:
def __init__( # noqa: PLR0913
def __init__(
self,
*,
name: str,
Expand Down
4 changes: 2 additions & 2 deletions src/mopidy_mpd/protocol/current_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions src/mopidy_mpd/protocol/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 2 additions & 4 deletions src/mopidy_mpd/protocol/stored_playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/mopidy_mpd/session.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion src/mopidy_mpd/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
*,
Expand Down
1 change: 0 additions & 1 deletion tests/dummy_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
tests of the core and backends.
"""


import pykka
from mopidy import audio

Expand Down
1 change: 0 additions & 1 deletion tests/dummy_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
used in tests of the frontends.
"""


import pykka
from mopidy import backend
from mopidy.models import Playlist, Ref, SearchResult
Expand Down
2 changes: 1 addition & 1 deletion tests/network/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Loading

0 comments on commit 9c66c58

Please sign in to comment.