-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
repofs: use underlying fs.download to download files #6401
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,9 +62,7 @@ def _get_granular_hash( | |
return obj.hash_info | ||
raise FileNotFoundError | ||
|
||
def open( # type: ignore | ||
self, path: PathInfo, mode="r", encoding=None, remote=None, **kwargs | ||
): # pylint: disable=arguments-differ | ||
def _get_fs_path(self, path: PathInfo, remote=None): | ||
try: | ||
outs = self._find_outs(path, strict=False) | ||
except OutputNotFoundError as exc: | ||
|
@@ -92,16 +90,20 @@ def open( # type: ignore | |
else: | ||
checksum = out.hash_info.value | ||
remote_info = remote_odb.hash_to_path_info(checksum) | ||
return remote_odb.fs.open( | ||
remote_info, mode=mode, encoding=encoding | ||
) | ||
return remote_odb.fs, remote_info | ||
|
||
if out.is_dir_checksum: | ||
checksum = self._get_granular_hash(path, out).value | ||
cache_path = out.odb.hash_to_path_info(checksum).url | ||
else: | ||
cache_path = out.cache_path | ||
return open(cache_path, mode=mode, encoding=encoding) | ||
return out.odb.fs, cache_path | ||
|
||
def open( # type: ignore | ||
self, path: PathInfo, mode="r", encoding=None, **kwargs | ||
): # pylint: disable=arguments-renamed | ||
fs, fspath = self._get_fs_path(path, **kwargs) | ||
return fs.open(fspath, mode=mode, encoding=encoding) | ||
|
||
def exists(self, path): # pylint: disable=arguments-renamed | ||
try: | ||
|
@@ -253,3 +255,9 @@ def info(self, path_info): | |
ret[obj.hash_info.name] = obj.hash_info.value | ||
|
||
return ret | ||
|
||
def _download(self, from_info, to_file, **kwargs): | ||
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. For the record: this is a bit ugly, but it will turn into a cleaner and more proper |
||
fs, path = self._get_fs_path(from_info) | ||
fs._download( # pylint: disable=protected-access | ||
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. This again is temporary, it will be replaced by just |
||
path, to_file, **kwargs | ||
) |
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 didn't handle chained imports before and neither does it handle them now. We'll need to generalize resolving logic we use in dvc/dependency/repo.py to use it here. Will prob look into it in a followup.