Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mbsantiago committed Jan 25, 2024
1 parent cd260b6 commit a1927c5
Show file tree
Hide file tree
Showing 28 changed files with 45 additions and 60 deletions.
4 changes: 2 additions & 2 deletions back/src/whombat/api/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ def load_clip_bytes(
header = b""

if bytes_to_load < 0:
return header, 0, header_size, filesize
return header, 0, len(header), filesize

current_position = start_position + start - header_size
current_position = start_position + max(start - header_size, 0)
bytes_to_load = min(
bytes_to_load,
end_position - current_position,
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/api/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from whombat.api.common import BaseAPI
from whombat.api.recordings import recordings
from whombat.core import files
from whombat.system import get_settings
from whombat.filters.base import Filter
from whombat.filters.recordings import DatasetFilter
from whombat.system import get_settings

__all__ = [
"DatasetAPI",
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/api/evaluations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
)
from whombat.api.evaluation_sets import evaluation_sets
from whombat.api.features import features
from whombat.api.io.aoef.evaluations import import_evaluation
from whombat.api.model_runs import model_runs
from whombat.filters.base import Filter
from whombat.filters.clip_evaluations import EvaluationFilter
from whombat.api.io.aoef.evaluations import import_evaluation


class EvaluationAPI(
Expand Down
4 changes: 3 additions & 1 deletion back/src/whombat/api/io/aoef/model_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from whombat.api.io.aoef.clips import get_clips
from whombat.api.io.aoef.features import get_feature_names
from whombat.api.io.aoef.recordings import get_recordings
from whombat.api.io.aoef.sound_event_predictions import get_sound_event_predictions
from whombat.api.io.aoef.sound_event_predictions import (
get_sound_event_predictions,
)
from whombat.api.io.aoef.sound_events import get_sound_events
from whombat.api.io.aoef.tags import import_tags
from whombat.api.io.aoef.users import import_users
Expand Down
1 change: 0 additions & 1 deletion back/src/whombat/core/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from PIL import Image as img
from PIL.Image import Image


__all__ = [
"array_to_image",
"image_to_buffer",
Expand Down
1 change: 0 additions & 1 deletion back/src/whombat/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from whombat.routes.tags import tags_router
from whombat.routes.user_runs import user_runs_router
from whombat.routes.users import get_users_router

from whombat.system.settings import Settings

__all__ = [
Expand Down
4 changes: 2 additions & 2 deletions back/src/whombat/routes/annotation_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from soundevent.io.aoef import to_aeof

from whombat import api, schemas
from whombat.routes.dependencies import Session, WhombatSettings
from whombat.filters.annotation_projects import AnnotationProjectFilter
from whombat.api.io import aoef
from whombat.filters.annotation_projects import AnnotationProjectFilter
from whombat.routes.dependencies import Session, WhombatSettings
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/annotation_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from soundevent.data import AnnotationState

from whombat import api, schemas
from whombat.routes.dependencies import ActiveUser, Session
from whombat.filters.annotation_tasks import AnnotationTaskFilter
from whombat.filters.clips import UUIDFilter as ClipUUIDFilter
from whombat.routes.dependencies import ActiveUser, Session
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Module containing the router for the Auth."""
from fastapi import APIRouter

from whombat.routes.dependencies.auth import get_users_api, get_auth_backend
from whombat.routes.dependencies.auth import get_auth_backend, get_users_api
from whombat.schemas.users import User, UserCreate
from whombat.system.settings import Settings

Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/clip_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from fastapi import APIRouter, Depends

from whombat import api, schemas
from whombat.routes.dependencies import ActiveUser, Session
from whombat.filters.clip_annotations import ClipAnnotationFilter
from whombat.routes.dependencies import ActiveUser, Session
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/clip_evaluations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from fastapi import APIRouter, Depends

from whombat import api, schemas
from whombat.routes.dependencies import Session
from whombat.filters.clip_evaluations import ClipEvaluationFilter
from whombat.routes.dependencies import Session
from whombat.routes.types import Limit, Offset

clip_evaluations_router = APIRouter()
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/clip_predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from fastapi import APIRouter, Depends

from whombat import api, schemas
from whombat.routes.dependencies import Session
from whombat.filters.clip_predictions import ClipPredictionFilter
from whombat.routes.dependencies import Session
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/clips.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from fastapi import APIRouter, Depends

from whombat import api, schemas
from whombat.routes.dependencies import Session
from whombat.filters.clips import ClipFilter
from whombat.filters.recordings import UUIDFilter as RecordingUUIDFilter
from whombat.routes.dependencies import Session
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
4 changes: 2 additions & 2 deletions back/src/whombat/routes/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from soundevent.io.aoef import DatasetObject, to_aeof

from whombat import api, schemas
from whombat.routes.dependencies import Session, WhombatSettings
from whombat.filters.datasets import DatasetFilter
from whombat.api.io import aoef
from whombat.filters.datasets import DatasetFilter
from whombat.routes.dependencies import Session, WhombatSettings
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
4 changes: 2 additions & 2 deletions back/src/whombat/routes/evaluation_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from soundevent.io.aoef import to_aeof

from whombat import api, schemas
from whombat.routes.dependencies import Session, WhombatSettings
from whombat.filters.evaluation_sets import EvaluationSetFilter
from whombat.api.io import aoef
from whombat.filters.evaluation_sets import EvaluationSetFilter
from whombat.routes.dependencies import Session, WhombatSettings
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/evaluations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from fastapi import APIRouter, Depends

from whombat import api, schemas
from whombat.routes.dependencies import Session
from whombat.filters.evaluations import EvaluationFilter
from whombat.routes.dependencies import Session
from whombat.routes.types import Limit, Offset

evaluations_router = APIRouter()
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from fastapi import APIRouter, Depends

from whombat import api, schemas
from whombat.routes.dependencies import Session
from whombat.filters.feature_names import FeatureNameFilter
from whombat.routes.dependencies import Session
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
4 changes: 2 additions & 2 deletions back/src/whombat/routes/model_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from fastapi import APIRouter, Depends, UploadFile

from whombat import api, schemas
from whombat.routes.dependencies import Session, WhombatSettings
from whombat.filters.model_runs import ModelRunFilter
from whombat.api.io import aoef
from whombat.filters.model_runs import ModelRunFilter
from whombat.routes.dependencies import Session, WhombatSettings
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from fastapi import APIRouter, Depends

from whombat import api, schemas
from whombat.routes.dependencies import Session
from whombat.filters.notes import NoteFilter
from whombat.routes.dependencies import Session
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from fastapi import APIRouter, Depends

from whombat import api, schemas
from whombat.routes.dependencies import ActiveUser, Session
from whombat.filters.recordings import RecordingFilter
from whombat.routes.dependencies import ActiveUser, Session
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/sound_event_evaluations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from fastapi import APIRouter, Depends

from whombat import api, schemas
from whombat.routes.dependencies import Session
from whombat.filters.sound_event_evaluations import SoundEventEvaluationFilter
from whombat.routes.dependencies import Session
from whombat.routes.types import Limit, Offset

sound_event_evaluations_router = APIRouter()
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/sound_event_predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from fastapi import APIRouter, Depends

from whombat import api, schemas
from whombat.routes.dependencies import Session
from whombat.filters.sound_event_predictions import SoundEventPredictionFilter
from whombat.routes.dependencies import Session
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from fastapi import APIRouter, Depends

from whombat import api, schemas
from whombat.routes.dependencies import Session
from whombat.filters.recording_tags import RecordingTagFilter
from whombat.filters.tags import TagFilter
from whombat.routes.dependencies import Session
from whombat.routes.types import Limit, Offset

tags_router = APIRouter()
Expand Down
2 changes: 1 addition & 1 deletion back/src/whombat/routes/user_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from fastapi import APIRouter, Depends

from whombat import api, schemas
from whombat.routes.dependencies import ActiveUser, Session
from whombat.filters.user_runs import UserRunFilter
from whombat.routes.dependencies import ActiveUser, Session
from whombat.routes.types import Limit, Offset

__all__ = [
Expand Down
8 changes: 2 additions & 6 deletions back/src/whombat/system/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,10 @@ async def whombat_init(settings: Settings, _: FastAPI):
print_first_run_message(settings)

if settings.open_on_startup and not settings.dev:
webbrowser.open(
f"http://{settings.host}:{settings.port}/first/"
)
webbrowser.open(f"http://{settings.host}:{settings.port}/first/")
return

print_ready_message(settings)

if settings.open_on_startup and not settings.dev:
webbrowser.open(
f"http://{settings.host}:{settings.port}/"
)
webbrowser.open(f"http://{settings.host}:{settings.port}/")
4 changes: 2 additions & 2 deletions back/src/whombat/system/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
We are using pydantic to define our settings.
"""
import warnings
from functools import lru_cache
from pathlib import Path
from typing import Tuple, Type
import warnings

from pydantic import ValidationError
from pydantic_settings import (
Expand Down Expand Up @@ -79,7 +79,7 @@ class Settings(BaseSettings):
port: int = 5000
"""Port on which the backend is running."""

domain: str = "http://localhost"
domain: str = "localhost"
"""Domain on which the backend is running."""

log_config: Path = Path("logging.conf")
Expand Down
32 changes: 11 additions & 21 deletions back/tests/test_api/test_audio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import struct

from whombat.api.audio import HEADER_FORMAT, CHUNK_SIZE, load_clip_bytes
from whombat.api.audio import CHUNK_SIZE, HEADER_FORMAT, load_clip_bytes


def test_load_clip_bytes(random_wav_factory):
Expand Down Expand Up @@ -35,7 +35,7 @@ def test_load_clip_bytes(random_wav_factory):
assert len(loaded_bytes) == len(read_bytes)
assert loaded_bytes == read_bytes
assert start_ == start
assert end_ == end
assert end_ == end - 1
assert filesize == path.stat().st_size


Expand Down Expand Up @@ -66,7 +66,7 @@ def test_load_clip_bytes_with_header(random_wav_factory):

assert len(loaded_bytes) == len(read_bytes)
assert start_ == start
assert end_ == end
assert end_ == end - 1
assert filesize == path.stat().st_size


Expand All @@ -87,25 +87,21 @@ def test_stream_a_whole_audio_file(random_wav_factory):
filesize = None
parts = []
while True:
end = start + 1024 * 1024

if filesize is not None and end > filesize:
end = filesize

part, start, end, filesize = load_clip_bytes(
part, start, _, filesize = load_clip_bytes(
path=path,
start=start,
end=end,
)
parts.append(part)
start = end
start = start + len(part)

assert filesize == true_filesize

if not part or start >= filesize:
break

assert b"".join(parts) == full_bytes
streamed = b"".join(parts)
assert len(streamed) == len(full_bytes)
assert streamed == full_bytes


def test_stream_a_whole_audio_file_with_non_1_speed(random_wav_factory):
Expand All @@ -127,19 +123,13 @@ def test_stream_a_whole_audio_file_with_non_1_speed(random_wav_factory):
filesize = None
parts = []
while True:
end = start + CHUNK_SIZE

if filesize is not None and end > filesize:
end = filesize

part, start, end, filesize = load_clip_bytes(
part, start, _, filesize = load_clip_bytes(
path=path,
start=start,
end=end,
speed=speed,
)
parts.append(part)
start = end
start = start + len(part)

assert filesize == true_filesize

Expand Down Expand Up @@ -169,7 +159,7 @@ def test_stream_a_whole_audio_file_with_non_1_speed(random_wav_factory):
orig_header = struct.unpack(HEADER_FORMAT, full_bytes[:44])
streamed_header = struct.unpack(HEADER_FORMAT, streamed[:44])

for (field, h1, h2) in zip(fields, orig_header, streamed_header):
for field, h1, h2 in zip(fields, orig_header, streamed_header):
if field == "samplerate":
assert int(h1 * speed) == h2
continue
Expand Down
3 changes: 1 addition & 2 deletions back/tests/test_routers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import pytest
from fastapi.testclient import TestClient

from whombat.routes.dependencies import get_settings
from whombat.system import create_app
from whombat.system.settings import Settings
from whombat.system.settings import Settings, get_settings


@pytest.fixture
Expand Down

0 comments on commit a1927c5

Please sign in to comment.