Fix copy() command: Use SCP fallback on Windows and conditionally apply sudo for rsync #3
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.
This pull request addresses a Windows compatibility issue in the copy() function. I encountered errors on Windows due to the absence of rsync (which is typically not installed by default), while Windows usually has scp available. To resolve this, the function now:
Checks the platform and rsync availability:
Uses Python’s platform module and shutil.which() to detect if the script is running on Windows or if rsync is missing.
Applies a fallback mechanism:
If running on Windows or if rsync is not available, the function builds and executes an scp command for file transfers.
Conditional use of sudo:
On non-Windows systems, the command prepends sudo (via a sudo_prefix variable) to the rsync command to ensure proper permissions. On Windows, sudo is skipped.
Inline comments for clarity:
Added comments throughout the function to explain these changes.
These modifications ensure that the file copy operations work correctly across both Windows and Unix-like systems. This change fixes the issue I faced on Windows by using a more suitable tool (scp) when rsync is not available while preserving the existing functionality on other platforms.