Add pydocstyle to the ruff rules (#52136)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Signed-off-by: Harry Mellor <hej.mellor@gmail.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
804e5377aa
commit
8c1557a79c
@@ -92,6 +92,10 @@ def load_audio_pyav(
|
||||
Args:
|
||||
path: A :class:`~io.BytesIO` buffer, a filesystem
|
||||
:class:`~pathlib.Path`, or a string path.
|
||||
sr: Target sample rate, or None to keep the native rate.
|
||||
mono: Whether to average the channels down to mono.
|
||||
max_decode_bytes: If set, abort decoding once this many bytes have
|
||||
been read from the source.
|
||||
max_duration_s: If set, abort decoding once the accumulated
|
||||
sample count exceeds this many seconds of audio. Prevents
|
||||
decompression-bomb attacks where a small compressed file
|
||||
@@ -100,6 +104,7 @@ def load_audio_pyav(
|
||||
Returns:
|
||||
``(waveform, sample_rate)`` where *waveform* is a 1-D float32
|
||||
NumPy array and *sample_rate* is the native sample rate in Hz.
|
||||
|
||||
"""
|
||||
try:
|
||||
container = av.open(path)
|
||||
@@ -209,7 +214,7 @@ def load_audio_soundfile(
|
||||
max_duration_s: float | None = None,
|
||||
max_decode_bytes: int | None = None,
|
||||
) -> tuple[np.ndarray, int]:
|
||||
"""Load audio via soundfile"""
|
||||
"""Load audio via soundfile."""
|
||||
with soundfile.SoundFile(path) as f:
|
||||
native_sr = f.samplerate
|
||||
if max_duration_s is not None:
|
||||
@@ -274,6 +279,7 @@ def load_audio_torchcodec(
|
||||
``(waveform, sample_rate)`` where *waveform* is a float32 NumPy
|
||||
array (1-D when ``mono=True``) and *sample_rate* is the output
|
||||
sample rate in Hz.
|
||||
|
||||
"""
|
||||
if AudioDecoder is None:
|
||||
# Unify "torchcodec not installed" and "system ffmpeg missing" into
|
||||
@@ -412,10 +418,17 @@ def load_audio(
|
||||
"""Load audio using the selected decoding backend.
|
||||
|
||||
Args:
|
||||
path: Audio file path or in-memory buffer.
|
||||
sr: Target sample rate, or None to keep the native rate.
|
||||
mono: Whether to downmix to a single channel.
|
||||
max_duration_s: Reject audio longer than this many seconds.
|
||||
max_decode_bytes: Reject audio that would decode to more than this
|
||||
many bytes.
|
||||
backend: One of ``AUDIO_BACKENDS``. ``None`` (default) selects
|
||||
``"auto"``, which tries soundfile, then torchcodec, then PyAV;
|
||||
the other values select a single
|
||||
backend with no fallback.
|
||||
|
||||
"""
|
||||
backend = backend or "auto"
|
||||
if backend not in AUDIO_BACKENDS:
|
||||
|
||||
@@ -14,8 +14,7 @@ _T = TypeVar("_T")
|
||||
|
||||
@dataclass
|
||||
class MediaWithBytes(Generic[_T]):
|
||||
"""
|
||||
Wrapper that couples a media object with its original encoded bytes.
|
||||
"""Wrapper that couples a media object with its original encoded bytes.
|
||||
|
||||
This ensures the raw bytes and media object remain synchronized,
|
||||
preventing cache corruption from in-place modifications.
|
||||
@@ -89,8 +88,7 @@ class MediaIO(ABC, Generic[_T]):
|
||||
|
||||
@abstractmethod
|
||||
def load_base64(self, media_type: str, data: str) -> _T:
|
||||
"""
|
||||
List of media types:
|
||||
"""List of media types:
|
||||
https://www.iana.org/assignments/media-types/media-types.xhtml
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -73,6 +73,7 @@ def _wrap_media_fetch_error(
|
||||
408/429, invalid URL)
|
||||
Original exception for transient errors (5xx, 408, 429, network blips)
|
||||
or other exceptions
|
||||
|
||||
"""
|
||||
if isinstance(exc, VLLMValidationError):
|
||||
return exc
|
||||
@@ -162,16 +163,16 @@ class MediaConnector:
|
||||
allowed_local_media_path: str = "",
|
||||
allowed_media_domains: list[str] | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
Args:
|
||||
media_io_kwargs: Additional args passed to process media
|
||||
inputs, keyed by modalities. For example,
|
||||
to set num_frames for video, set
|
||||
`--media-io-kwargs '{"video":{"num_frames":40}}'`
|
||||
connection: HTTP connection client to download media contents.
|
||||
allowed_local_media_path: A local directory to load media files from.
|
||||
allowed_media_domains: If set, only media URLs that belong to this
|
||||
domain can be used for multi-modal inputs.
|
||||
"""Args:
|
||||
media_io_kwargs: Additional args passed to process media
|
||||
inputs, keyed by modalities. For example,
|
||||
to set num_frames for video, set
|
||||
`--media-io-kwargs '{"video":{"num_frames":40}}'`
|
||||
connection: HTTP connection client to download media contents.
|
||||
allowed_local_media_path: A local directory to load media files from.
|
||||
allowed_media_domains: If set, only media URLs that belong to this
|
||||
domain can be used for multi-modal inputs.
|
||||
|
||||
"""
|
||||
super().__init__()
|
||||
|
||||
@@ -468,9 +469,7 @@ class MediaConnector:
|
||||
self,
|
||||
audio_url: str,
|
||||
) -> tuple[np.ndarray, int | float]:
|
||||
"""
|
||||
Load audio from a URL.
|
||||
"""
|
||||
"""Load audio from a URL."""
|
||||
audio_io = AudioMediaIO(**self.media_io_kwargs.get("audio", {}))
|
||||
|
||||
return self.load_from_url(
|
||||
@@ -483,9 +482,7 @@ class MediaConnector:
|
||||
self,
|
||||
audio_url: str,
|
||||
) -> tuple[np.ndarray, int | float]:
|
||||
"""
|
||||
Asynchronously fetch audio from a URL.
|
||||
"""
|
||||
"""Asynchronously fetch audio from a URL."""
|
||||
audio_io = AudioMediaIO(**self.media_io_kwargs.get("audio", {}))
|
||||
|
||||
return await self.load_from_url_async(
|
||||
@@ -500,8 +497,7 @@ class MediaConnector:
|
||||
*,
|
||||
image_mode: str | None = "RGB",
|
||||
) -> Image.Image:
|
||||
"""
|
||||
Load a PIL image from an HTTP or base64 data URL.
|
||||
"""Load a PIL image from an HTTP or base64 data URL.
|
||||
|
||||
By default, the image is converted into RGB format. Set
|
||||
`media_io_kwargs={"image": {"image_mode": None}}` to keep the
|
||||
@@ -527,8 +523,7 @@ class MediaConnector:
|
||||
*,
|
||||
image_mode: str | None = "RGB",
|
||||
) -> Image.Image:
|
||||
"""
|
||||
Asynchronously load a PIL image from an HTTP or base64 data URL.
|
||||
"""Asynchronously load a PIL image from an HTTP or base64 data URL.
|
||||
|
||||
By default, the image is converted into RGB format. Set
|
||||
`media_io_kwargs={"image": {"image_mode": None}}` to keep the
|
||||
@@ -555,9 +550,7 @@ class MediaConnector:
|
||||
image_mode: str | None = "RGB",
|
||||
video_processor: str | None = None,
|
||||
) -> MediaWithBytes[tuple[npt.NDArray, dict[str, Any]]]:
|
||||
"""
|
||||
Load video from an HTTP or base64 data URL.
|
||||
"""
|
||||
"""Load video from an HTTP or base64 data URL."""
|
||||
image_io = ImageMediaIO(
|
||||
**({"image_mode": image_mode} | self.media_io_kwargs.get("image", {}))
|
||||
)
|
||||
@@ -581,8 +574,7 @@ class MediaConnector:
|
||||
image_mode: str | None = "RGB",
|
||||
video_processor: str | None = None,
|
||||
) -> MediaWithBytes[tuple[npt.NDArray, dict[str, Any]]]:
|
||||
"""
|
||||
Asynchronously load video from an HTTP or base64 data URL.
|
||||
"""Asynchronously load video from an HTTP or base64 data URL.
|
||||
|
||||
By default, the image is converted into RGB format. Set
|
||||
`media_io_kwargs={"image": {"image_mode": None}}` to keep the
|
||||
@@ -608,9 +600,7 @@ class MediaConnector:
|
||||
self,
|
||||
data: str,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Load image embedding from a URL.
|
||||
"""
|
||||
"""Load image embedding from a URL."""
|
||||
image_embedding_io = ImageEmbeddingMediaIO()
|
||||
|
||||
return image_embedding_io.load_base64("", data)
|
||||
@@ -619,9 +609,7 @@ class MediaConnector:
|
||||
self,
|
||||
data: str,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Asynchronously load image embedding from a URL.
|
||||
"""
|
||||
"""Asynchronously load image embedding from a URL."""
|
||||
image_embedding_io = ImageEmbeddingMediaIO()
|
||||
loop = asyncio.get_running_loop()
|
||||
|
||||
@@ -633,9 +621,7 @@ class MediaConnector:
|
||||
self,
|
||||
data: str,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Load audio embedding from a URL.
|
||||
"""
|
||||
"""Load audio embedding from a URL."""
|
||||
audio_embedding_io = AudioEmbeddingMediaIO()
|
||||
|
||||
return audio_embedding_io.load_base64("", data)
|
||||
@@ -644,9 +630,7 @@ class MediaConnector:
|
||||
self,
|
||||
data: str,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Asynchronously load audio embedding from a URL.
|
||||
"""
|
||||
"""Asynchronously load audio embedding from a URL."""
|
||||
audio_embedding_io = AudioEmbeddingMediaIO()
|
||||
loop = asyncio.get_running_loop()
|
||||
|
||||
@@ -658,9 +642,7 @@ class MediaConnector:
|
||||
self,
|
||||
data: str,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Load video embedding from a URL.
|
||||
"""
|
||||
"""Load video embedding from a URL."""
|
||||
video_embedding_io = VideoEmbeddingMediaIO()
|
||||
|
||||
return video_embedding_io.load_base64("", data)
|
||||
@@ -669,9 +651,7 @@ class MediaConnector:
|
||||
self,
|
||||
data: str,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Asynchronously load video embedding from a URL.
|
||||
"""
|
||||
"""Asynchronously load video embedding from a URL."""
|
||||
video_embedding_io = VideoEmbeddingMediaIO()
|
||||
loop = asyncio.get_running_loop()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user