From b01c4f8b052b4f4da9476ae00cb5bc1bbcdf4f0f Mon Sep 17 00:00:00 2001 From: Ronan Lamy Date: Wed, 21 Sep 2022 13:09:36 +0100 Subject: [PATCH] ls-url: call get_cloud_fs() directly Note: removes a spurious check on whether the target is a dvc file. --- dvc/repo/ls_url.py | 35 +++++------------------------------ tests/func/test_ls_url.py | 2 +- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/dvc/repo/ls_url.py b/dvc/repo/ls_url.py index bd8a186da..cf8263465 100644 --- a/dvc/repo/ls_url.py +++ b/dvc/repo/ls_url.py @@ -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: diff --git a/tests/func/test_ls_url.py b/tests/func/test_ls_url.py index 9340611ce..94fb777fe 100644 --- a/tests/func/test_ls_url.py +++ b/tests/func/test_ls_url.py @@ -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"})