ls-url: call get_cloud_fs() directly

Note: removes a spurious check on whether the target is a dvc file.
This commit is contained in:
Ronan Lamy
2022-10-04 14:37:29 +03:00
committed by Ruslan Kuprieiev
parent c27125d9c0
commit b01c4f8b05
2 changed files with 6 additions and 31 deletions
+5 -30
View File
@@ -1,40 +1,15 @@
from dvc.exceptions import URLMissingError
from dvc.fs import get_cloud_fs
from dvc.output import OutputIsStageFileError
class Output:
def __init__(
self,
path,
fs_config=None,
):
fs_config = fs_config or {}
fs_cls, _fs_config, fs_path = get_cloud_fs(None, url=path, **fs_config)
self.fs = fs_cls(**_fs_config)
_validate_output_path(path)
self.fs_path = _parse_path(self.fs, fs_path)
def _parse_path(fs, fs_path):
return fs.path.abspath(fs.path.normpath(fs_path))
def _validate_output_path(path):
from dvc.dvcfile import is_valid_filename
if is_valid_filename(path):
raise OutputIsStageFileError(path)
def get_external_fs(url, fs_config=None):
out = Output(url, fs_config)
return out.fs, out.fs_path
def parse_external_url(url):
fs_cls, fs_config, fs_path = get_cloud_fs(None, url=url)
fs = fs_cls(**fs_config)
return fs, fs.path.abspath(fs.path.normpath(fs_path))
def ls_url(url):
fs, fs_path = get_external_fs(url)
fs, fs_path = parse_external_url(url)
try:
info = fs.info(fs_path)
except FileNotFoundError:
+1 -1
View File
@@ -12,7 +12,7 @@ def match_files(entries, expected):
assert entries_content == expected_content
@pytest.mark.parametrize("fname", ["foo", "dir/foo"])
@pytest.mark.parametrize("fname", ["foo", "foo.dvc", "dir/foo"])
def test_file(tmp_dir, fname):
tmp_dir.gen({fname: "foo contents"})