refactor: de-duplicate bundled auto-editor binary sync in main.py (#7) - #5
Open
rsmxingu wants to merge 1 commit into
Open
refactor: de-duplicate bundled auto-editor binary sync in main.py (#7)#5rsmxingu wants to merge 1 commit into
rsmxingu wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thedownload_binarymonkeypatch. 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 itsPath(orNonewhen no bundled binary exists). Both call sites use it:_use_bundled_binary()raisesFileNotFoundErrorwhen it returnsNone.Behavior is unchanged.
Testing
python3 -m py_compile main.pypasses.python -m auto_editorre-entry block, which is guarded by the argv check and never executes during import or the unit tests, sotests/test_main.py(start/cancel/on_closing) is unaffected.tests/test_main.pyitself requirestkinter(viaimport ui), unavailable in my sandbox, so I could not execute it here. Please runpython3 -m unittest tests.test_mainin a tkinter environment to confirm.🤖 Generated with Claude Code