Move exception raising to glob_targets to cover all commands.

This commit is contained in:
Karthikeyan Singaravelan
2022-05-11 18:37:09 +03:00
committed by Ruslan Kuprieiev
parent e177f041c8
commit 9b3873c4f0
4 changed files with 15 additions and 13 deletions
-4
View File
@@ -1,7 +1,6 @@
import logging
from typing import TYPE_CHECKING, Optional
from dvc.exceptions import GlobDoesNotMatchError
from dvc.repo import locked
from dvc.utils import glob_targets
@@ -32,9 +31,6 @@ def pull(
expanded_targets = glob_targets(targets, glob=glob)
if targets and not expanded_targets:
raise GlobDoesNotMatchError(targets)
processed_files_count = self.fetch(
expanded_targets,
jobs,
+1 -8
View File
@@ -1,10 +1,6 @@
from typing import TYPE_CHECKING, Optional
from dvc.exceptions import (
FileTransferError,
GlobDoesNotMatchError,
UploadError,
)
from dvc.exceptions import FileTransferError, UploadError
from ..utils import glob_targets
from . import locked
@@ -39,9 +35,6 @@ def push(
expanded_targets = glob_targets(targets, glob=glob)
if targets and not expanded_targets:
raise GlobDoesNotMatchError(targets)
used = self.used_objs(
expanded_targets,
all_branches=all_branches,
+8 -1
View File
@@ -476,17 +476,24 @@ def is_exec(mode):
def glob_targets(targets, glob=True, recursive=True):
from dvc.exceptions import GlobDoesNotMatchError
if not glob:
return targets
from glob import iglob
return [
results = [
exp_target
for target in targets
for exp_target in iglob(target, recursive=recursive)
]
if not results:
raise GlobDoesNotMatchError(targets)
return results
def error_handler(func):
def wrapper(*args, **kwargs):
+6
View File
@@ -16,6 +16,7 @@ from dvc.data.db import ODBManager
from dvc.dvcfile import DVC_FILE_SUFFIX
from dvc.exceptions import (
DvcException,
GlobDoesNotMatchError,
InvalidArgumentError,
OutputDuplicationError,
OverlappingOutputPathsError,
@@ -292,6 +293,11 @@ def test_add_filtered_files_in_dir(
assert stage.outs[0].def_path in expected_def_paths
def test_add_glob_no_result_exception(dvc):
with pytest.raises(GlobDoesNotMatchError):
dvc.add(["invalid*"], glob=True)
class TestAddExternal(TestAdd):
@pytest.fixture
def hash_name(self):