Skip to content

Conversation

@Iamrodos
Copy link
Contributor

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_points with console_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_points requires 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-backup
  • github_backup/__main__.py: enables python -m github_backup (standard Python convention)
  • bin/github-backup: reduced to a thin wrapper for backwards compatibility with existing users who call it directly

For existing users, nothing changes github-backup works exactly as before after pip 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 is os.replace() which handles this atomically on all platforms. The os.replace() calls were also moved outside with 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 by github-backup --help works
  • python -m github_backup --help works
  • Full backup with --labels --issues completes successfully
  • Incremental backup (re-running same command) works without FileExistsError
  • All 36 pytest tests pass on both platforms

Closes #112

- 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
@josegonzalez josegonzalez merged commit 3f1ef82 into josegonzalez:master Dec 11, 2025
10 checks passed
@Iamrodos Iamrodos deleted the fix/112-windows-support branch December 17, 2025 01:56
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.

'github-backup' is not recognized as an internal or external command, operable program or batch file.

2 participants