Skip to content

bpd plugin: use asyncio directly and remove bluelet - #6903

Open
snejus wants to merge 2 commits into
masterfrom
refactor-bluelet
Open

bpd plugin: use asyncio directly and remove bluelet#6903
snejus wants to merge 2 commits into
masterfrom
refactor-bluelet

Conversation

@snejus

@snejus snejus commented Aug 4, 2026

Copy link
Copy Markdown
Member

So I was looking to add types to beets.util.bluelet and realised that it is only used by BPD plugin. Instead of investing any time into it, I scrapped it and used asyncio directly in BPD. I used GitHub search to check that it is not used outside of our codebase.


  • Replaces the custom coroutine scheduler in beets.util.bluelet with Python's built-in asyncio for the bpd plugin.

  • In beetsplug/bpd/__init__.py, the server architecture shifts from Bluelet generators and event objects to native async I/O:

    • connection handling now uses asyncio.start_server
    • connection flows are rewritten as async def methods with await
    • notification delivery is handled with background asyncio tasks
    • socket lifecycle and disconnect handling move to asyncio stream readers/writers
  • This removes an internal async framework from the codebase, consolidates bpd on a standard runtime model, and makes the networking layer simpler to reason about and maintain.

  • Tests in test/plugins/test_bpd.py are updated to mock asyncio.start_server instead of Bluelet internals, matching the new server entrypoint and preserving coverage around dynamic port assignment.

Copilot AI review requested due to automatic review settings August 4, 2026 00:08
@snejus
snejus requested a review from a team as a code owner August 4, 2026 00:08
@github-actions github-actions Bot added the bpd bpd plugin label Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

grug see PR move bpd plugin off custom Bluelet scheduler and onto stdlib asyncio. this remove homegrown async engine and make server code speak native async/await.

Changes:

  • rewrite beetsplug.bpd server + connection flow to asyncio.start_server and stream reader/writer
  • remove beets.util.bluelet module
  • update BPD tests + changelog for new server entrypoint and behavior

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
beetsplug/bpd/__init__.py replace Bluelet generator scheduler with asyncio servers/tasks; refactor connection I/O to streams
beets/util/bluelet.py delete Bluelet implementation (no longer used)
test/plugins/test_bpd.py mock asyncio.start_server instead of Bluelet listener for dynamic port assignment test
docs/changelog.rst add unreleased changelog entry noting BPD move to asyncio

Comment thread beetsplug/bpd/__init__.py Outdated
Comment on lines +269 to +272
for conn in list(self.connections):
yield bluelet.spawn(conn.send_notifications())
task = asyncio.create_task(conn.send_notifications())
self._notification_tasks.add(task)
task.add_done_callback(self._notification_tasks.discard)
Comment thread beetsplug/bpd/__init__.py Outdated
Comment thread beetsplug/bpd/__init__.py
Comment on lines 869 to 873
err = BPDError(
ERROR_UNKNOWN, f"Got command while idle: {line}"
)
yield self.send(err.response())
await self.send(err.response())
break
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.90698% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.87%. Comparing base (74c2d98) to head (35579c4).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/bpd/__init__.py 77.90% 17 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6903      +/-   ##
==========================================
+ Coverage   75.69%   75.87%   +0.17%     
==========================================
  Files         163      162       -1     
  Lines       21412    21107     -305     
  Branches     3384     3336      -48     
==========================================
- Hits        16208    16015     -193     
+ Misses       4405     4309      -96     
+ Partials      799      783      -16     
Files with missing lines Coverage Δ
beetsplug/bpd/__init__.py 75.90% <77.90%> (+0.14%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@snejus
snejus force-pushed the refactor-bluelet branch from cf209d0 to d67a23d Compare August 4, 2026 00:34
snejus added 2 commits August 5, 2026 02:04
- Track active notification tasks by connection so repeated dispatches do not
  send duplicate idle responses while a previous send is still draining.
- Add regression coverage for serialized notification delivery and idle command
  disconnect handling.
@snejus
snejus force-pushed the refactor-bluelet branch from d67a23d to 35579c4 Compare August 5, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bpd bpd plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants