diff --git a/dvc/repo/ls_url.py b/dvc/repo/ls_url.py index affc16266..bd8a186da 100644 --- a/dvc/repo/ls_url.py +++ b/dvc/repo/ls_url.py @@ -1,10 +1,39 @@ from dvc.exceptions import URLMissingError -from dvc.output import Output +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 ls_url(url): - out = Output(None, url) - fs, fs_path = out.fs, out.fs_path + fs, fs_path = get_external_fs(url) try: info = fs.info(fs_path)