Skip to content

refactor(file_transcriber): extract methods from FileTranscriber.run to fix R0915#1539

Merged
raivisdejus merged 16 commits into
chidiwilliams:mainfrom
josiasdev:refactor/remove-code-smell-too-many-statements
Jul 1, 2026
Merged

refactor(file_transcriber): extract methods from FileTranscriber.run to fix R0915#1539
raivisdejus merged 16 commits into
chidiwilliams:mainfrom
josiasdev:refactor/remove-code-smell-too-many-statements

Conversation

@josiasdev

Copy link
Copy Markdown
Contributor

Why is this change needed?

The FileTranscriber.run method had 58 statements, exceeding Pylint's limit of 50 (too-many-statements / R0915). This made the method overly long and difficult to read, test, and maintain. It mixed three distinct responsibilities:

  1. URL downloading (yt-dlp extraction + ffmpeg conversion)
  2. Transcription orchestration (calling transcribe, stripping segments, emitting signals, writing output files)
  3. Folder watch file handling (removing or moving the source file post-transcription)

How was it tested?

  • Ran all transcriber tests with uv run pytest tests/transcriber/ -v
  • All tests passed except one pre-existing unrelated failure (test_missing_file in whisper_file_transcriber_test — a UnicodeDecodeError in the av library)
  • Pylint R0915 check now passes: Your code has been rated at 10.00/10

What was changed?

Two private helper methods were extracted from run:

  • _download_from_url(self) -> bool — encapsulates the entire URL import flow: video title extraction, yt-dlp download, ffmpeg conversion to WAV, and Windows-specific subprocess handling. Returns False on download failure so run can abort early.
  • _handle_folder_watch(self) — encapsulates the FOLDER_WATCH source file management (remove or move).

The run method was simplified from ~58 statements to ~20, now acting as a clear orchestrator of these steps.

Notes for the reviewer

  • The _download_from_url method returns a bool instead of raising an exception on download failure. This is intentional: the original code used a bare return to exit run early when the download failed, and a boolean return preserves that control flow cleanly without introducing exception-based control flow.
  • No logic was altered — only extracted. The behavior is identical to the original.

josiasdev and others added 15 commits June 17, 2026 16:42
Decompose ModelDownloader.download_model (142 statements, > 50 limit)
into four focused helpers:
  _prepare_resume_download  - existing file validation & resume logic
  _check_range_support      - server Range-request capability
  _stream_download          - HTTP streaming with progress/cancel
  _verify_sha256            - post-download integrity check

download_model now acts as a high-level orchestrator (~16 statements).
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.65753% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.88%. Comparing base (b756a47) to head (572ae6e).

Files with missing lines Patch % Lines
buzz/transcriber/recording_transcriber.py 74.00% 26 Missing ⚠️
buzz/transcriber/file_transcriber.py 76.08% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1539      +/-   ##
==========================================
+ Coverage   82.85%   82.88%   +0.02%     
==========================================
  Files         108      108              
  Lines       11627    11653      +26     
==========================================
+ Hits         9634     9659      +25     
- Misses       1993     1994       +1     
Flag Coverage Δ
Linux 81.63% <74.65%> (+0.02%) ⬆️
macOS 82.39% <74.65%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@raivisdejus
raivisdejus enabled auto-merge (squash) July 1, 2026 12:37
@raivisdejus
raivisdejus merged commit e5179fc into chidiwilliams:main Jul 1, 2026
16 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants