-
Notifications
You must be signed in to change notification settings - Fork 443
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
Add file datatype type to support saving and reading files/folders in artifact_store #1805
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d3f6c35
Add file datatype type to support saving and reading files/folders in…
jieguangzhou e78ebfd
Optimize the path structure of file saving
jieguangzhou 0c6d5da
Added ReferenceEncodable to support better handling of files/folders
jieguangzhou 9066a90
Support lazy Encodable
jieguangzhou 8708513
Add integration test for mongodb saving files and folders
jieguangzhou 61ced9a
Generating random file_id for saving file to artifact store
jieguangzhou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import os | ||
import shutil | ||
import typing as t | ||
from pathlib import Path | ||
|
||
import click | ||
|
||
|
@@ -69,6 +70,29 @@ def _load_bytes(self, file_id: str) -> bytes: | |
with open(os.path.join(self.conn, file_id), 'rb') as f: | ||
return f.read() | ||
|
||
def _save_file(self, file_path: str, file_id: str): | ||
""" | ||
Save file in artifact store and return the relative path | ||
return the relative path {file_id}/{name} | ||
""" | ||
path = Path(file_path) | ||
name = path.name | ||
file_id_folder = os.path.join(self.conn, file_id) | ||
os.makedirs(file_id_folder, exist_ok=True) | ||
save_path = os.path.join(file_id_folder, name) | ||
logging.info(f"Copying file {file_path} to {save_path}") | ||
if path.is_dir(): | ||
shutil.copytree(file_path, save_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jieguangzhou @blythed |
||
else: | ||
shutil.copy(file_path, save_path) | ||
# return the relative path {file_id}/{name} | ||
return os.path.join(file_id, name) | ||
|
||
def _load_file(self, file_id: str) -> str: | ||
"""Return the path to the file in the artifact store""" | ||
logging.info(f"Loading file {file_id} from {self.conn}") | ||
return os.path.join(self.conn, file_id) | ||
|
||
def disconnect(self): | ||
""" | ||
Disconnect the client | ||
|
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
@jieguangzhou if there is a partially copy and program crashes may be a rollback?
possibly in future if not in this pr.
Ignore if already happens in shut.copy*
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.
Yes, we need to do this in future, not only filesystem, all the artifact store need to support this
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 should be handled in
db.add
. We need to be able to roll back the wholeadd
process.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.
Not an easy task.