Skip to content

Commit

Permalink
Fix a couple of lints
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Sep 22, 2024
1 parent 5fa89dd commit f9d7b02
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 33 deletions.
8 changes: 4 additions & 4 deletions beetsplug/bandcamp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import logging
import re
from contextlib import contextmanager
from functools import lru_cache, partial
from functools import partial
from itertools import chain
from operator import itemgetter
from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, List, Literal, Sequence
from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, List, Literal

from beets import IncludeLazyConfig, config, library, plugins

Expand Down Expand Up @@ -64,10 +64,10 @@ class BandcampRequestsHandler:
_log: logging.Logger
config: IncludeLazyConfig

def _exc(self, msg_template: str, *args: Sequence[str]) -> None:
def _exc(self, msg_template: str, *args: object) -> None:
self._log.log(logging.WARNING, msg_template, *args, exc_info=True)

def _info(self, msg_template: str, *args: Sequence[str]) -> None:
def _info(self, msg_template: str, *args: object) -> None:
self._log.log(logging.DEBUG, msg_template, *args, exc_info=False)

def _get(self, url: str) -> str:
Expand Down
4 changes: 2 additions & 2 deletions beetsplug/bandcamp/album_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AlbumName:
_series = r"(?i:\b(part|volume|pt|vol)\b\.?)"
SERIES = re.compile(rf"{_series}[ ]?[A-Z\d.-]+\b")
SERIES_FMT = re.compile(rf"^(.+){_series} *0*")
REMIX_IN_TITLE = re.compile(r"[\( :]+(with re|inc|\+).*mix(\)|(.*$))", re.I)
REMIX_IN_TITLE = re.compile(r"[\( :]+(with re|inc|\+).*?mix[^)]*(\)|$)", re.I)
CLEAN_EPLP = re.compile(r"(?:[([]|Double ){0,2}(\b[EL]P\b)\S?", re.I)
EPLP_ALBUM = re.compile(r"\b(?!VA|0\d|-)([^\s:]+\b|[&, ])+ [EL]P\b( [\w#][^ ]+$)?")
EPLP_ALBUM_LINE = re.compile(r"\b(?=[A-Z])(((?!Vinyl|VA|-)[^:\s]+ )+)[EL]P$", re.M)
Expand All @@ -35,7 +35,7 @@ class AlbumName:
CLEAN_CATALOGNUM = re.compile(
r"""
(^[A-Z]+\d+\ [|-]\ )
| [^[\w)]*?\[[A-Z]+\d+\]
| [^[\w)\]]*\[[A-Z]+\d+\]
""",
re.VERBOSE,
)
Expand Down
2 changes: 1 addition & 1 deletion beetsplug/bandcamp/catalognum.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Catalognum:
(?:[.-]\d+)? # .1 in RAWVA01.1RP, -1322 in SOP 063-1322
(?:
(?!MIX)
(?<=\d\d)-?[A-Z]+ # CD in IBM001CD (needs at least two preceding digits)
(?<=\d\d)-?[A-Z]+ # CD in IBM001CD (at least two preceding digits)
| RP # RP in RAWVA01.1RP
)?
)?
Expand Down
32 changes: 16 additions & 16 deletions beetsplug/bandcamp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ def medium_count(self) -> int:
),
"track_alt": re.compile(
r"""
(?:(?<=^)|(?<=-\ )) # beginning of the line or right after the title separator
(?:(?<=^)|(?<=-\ )) # beginning of the line or right after the title separator
( # capture the catalogue number, either
(?:[A-J]{1,3}[12]?\.?\d) # A1, B2, E4, A1.1 etc.
| (?:[AB]+(?=\W{2}\b)) # A, AA BB
[A-J]{1,3}[12]?\.?\d # A1, B2, E4, A1.1 etc.
| [AB]+(?=\W{2}\b) # A, AA BB
)
(?:[/.:)_\s-]+) # consume the non-word chars for removal
[/.:)_\s-]+ # consume the non-word chars for removal
""",
re.M | re.VERBOSE,
),
Expand Down Expand Up @@ -154,18 +154,18 @@ def split_artist_title(m: Match[str]) -> str:
# fmt: off
CLEAN_PATTERNS: List[Tuple[Pattern[str], Union[str, Callable[[Match[str]], str]]]] = [
(re.compile(rf"(([\[(])|(^| ))\*?({'|'.join(rm_strings)})(?(2)[])]|([- ]|$))", re.I), ""),
(re.compile(r" -(\S)"), r" - \1"), # hi -bye -> hi - bye
(re.compile(r"(\S)- "), r"\1 - "), # hi- bye -> hi - bye
(re.compile(r" +"), " "), # hi bye -> hi bye
(re.compile(r"(- )?\( *"), "("), # hi - ( bye) -> hi (bye)
(re.compile(r" \)+|(\)+$)"), ")"), # hi (bye )) -> hi (bye)
(re.compile(r"- Reworked"), "(Reworked)"), # bye - Reworked -> bye (Reworked)
(re.compile(rf"(?<= - )([^()]+?) - ({REMIX.pattern})$", re.I), r"\1 (\2)"), # - bye - Some Mix -> - bye (Some Mix)
(re.compile(rf"(\({REMIX.pattern})$", re.I), r"\1)"), # bye - (Some Mix -> bye - (Some Mix)
(re.compile(rf"- *({REMIX.pattern})$", re.I), r"(\1)"), # bye - Some Mix -> bye (Some Mix)
(re.compile(r'(^|- )[“"]([^”"]+)[”"]( \(|$)'), r"\1\2\3"), # "bye" -> bye; hi - "bye" -> hi - bye
(re.compile(r"\((the )?(remixes)\)", re.I), r"\2"), # Album (Remixes) -> Album Remixes
(re.compile(r"examine-.+CD\d+_([^_-]+)[_-](.*)"), split_artist_title), # See https://examine-archive.bandcamp.com/album/va-examine-archive-international-sampler-xmn01
(re.compile(r" -(\S)"), r" - \1"), # hi -bye -> hi - bye # noqa
(re.compile(r"(\S)- "), r"\1 - "), # hi- bye -> hi - bye # noqa
(re.compile(r" +"), " "), # hi bye -> hi bye # noqa
(re.compile(r"(- )?\( *"), "("), # hi - ( bye) -> hi (bye) # noqa
(re.compile(r" \)+|(\)+$)"), ")"), # hi (bye )) -> hi (bye) # noqa
(re.compile(r"- Reworked"), "(Reworked)"), # bye - Reworked -> bye (Reworked) # noqa
(re.compile(rf"(?<= - )([^()]+?) - ({REMIX.pattern})$", re.I), r"\1 (\2)"), # - bye - Some Mix -> - bye (Some Mix) # noqa
(re.compile(rf"(\({REMIX.pattern})$", re.I), r"\1)"), # bye - (Some Mix -> bye - (Some Mix) # noqa
(re.compile(rf"- *({REMIX.pattern})$", re.I), r"(\1)"), # bye - Some Mix -> bye (Some Mix) # noqa
(re.compile(r'(^|- )[“"]([^”"]+)[”"]( \(|$)'), r"\1\2\3"), # "bye" -> bye; hi - "bye" -> hi - bye # noqa
(re.compile(r"\((the )?(remixes)\)", re.I), r"\2"), # Album (Remixes) -> Album Remixes # noqa
(re.compile(r"examine-.+CD\d+_([^_-]+)[_-](.*)"), split_artist_title), # See https://examine-archive.bandcamp.com/album/va-examine-archive-international-sampler-xmn01 # noqa
]
# fmt: on

Expand Down
2 changes: 1 addition & 1 deletion beetsplug/bandcamp/http.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from functools import lru_cache
from html import unescape
from urllib.parse import urlsplit

from beets import __version__
import httpx
Expand All @@ -11,6 +10,7 @@

_client = httpx.Client(headers={"User-Agent": USER_AGENT})


@lru_cache(maxsize=None)
def http_get_text(url: str) -> str:
"""Return text contents of the url."""
Expand Down
1 change: 0 additions & 1 deletion beetsplug/bandcamp/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import re
from difflib import SequenceMatcher
from html import unescape
from operator import itemgetter
from typing import Any, Callable, Dict, List
from urllib.parse import quote_plus
Expand Down
2 changes: 0 additions & 2 deletions beetsplug/bandcamp/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ def info(self) -> JSONDict:
artists = self.artists
if self.ft_artist:
artists.append(self.ft_artist)
# if self.remix:
# artists.append(self.remix.remixer)

return {
"index": self.index,
Expand Down
1 change: 1 addition & 0 deletions tests/test_genre.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for genre functionality."""

import pytest
from beetsplug.bandcamp.metaguru import Metaguru

Expand Down
10 changes: 7 additions & 3 deletions tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, List, NamedTuple, Tuple

import pytest
from beetsplug.bandcamp import BandcampPlugin
from beetsplug.bandcamp.metaguru import Metaguru
from rich.console import Group
from rich.traceback import install
from rich_tables.utils import (
Expand All @@ -30,6 +28,9 @@
wrap,
)

from beetsplug.bandcamp import BandcampPlugin
from beetsplug.bandcamp.metaguru import Metaguru

if TYPE_CHECKING:
from _pytest.config import Config
from _pytest.fixtures import FixtureRequest
Expand Down Expand Up @@ -303,7 +304,10 @@ def get_tracks(data: JSONDict) -> List[Tuple[str, ...]]:
else:
artist, title = new["artist"], new["title"]

return f"{make_difftext(guru.original_albumartist, artist)} - {make_difftext(guru.original_album, title)}"
return (
f"{make_difftext(guru.original_albumartist, artist)} - "
f"{make_difftext(guru.original_album, title)}"
)


@pytest.fixture
Expand Down
9 changes: 6 additions & 3 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def test_singleton_candidates(plugin, expected_release):

assert candidates == [expected_release]


def test_bandcamp_plugin_name():
assert BandcampPlugin().data_source == "bandcamp"

Expand Down Expand Up @@ -174,9 +175,11 @@ def test_no_coverart_empty_response(monkeypatch, bandcamp_item, beets_config):
"empty",
json.dumps({"@id": "", "image": "someurl"}), # no tracks
json.dumps({"@id": "", "track": [], "image": "someurl"}), # no label
json.dumps(
{"@id": "", "track": [], "publisher": {"name": "Label"}}
), # missing image
json.dumps({
"@id": "",
"track": [],
"publisher": {"name": "Label"},
}), # missing image
),
)
def test_no_coverart_bad_html(monkeypatch, html, bandcamp_item, beets_config):
Expand Down
1 change: 1 addition & 0 deletions tests/test_real_queries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""End to end tests aimed at catching issues with html updates on bandcamp side."""

import pytest
from beetsplug.bandcamp import BandcampPlugin

Expand Down
1 change: 1 addition & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for searching functionality."""

import pytest
from beetsplug.bandcamp.search import get_matches, parse_and_sort_results

Expand Down

0 comments on commit f9d7b02

Please sign in to comment.