fix: add Windows support with entry_points and os.replace#466
Merged
josegonzalez merged 1 commit intojosegonzalez:masterfrom Dec 11, 2025
Merged
fix: add Windows support with entry_points and os.replace#466josegonzalez merged 1 commit intojosegonzalez:masterfrom
josegonzalez merged 1 commit intojosegonzalez:masterfrom
Conversation
- Replace os.rename() with os.replace() for atomic file operations on Windows (os.rename fails if destination exists on Windows) - Add entry_points console_scripts for proper .exe generation on Windows - Create github_backup/cli.py with main() entry point - Add github_backup/__main__.py for python -m github_backup support - Keep bin/github-backup as thin wrapper for backwards compatibility Closes josegonzalez#112
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.
Windows users have reported "'github-backup' is not recognized as an internal or external command" since the project uses
scripts=in setup.py. This approach doesn't work reliably on Windows because it depends on shebang handling which Windows doesn't support natively.The standard solution is
entry_pointswithconsole_scripts, which generates proper .exe wrappers on Windows. This is the approach recommended by the Python Packaging Authority and used by most modern Python CLI tools.However,
entry_pointsrequires the CLI entry point to be a function inside an installed package - it can't point to a standalone script. This is why the PR restructures the CLI code:github_backup/cli.py: the main() function and logging setup moved here from bin/github-backupgithub_backup/__main__.py: enablespython -m github_backup(standard Python convention)bin/github-backup: reduced to a thin wrapper for backwards compatibility with existing users who call it directlyFor existing users, nothing changes
github-backupworks exactly as before afterpip install.While making this change, I also fixed a related Windows issue:
os.rename()fails on Windows if the destination file already exists, causing errors during incremental backups. The fix isos.replace()which handles this atomically on all platforms. Theos.replace()calls were also moved outsidewith open()blocks to ensure file handles are closed before the atomic rename, as Windows locks open files and the rename fails otherwise.Tested on Windows 11 (PowerShell) and macOS:
pip install -e .followed bygithub-backup --helpworkspython -m github_backup --helpworks--labels --issuescompletes successfullyCloses #112