Skip to content
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

Fail on sync when there is no match for glob. #7687

Merged
merged 6 commits into from May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion dvc/utils/__init__.py
Expand Up @@ -476,17 +476,25 @@ def is_exec(mode):


def glob_targets(targets, glob=True, recursive=True):
from ..exceptions import DvcException

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:
msg = f"Glob {targets} has no matches."
raise DvcException(msg)

return results


def error_handler(func):
def wrapper(*args, **kwargs):
Expand Down
12 changes: 12 additions & 0 deletions tests/func/test_utils.py
@@ -1,4 +1,9 @@
import re

import pytest

from dvc import utils
from dvc.exceptions import DvcException
from dvc.fs.local import LocalFileSystem


Expand Down Expand Up @@ -42,3 +47,10 @@ def test_boxify():
)

assert expected == utils.boxify("message")


def test_glob_no_match():
with pytest.raises(
DvcException, match=re.escape("Glob ['invalid*'] has no matches.")
):
utils.glob_targets(["invalid*"], glob=True)