Skip to content

Commit aa49385

Browse files
committed
artresizer: address review
1 parent 720023c commit aa49385

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

beets/util/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,9 +1042,6 @@ def __get__(self, instance, owner):
10421042
return self.cache[owner]
10431043

10441044

1045-
T = TypeVar("T")
1046-
1047-
10481045
class LazySharedInstance(Generic[T]):
10491046
"""A descriptor that provides access to a lazily-created shared instance of
10501047
the containing class, while calling the class constructor to construct a

beets/util/artresizer.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,15 @@ class LocalBackend(ABC):
7676
@classmethod
7777
@abstractmethod
7878
def version(cls) -> Any:
79+
"""Return the backend version if its dependencies are satisfied or
80+
raise `LocalBackendNotAvailableError`.
81+
"""
7982
pass
8083

8184
@classmethod
8285
def available(cls) -> bool:
86+
"""Return `True` this backend's dependencies are satisfied and it can
87+
be used, `False` otherwise."""
8388
try:
8489
cls.version()
8590
return True
@@ -95,10 +100,15 @@ def resize(
95100
quality: int = 0,
96101
max_filesize: int = 0,
97102
) -> bytes:
103+
"""Resize an image to the given width and return the output path.
104+
105+
On error, logs a warning and returns `path_in`.
106+
"""
98107
pass
99108

100109
@abstractmethod
101110
def get_size(self, path_in: bytes) -> tuple[int, int] | None:
111+
"""Return the (width, height) of the image or None if unavailable."""
102112
pass
103113

104114
@abstractmethod
@@ -107,10 +117,15 @@ def deinterlace(
107117
path_in: bytes,
108118
path_out: bytes | None = None,
109119
) -> bytes:
120+
"""Remove interlacing from an image and return the output path.
121+
122+
On error, logs a warning and returns `path_in`.
123+
"""
110124
pass
111125

112126
@abstractmethod
113127
def get_format(self, path_in: bytes) -> str | None:
128+
"""Return the image format (e.g., 'PNG') or None if undetectable."""
114129
pass
115130

116131
@abstractmethod
@@ -120,10 +135,15 @@ def convert_format(
120135
target: bytes,
121136
deinterlaced: bool,
122137
) -> bytes:
138+
"""Convert an image to a new format and return the new file path.
139+
140+
On error, logs a warning and returns `source`.
141+
"""
123142
pass
124143

125144
@property
126145
def can_compare(self) -> bool:
146+
"""Indicate whether image comparison is supported by this backend."""
127147
return False
128148

129149
def compare(
@@ -132,14 +152,24 @@ def compare(
132152
im2: bytes,
133153
compare_threshold: float,
134154
) -> bool | None:
155+
"""Compare two images and return `True` if they are similar enough, or
156+
`None` if there is an error.
157+
158+
This must only be called if `self.can_compare()` returns `True`.
159+
"""
135160
# It is an error to call this when ArtResizer.can_compare is not True.
136161
raise NotImplementedError()
137162

138163
@property
139164
def can_write_metadata(self) -> bool:
165+
"""Indicate whether writing metadata to images is supported."""
140166
return False
141167

142168
def write_metadata(self, file: bytes, metadata: Mapping[str, str]) -> None:
169+
"""Write key-value metadata into the image file.
170+
171+
This must only be called if `self.can_write_metadata()` returns `True`.
172+
"""
143173
# It is an error to call this when ArtResizer.can_write_metadata is not True.
144174
raise NotImplementedError()
145175

0 commit comments

Comments
 (0)