-
Notifications
You must be signed in to change notification settings - Fork 38
Add as_posix to s3 push file paths in deployment step #314
Conversation
@desertaxle you were an active maintainer, so I'm pinging you to see if I can get this PR looked at? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works for Windows now but is failing when run on Linux. I made a suggestion that should fix the behavior on both platforms.
@@ -117,7 +117,9 @@ def push_to_s3( | |||
continue | |||
elif not local_file_path.is_dir(): | |||
remote_file_path = Path(folder) / local_file_path.relative_to(local_path) | |||
client.upload_file(str(local_file_path), bucket, str(remote_file_path)) | |||
client.upload_file( | |||
str(local_file_path), bucket, str(remote_file_path.as_posix()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trick can help ensure it works on Windows and Linux platforms.
str(local_file_path), bucket, str(remote_file_path.as_posix()) | |
str(local_file_path), bucket, str(PureWindowsPath(remote_file_path.as_posix())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@desertaxle I think it's a problem in the test, not in the code.
I ran the following code on both windows and linux:
from pathlib import Path
folder = 'arbitrary/s3/folder/'
local_path = Path.cwd()
for local_file_path in local_path.expanduser().rglob("*"):
if not local_file_path.is_dir():
remote_file_path = Path(folder) / local_file_path.relative_to(local_path)
print(f"not_posix: {str(remote_file_path)}")
print(f"yes_posix: {str(remote_file_path.as_posix())}")
Windows yielded:
not_posix: arbitrary\s3\folder\top.txt
yes_posix: arbitrary/s3/folder/top.txt
not_posix: arbitrary\s3\folder\dir1\sub.txt
yes_posix: arbitrary/s3/folder/dir1/sub.txt
Linux yielded:
not_posix: arbitrary/s3/folder/top.txt
yes_posix: arbitrary/s3/folder/top.txt
not_posix: arbitrary/s3/folder/dir1/sub.txt
yes_posix: arbitrary/s3/folder/dir1/sub.txt
So I think that the code that I wrote will not break based on OS, but I might need to make the mock of the returned files more accurate. Thoughts? Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the issue might be in the tmp_file_win
fixture. On Linux it's likely escaping the \
to create a valid posix path. I'd recommend updating test_push_tos3_as_posix
to only run on Windows. You can do that like this: @pytest.mark.skipif(sys.platform != 'win32', reason="requires Windows")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@desertaxle done and done
Add as_posix test Completed tests
@desertaxle anything left before this can be merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Add as_posix test
Completed tests
Closes #309
Example
Now handles windows pathing appropriately as posix paths when writing to S3
Screenshots
N/A, only affects existing processing
Checklist
pre-commit
checks.pre-commit install && pre-commit run --all
locally for formatting and linting.mkdocs serve
view documentation locally.