Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write to docker as tar file #56

Merged
merged 2 commits into from
Jul 19, 2024
Merged

write to docker as tar file #56

merged 2 commits into from
Jul 19, 2024

Conversation

granawkins
Copy link
Member

No description provided.

Copy link

@mentatai mentatai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this pull request improve the file writing mechanism in Docker by using a tar archive instead of directly writing to the container. This approach is more robust and efficient. The version bump in pyproject.toml and init.py is appropriate for this feature update. Overall, the changes look good, but there are a few minor suggestions for error handling and code cleanup.

Thanks for using MentatBot. Give comments a 👍 or 👎 to help me improve!

raise IOError(
f"Failed to write file {self.path} in container: {result.stderr.decode('utf-8')}"
)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error handling for the case where the temporary file creation fails.

tar_stream.seek(0)

# Put the archive into the container
self.container.put_archive(os.path.dirname(self.path), tar_stream)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to add error handling here in case the put_archive operation fails.

self.container.put_archive(os.path.dirname(self.path), tar_stream)

# Clean up the temporary file
os.remove(temp_file_path)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a context manager (like with tempfile.NamedTemporaryFile() as temp_file:) to ensure the temporary file is always deleted, even if an exception occurs.

@@ -153,3 +171,10 @@ def rename(self, src: Path | str, dst: Path | str):
def exists(self, path: Path | str) -> bool:
result = self.container.exec_run(f"test -e {self.cwd / path}")
return result.exit_code == 0


"""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commented-out code block at the end of the file seems unnecessary. Consider removing it if it's not needed.

@granawkins granawkins merged commit 039ed52 into main Jul 19, 2024
3 checks passed
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.

1 participant