Skip to content

refactor: de-duplicate bundled auto-editor binary sync in main.py (#7) - #5

Open
rsmxingu wants to merge 1 commit into
rsd:masterfrom
rsmxingu:refactor/main-dedup-bundled-binary
Open

refactor: de-duplicate bundled auto-editor binary sync in main.py (#7)#5
rsmxingu wants to merge 1 commit into
rsd:masterfrom
rsmxingu:refactor/main-dedup-bundled-binary

Conversation

@rsmxingu

Copy link
Copy Markdown

Problem

In the frozen-bundle re-entry path (python -m auto_editor), the "copy bundled binary into the writable cache" logic — exists check, makedirs, stale-size check, copy2, chmod — was written twice: once to pre-populate the cache, and again inside the download_binary monkeypatch. The two copies could drift independently.

Change

Extract a single _sync_bundled_binary() helper that copies the binary when the target is missing/stale and returns its Path (or None when no bundled binary exists). Both call sites use it:

  • pre-population calls it best-effort (errors still swallowed — the monkeypatch is the real fallback);
  • _use_bundled_binary() raises FileNotFoundError when it returns None.

Behavior is unchanged.

Testing

  • python3 -m py_compile main.py passes.
  • This only touches the python -m auto_editor re-entry block, which is guarded by the argv check and never executes during import or the unit tests, so tests/test_main.py (start/cancel/on_closing) is unaffected.
  • tests/test_main.py itself requires tkinter (via import ui), unavailable in my sandbox, so I could not execute it here. Please run python3 -m unittest tests.test_main in a tkinter environment to confirm.

🤖 Generated with Claude Code

In the frozen-bundle re-entry path, the copy-into-writable-cache logic
(exists check, makedirs, stale-size check, copy2, chmod) was written twice:
once to pre-populate the cache and again inside the download_binary
monkeypatch. The two copies could drift independently.

Extract a single _sync_bundled_binary() helper that performs the copy when the
target is missing/stale and returns its Path (or None when no bundled binary
exists). Both call sites now use it:
- pre-population calls it best-effort (errors still swallowed, since the
  monkeypatch is the real fallback);
- _use_bundled_binary() raises FileNotFoundError when it returns None.

Behavior is unchanged. This only touches the `python -m auto_editor` re-entry
block, which never executes during import or the unit tests (it's guarded by the
argv check), so tests/test_main.py is unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant