diff --git a/bats_ai/core/management/commands/copy_recordings.py b/bats_ai/core/management/commands/copy_recordings.py index 735cfae5..c11781a6 100644 --- a/bats_ai/core/management/commands/copy_recordings.py +++ b/bats_ai/core/management/commands/copy_recordings.py @@ -151,7 +151,7 @@ def add_arguments(self, parser): ), ) - def handle(self, *args, **options): + def handle(self, *args, **options): # noqa: C901, PLR0912, PLR0915 count = options["count"] tags_raw = options["tags"] or ",".join(DEFAULT_TAGS) tag_texts = [t.strip() for t in tags_raw.split(",") if t.strip()] diff --git a/bats_ai/core/management/commands/importRecordings.py b/bats_ai/core/management/commands/importRecordings.py index d66c6865..91c547ed 100644 --- a/bats_ai/core/management/commands/importRecordings.py +++ b/bats_ai/core/management/commands/importRecordings.py @@ -55,7 +55,7 @@ def add_arguments(self, parser): ), ) - def handle(self, *args, **options): + def handle(self, *args, **options): # noqa: C901, PLR0912, PLR0915 directory_path = Path(options["directory"]) owner_username = options.get("owner") is_public = options.get("public", False) diff --git a/bats_ai/core/management/commands/loadGRTS.py b/bats_ai/core/management/commands/loadGRTS.py index 3f13605a..a77183a6 100644 --- a/bats_ai/core/management/commands/loadGRTS.py +++ b/bats_ai/core/management/commands/loadGRTS.py @@ -65,7 +65,7 @@ def _download_file(self, url: str, zip_path: Path) -> None: with zip_path.open("wb") as f: f.write(response.content) - def handle(self, *args, **options): + def handle(self, *args, **options): # noqa: C901, PLR0912, PLR0915 batch_size = options["batch_size"] # Track existing IDs to avoid duplicates diff --git a/bats_ai/core/management/commands/load_public_dataset.py b/bats_ai/core/management/commands/load_public_dataset.py index 4ac7bb63..e7b64b3c 100644 --- a/bats_ai/core/management/commands/load_public_dataset.py +++ b/bats_ai/core/management/commands/load_public_dataset.py @@ -108,7 +108,7 @@ def _try_start_spectrogram_generation(recording_id: int): recording_compute_spectrogram.delay(recording_id) -def _ingest_files_from_manifest( +def _ingest_files_from_manifest( # noqa: C901, PLR0912, PLR0913, PLR0915 *, s3_client, bucket: str, diff --git a/bats_ai/core/management/commands/load_species_geojson.py b/bats_ai/core/management/commands/load_species_geojson.py index ec72e51f..f979133d 100644 --- a/bats_ai/core/management/commands/load_species_geojson.py +++ b/bats_ai/core/management/commands/load_species_geojson.py @@ -32,7 +32,7 @@ def add_arguments(self, parser): help="Delete all SpeciesRange rows before loading.", ) - def handle(self, *args, **options): + def handle(self, *args, **options): # noqa: C901 path = Path(options["geojson_path"] or DEFAULT_GEOJSON).resolve() if not path.is_file(): raise CommandError(f"GeoJSON file not found: {path}") diff --git a/bats_ai/core/tasks/export_task.py b/bats_ai/core/tasks/export_task.py index 30beb52a..494c6bc5 100644 --- a/bats_ai/core/tasks/export_task.py +++ b/bats_ai/core/tasks/export_task.py @@ -75,7 +75,7 @@ def annotation_to_dict( return data -def write_csv_and_json( +def write_csv_and_json( # noqa: PLR0913 zipf, name_prefix, queryset, diff --git a/bats_ai/core/tasks/nabat/tasks.py b/bats_ai/core/tasks/nabat/tasks.py index 70cc01ae..512d04b0 100644 --- a/bats_ai/core/tasks/nabat/tasks.py +++ b/bats_ai/core/tasks/nabat/tasks.py @@ -22,7 +22,7 @@ logger = logging.getLogger("NABatDataRetrieval") -def generate_spectrograms( +def generate_spectrograms( # noqa: C901, PLR0915 self, nabat_recording: NABatRecording, presigned_url: str, processing_task: ProcessingTask ): from bats_ai.core.utils.batbot_metadata import generate_spectrogram_assets diff --git a/bats_ai/core/tasks/tasks.py b/bats_ai/core/tasks/tasks.py index 5870cdbe..0bae446c 100644 --- a/bats_ai/core/tasks/tasks.py +++ b/bats_ai/core/tasks/tasks.py @@ -27,7 +27,7 @@ @app.task(bind=True) -def recording_compute_spectrogram(self, recording_id: int): +def recording_compute_spectrogram(self, recording_id: int): # noqa: C901, PLR0912, PLR0915 from bats_ai.core.utils.batbot_metadata import generate_spectrogram_assets celery_id = getattr(self.request, "id", None) diff --git a/bats_ai/core/utils/contour_utils.py b/bats_ai/core/utils/contour_utils.py index 018890fd..b5028724 100644 --- a/bats_ai/core/utils/contour_utils.py +++ b/bats_ai/core/utils/contour_utils.py @@ -86,7 +86,7 @@ def auto_histogram_levels( return groups -def compute_auto_levels( +def compute_auto_levels( # noqa: PLR0913 data: npt.NDArray, mode: str, percentile_values, @@ -227,7 +227,7 @@ def apply_transparency_mask(mat, threshold_percent): # ----------------------------------------------------------------------------- -def extract_contours( +def extract_contours( # noqa: PLR0913 image_path: Path, *, levels_mode: str, @@ -277,7 +277,7 @@ def extract_contours( return sorted(contours, key=lambda x: x[1]), img.shape -def process_spectrogram_assets_for_contours( +def process_spectrogram_assets_for_contours( # noqa: C901, PLR0913 assets: dict[str, Any], *, levels_mode: str = "percentile", diff --git a/bats_ai/core/utils/guano_utils.py b/bats_ai/core/utils/guano_utils.py index b73f4089..3f76af1f 100644 --- a/bats_ai/core/utils/guano_utils.py +++ b/bats_ai/core/utils/guano_utils.py @@ -86,7 +86,7 @@ def extract_metadata_from_filename(filename: str) -> dict: return metadata -def extract_guano_metadata(file_path: str | Path, *, check_filename: bool = False) -> dict: +def extract_guano_metadata(file_path: str | Path, *, check_filename: bool = False) -> dict: # noqa: C901 """Extract GUANO metadata from a WAV file. Args: diff --git a/bats_ai/core/views/nabat/nabat_recording.py b/bats_ai/core/views/nabat/nabat_recording.py index aaa94757..62ff7503 100644 --- a/bats_ai/core/views/nabat/nabat_recording.py +++ b/bats_ai/core/views/nabat/nabat_recording.py @@ -82,7 +82,7 @@ def decode_jwt(token): return json.loads(decoded_str) -def get_email_if_authorized( +def get_email_if_authorized( # noqa: PLR0911 request: HttpRequest, api_token: str, recording_id: int | None = None, @@ -196,7 +196,7 @@ def update_nabat_species(species_id: int, api_token: str, recording_id: int, sur @router.post("/", auth=None) -def generate_nabat_recording( +def generate_nabat_recording( # noqa: PLR0911 request: HttpRequest, payload: Form[NABatRecordingGenerateSchema], ): diff --git a/bats_ai/core/views/recording.py b/bats_ai/core/views/recording.py index 181f30cf..8778247c 100644 --- a/bats_ai/core/views/recording.py +++ b/bats_ai/core/views/recording.py @@ -351,7 +351,7 @@ def create_recording( @router.patch("/{pk}") -def update_recording(request: HttpRequest, pk: int, recording_data: RecordingUploadSchema): +def update_recording(request: HttpRequest, pk: int, recording_data: RecordingUploadSchema): # noqa: C901, PLR0912 try: recording = Recording.objects.get(pk=pk, owner=request.user) except Recording.DoesNotExist: @@ -484,7 +484,7 @@ def delete_recording( @router.get("/", response=RecordingPaginatedResponse) -def get_recordings( +def get_recordings( # noqa: C901 request: HttpRequest, q: Query[RecordingListQuerySchema], ): @@ -1085,7 +1085,7 @@ def put_annotation( @router.patch("/{recording_pk}/annotations/{annotation_pk}") -def patch_annotation( +def patch_annotation( # noqa: C901, PLR0912 request, recording_pk: int, annotation_pk: int, @@ -1168,10 +1168,7 @@ def patch_sequence_annotation( annotation_instance.end_time = annotation.end_time if annotation.comments: annotation_instance.comments = annotation.comments - if annotation.type: - annotation_instance.type = annotation.type - else: - annotation_instance.type = None + annotation_instance.type = annotation.type or None annotation_instance.save() # Clear existing species associations diff --git a/bats_ai/core/views/recording_location.py b/bats_ai/core/views/recording_location.py index 8c3fea48..4ad1edaa 100644 --- a/bats_ai/core/views/recording_location.py +++ b/bats_ai/core/views/recording_location.py @@ -62,7 +62,7 @@ def _split_tags(tags: str | None) -> list[str]: return [t.strip() for t in tags.split(",") if t.strip()] -def _apply_recording_filters_and_sort( +def _apply_recording_filters_and_sort( # noqa: PLR0913 *, qs: QuerySet[Recording], exclude_submitted: bool, diff --git a/pyproject.toml b/pyproject.toml index 0d9a3ba6..030c1523 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -157,15 +157,10 @@ ignore = [ # Project-specific "BLE001", # blind-except - "C901", # complex-structure "DJ001", # django-nullable-model-string-field "N815", # mixed-case-variable-in-class-scope "N999", # invalid-module-name "PLC0415", # import-outside-top-level - "PLR0911", # too-many-return-statements - "PLR0912", # too-many-branches - "PLR0913", # too-many-arguments - "PLR0915", # too-many-statements "PLW2901", # redefined-loop-name "PTH", # flake8-use-pathlib "S110", # try-except-pass diff --git a/scripts/contours/extract_contours.py b/scripts/contours/extract_contours.py index 9c5f3783..a9035cfe 100644 --- a/scripts/contours/extract_contours.py +++ b/scripts/contours/extract_contours.py @@ -98,7 +98,7 @@ def auto_histogram_levels( return groups -def compute_auto_levels( +def compute_auto_levels( # noqa: PLR0913 data: np.ndarray, mode: str, percentile_values, @@ -315,7 +315,7 @@ def apply_transparency_mask(mat, threshold_percent): # ----------------------------------------------------------------------------- -def extract_contours( +def extract_contours( # noqa: PLR0913 image_path: Path, *, output_path: Path | None = None, @@ -410,7 +410,7 @@ def extract_contours( is_flag=True, help="Save debug images (filtered and unfiltered) to the output directory", ) -def main(input_path: str, out_dir, verbose, debug_images, **kwargs): +def main(input_path: str, out_dir, verbose, debug_images, **kwargs): # noqa: C901, PLR0912, PLR0915 logging.basicConfig(level=logging.INFO if verbose else logging.WARNING) out_dir = Path(out_dir) diff --git a/scripts/generateSpectrograms.py b/scripts/generateSpectrograms.py index 27bc6c97..c80584cf 100644 --- a/scripts/generateSpectrograms.py +++ b/scripts/generateSpectrograms.py @@ -21,7 +21,7 @@ COLORMAP_ALLOWED = [None, "gist_yarg", "turbo"] -def generate_spectrogram(wav_path, output_folder, colormap=None): +def generate_spectrogram(wav_path, output_folder, colormap=None): # noqa: C901, PLR0915 try: sig, sr = librosa.load(wav_path, sr=None) duration = len(sig) / sr diff --git a/scripts/synthetic/waveGenerator.py b/scripts/synthetic/waveGenerator.py index 48f1158b..4086221b 100755 --- a/scripts/synthetic/waveGenerator.py +++ b/scripts/synthetic/waveGenerator.py @@ -155,7 +155,7 @@ def generate_spectrogram(wav_path, output_path, colormap="turbo"): return None, None -def generate_compressed(img_path, duration, annotation_path, output_path): +def generate_compressed(img_path, duration, annotation_path, output_path): # noqa: C901 try: img = np.array(Image.open(img_path)) canvas = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY).astype(np.float32)