Skip to content

Commit bf3d525

Browse files
committed
fixed all linting issues from new ruff settings
1 parent f178807 commit bf3d525

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+185
-107
lines changed

back/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ dev-dependencies = [
7979
"httpx>=0.23.3",
8080
"tox>=4.7.0",
8181
"flake8>=6.1.0",
82-
"pyright>=1.1.320",
82+
"pyright>=1.1.363",
8383
"ruff>=0.1.7",
8484
"icecream>=2.1.3",
8585
"pytest-xdist>=3.5.0",

back/src/whombat/api/annotation_projects.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ async def from_soundevent(
225225
session: AsyncSession,
226226
data: data.AnnotationProject,
227227
) -> schemas.AnnotationProject:
228-
"""Convert a soundevent Annotation Project to a Whombat annotation
229-
project.
228+
"""Convert a soundevent Annotation Project to a Whombat annotation project.
230229
231230
Parameters
232231
----------
@@ -263,8 +262,7 @@ async def to_soundevent(
263262
obj: schemas.AnnotationProject,
264263
audio_dir: Path | None = None,
265264
) -> data.AnnotationProject:
266-
"""Convert a Whombat annotation project to a soundevent annotation
267-
project.
265+
"""Convert a Whombat annotation project to a soundevent annotation project.
268266
269267
Parameters
270268
----------

back/src/whombat/api/audio.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def load_audio(
2323
recording: schemas.Recording,
2424
start_time: float | None = None,
2525
end_time: float | None = None,
26-
audio_dir: Path = Path.cwd(),
27-
audio_parameters: schemas.AudioParameters = schemas.AudioParameters(),
26+
audio_dir: Path | None = None,
27+
audio_parameters: schemas.AudioParameters | None = None,
2828
):
2929
"""Load audio.
3030
@@ -46,6 +46,12 @@ def load_audio(
4646
bytes
4747
Audio data.
4848
"""
49+
if audio_dir is None:
50+
audio_dir = Path().cwd()
51+
52+
if audio_parameters is None:
53+
audio_parameters = schemas.AudioParameters()
54+
4955
# Set start and end times.
5056
if start_time is None:
5157
start_time = 0.0
@@ -233,7 +239,6 @@ def generate_wav_header(
233239
The structure of the WAV header is described in
234240
(WAV PCM soundfile format)[http://soundfile.sapp.org/doc/WaveFormat/].
235241
"""
236-
237242
byte_rate = samplerate * channels * bit_depth // 8
238243
block_align = channels * bit_depth // 8
239244

back/src/whombat/api/clip_evaluations.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ async def to_soundevent(
239239
audio_dir: Path | None = None,
240240
evaluations: Sequence[schemas.SoundEventEvaluation] | None = None,
241241
) -> data.ClipEvaluation:
242-
"""Create a clip evaluation in soundevent format from a clip evaluation
243-
in whombat format.
242+
"""Create a clip evaluation in soundevent format from a clip evaluation in whombat format.
244243
245244
Parameters
246245
----------

back/src/whombat/api/clips.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async def create_many_without_duplicates(
112112
clip_features = await self._create_clip_features(session, clips)
113113
return [
114114
clip.model_copy(update=dict(features=features))
115-
for clip, features in zip(clips, clip_features)
115+
for clip, features in zip(clips, clip_features, strict=False)
116116
]
117117

118118
async def add_feature(
@@ -298,7 +298,6 @@ async def _create_clip_features(
298298
list[list[schemas.Feature]]
299299
List of features created for each clip.
300300
"""
301-
302301
clip_features = [
303302
[
304303
schemas.Feature(name=name, value=value)
@@ -309,7 +308,7 @@ async def _create_clip_features(
309308

310309
create_values = [
311310
(clip.id, feature.name, feature.value)
312-
for clip, features in zip(clips, clip_features)
311+
for clip, features in zip(clips, clip_features, strict=False)
313312
for feature in features
314313
]
315314

back/src/whombat/api/common/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def _clear_from_cache(self, obj: WhombatSchema) -> None:
366366
self._cache.pop(pk, None)
367367

368368
def _get_pk_condition(self, pk: PrimaryKey) -> _ColumnExpressionArgument:
369-
column = getattr(self._model, "uuid")
369+
column = self._model.uuid # type: ignore
370370
if not column:
371371
raise NotImplementedError(
372372
f"The model {self._model.__name__} does not have a column named"
@@ -375,7 +375,7 @@ def _get_pk_condition(self, pk: PrimaryKey) -> _ColumnExpressionArgument:
375375
return column == pk
376376

377377
def _get_pk_from_obj(self, obj: WhombatSchema) -> PrimaryKey:
378-
pk = getattr(obj, "uuid")
378+
pk = obj.uuid # type: ignore
379379
if not pk:
380380
raise NotImplementedError(
381381
"The primary key could not be retrieved from the object. "

back/src/whombat/api/datasets.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ async def add_recordings(
310310
if not recording.path.is_relative_to(obj.audio_dir):
311311
warnings.warn(
312312
"The recording is not part of the dataset audio "
313-
f"directory. \ndataset = {obj}\nrecording = {recording}"
313+
f"directory. \ndataset = {obj}\nrecording = {recording}",
314+
stacklevel=2,
314315
)
315316
continue
316317

back/src/whombat/api/evaluation_sets.py

-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ async def _update_from_soundevent(
404404
data: data.EvaluationSet,
405405
) -> schemas.EvaluationSet:
406406
"""Update an evaluation set from an object in `soundevent` format."""
407-
408407
_existing_tags = {(t.key, t.value) for t in obj.tags}
409408
for t in data.evaluation_tags:
410409
if (t.key, t.value) not in _existing_tags:

back/src/whombat/api/io/aoef/annotation_tasks.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ async def _create_annotation_tasks(
8989

9090
missing = [
9191
(t, proj_uuid)
92-
for (t, proj_uuid) in zip(annotation_tasks, annotation_project_uuids)
92+
for (t, proj_uuid) in zip(
93+
annotation_tasks, annotation_project_uuids, strict=False
94+
)
9395
if t.uuid not in mapping
9496
]
9597
if not missing:

back/src/whombat/api/io/aoef/clip_annotations.py

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ async def _create_clip_annotation_notes(
136136
users: dict[UUID, UUID],
137137
) -> None:
138138
"""Create clip annotation notes."""
139-
140139
notes = [
141140
note
142141
for annotation in clip_annotations

back/src/whombat/api/io/aoef/clip_evaluations.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ async def _create_clip_evaluations(
9292

9393
missing = [
9494
(clip_evals, eval_uuid)
95-
for clip_evals, eval_uuid in zip(clip_evaluations, evaluations_uuids)
95+
for clip_evals, eval_uuid in zip(
96+
clip_evaluations, evaluations_uuids, strict=False
97+
)
9698
if clip_evals.uuid not in mapping
9799
]
98100
if not missing:

back/src/whombat/api/io/aoef/datasets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async def import_dataset(
9999

100100

101101
def normalize_path(path: Path, dataset_dir: Path) -> Path:
102-
"""Normalize a path to a dataset directory"""
102+
"""Normalize a path to a dataset directory."""
103103
if path.is_absolute():
104104
return path.relative_to(dataset_dir)
105105
return path

back/src/whombat/api/io/aoef/recordings.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def import_recordings(
6161
users: dict[UUID, UUID],
6262
feature_names: dict[str, int],
6363
audio_dir: Path | None = None,
64-
base_audio_dir: Path = Path.home(),
64+
base_audio_dir: Path | None = None,
6565
) -> dict[UUID, int]:
6666
"""Import a set of recordings in AOEF format into the database.
6767
@@ -74,6 +74,9 @@ async def import_recordings(
7474
if not recordings:
7575
return {}
7676

77+
if base_audio_dir is None:
78+
base_audio_dir = Path.home()
79+
7780
if not audio_dir:
7881
# If no audio directory is given, assume that the paths are relative
7982
# to the base audio directory

back/src/whombat/api/io/aoef/sound_event_annotations.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ async def _create_sound_event_annotations(
122122

123123
missing = [
124124
(s, ca_uuid)
125-
for s, ca_uuid in zip(sound_events_annotations, clip_annotation_uuids)
125+
for s, ca_uuid in zip(
126+
sound_events_annotations, clip_annotation_uuids, strict=False
127+
)
126128
if s.uuid not in mapping
127129
]
128130
if not missing:

back/src/whombat/api/io/aoef/sound_event_evaluations.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ async def _create_sound_event_evaluations(
100100

101101
missing = [
102102
(match, eval_uuid)
103-
for match, eval_uuid in zip(matches, clip_evaluation_uuids)
103+
for match, eval_uuid in zip(
104+
matches, clip_evaluation_uuids, strict=False
105+
)
104106
if match.uuid not in mapping
105107
]
106108

back/src/whombat/api/io/aoef/sound_event_predictions.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ async def _create_sound_event_predictions(
109109

110110
missing = [
111111
(s, ca_uuid)
112-
for s, ca_uuid in zip(sound_events_predictions, clip_prediction_uuids)
112+
for s, ca_uuid in zip(
113+
sound_events_predictions, clip_prediction_uuids, strict=False
114+
)
113115
if s.uuid not in mapping
114116
]
115117
if not missing:

back/src/whombat/api/io/aoef/tags.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async def import_tags(
1111
session: AsyncSession,
1212
tags: list[TagObject],
1313
) -> dict[int, int]:
14-
"""Import tags from a list of dicts"""
14+
"""Import tags from a list of dicts."""
1515
if not tags:
1616
return {}
1717

back/src/whombat/api/recordings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import datetime
44
import logging
5-
import soundfile as sf
65
from functools import partial
76
from multiprocessing import Pool
87
from pathlib import Path
98
from typing import Sequence
109
from uuid import UUID
1110

1211
import cachetools
12+
import soundfile as sf
1313
from soundevent import data
14-
from soundevent.audio import compute_md5_checksum, get_media_info, MediaInfo
14+
from soundevent.audio import MediaInfo, compute_md5_checksum, get_media_info
1515
from sqlalchemy import and_
1616
from sqlalchemy.ext.asyncio import AsyncSession
1717

back/src/whombat/api/sound_event_annotations.py

-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ async def _create_from_soundevent(
306306
schemas.SoundEventAnnotation
307307
The created annotation.
308308
"""
309-
310309
user = None
311310
if data.created_by is not None:
312311
user = await users.from_soundevent(session, data.created_by)

back/src/whombat/api/sound_event_predictions.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ async def _create_from_soundevent(
265265
data: data.SoundEventPrediction,
266266
clip_prediction: schemas.ClipPrediction,
267267
) -> schemas.SoundEventPrediction:
268-
"""Create a new Whombat sound event prediction from a sound event
269-
prediction in soundevent format.
268+
"""Create a sound event prediction from one in soundevent format.
270269
271270
Parameters
272271
----------

back/src/whombat/api/spectrograms.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44

55
import numpy as np
6-
from soundevent import audio, arrays
6+
from soundevent import arrays, audio
77

88
import whombat.api.audio as audio_api
99
from whombat import schemas
@@ -20,7 +20,7 @@ def compute_spectrogram(
2020
end_time: float,
2121
audio_parameters: schemas.AudioParameters,
2222
spectrogram_parameters: schemas.SpectrogramParameters,
23-
audio_dir: Path = Path.cwd(),
23+
audio_dir: Path | None = None,
2424
) -> np.ndarray:
2525
"""Compute a spectrogram for a recording.
2626
@@ -42,6 +42,9 @@ def compute_spectrogram(
4242
DataArray
4343
Spectrogram image.
4444
"""
45+
if audio_dir is None:
46+
audio_dir = Path.cwd()
47+
4548
wav = audio_api.load_audio(
4649
recording,
4750
start_time,

back/src/whombat/core/spectrograms.py

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def normalize_spectrogram(
3030
xr.DataArray
3131
Normalized array.
3232
"""
33-
3433
attrs = spectrogram.attrs
3534
min_val = attrs.get("min_dB")
3635
if min_val is None or relative:

back/src/whombat/filters/annotation_tasks.py

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class RecordingTagFilter(base.Filter):
2323

2424
def filter(self, query: Select) -> Select:
2525
"""Filter the query."""
26-
2726
if self.key is None and self.value is None:
2827
return query
2928

back/src/whombat/migrations/env.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ def do_run_migrations(connection: Connection) -> None:
8686

8787

8888
def run_migrations() -> None:
89-
"""In this scenario we need to create an Engine and associate a connection
90-
with the context."""
89+
"""Run migrations synchronously."""
9190
configuration = get_configurations()
9291

9392
connectable = engine_from_config(
@@ -102,8 +101,7 @@ def run_migrations() -> None:
102101

103102

104103
async def run_async_migrations() -> None:
105-
"""In this scenario we need to create an Engine and associate a connection
106-
with the context."""
104+
"""Run migrations asynchronously."""
107105
configuration = get_configurations()
108106

109107
connectable = async_engine_from_config(

back/src/whombat/migrations/versions/03a1d239e06e_first_migration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""first migration
1+
"""first migration.
22
33
Revision ID: 03a1d239e06e
44
Revises:

back/src/whombat/models/clip_annotation.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class ClipAnnotation(Base):
3434
The sound events annotated in the clip.
3535
tags
3636
The tags attached to the annotation.
37-
notes
37+
38+
Notes
39+
-----
3840
The notes attached to the annotation.
3941
clip
4042
The clip to which the annotation belongs.

back/src/whombat/models/recording.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ class Recording(Base):
7676
The time expansion factor of the recording.
7777
rights
7878
A string describing the usage rights of the recording.
79-
notes
79+
80+
Notes
81+
-----
8082
A list of notes associated with the recording.
8183
tags
8284
A list of tags associated with the recording.

back/src/whombat/models/sound_event_annotation.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class SoundEventAnnotation(Base):
3838
The sound event annotated by the annotation.
3939
tags
4040
A list of tags associated with the annotation.
41-
notes
41+
42+
Notes
43+
-----
4244
A list of notes associated with the annotation.
4345
clip_annotation
4446
The clip annotation to which the annotation belongs.

back/src/whombat/plugins.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ def load_plugins() -> Generator[tuple[str, ModuleType], None, None]:
3535
module = importlib.import_module(name)
3636

3737
if not hasattr(module, "__description__"):
38-
warnings.warn(f"Plugin {name} has no __description__ attribute.")
38+
warnings.warn(
39+
f"Plugin {name} has no __description__ attribute.",
40+
stacklevel=2,
41+
)
3942
continue
4043

4144
if not hasattr(module, "__version__"):
42-
warnings.warn(f"Plugin {name} has no __version__ attribute.")
45+
warnings.warn(
46+
f"Plugin {name} has no __version__ attribute.", stacklevel=2
47+
)
4348

4449
yield name[8:], module
4550

0 commit comments

Comments
 (0)