parse: parse target correctly for generated stages (#4961)

This commit is contained in:
Saugat Pachhai
2020-11-25 16:13:17 +05:45
committed by GitHub
parent c989b28eae
commit 1294450a46
2 changed files with 37 additions and 2 deletions
+12 -2
View File
@@ -409,14 +409,20 @@ def error_link(name):
return format_link(f"https://error.dvc.org/{name}")
def parse_target(target, default=None):
def parse_target(target: str, default: str = None):
from dvc.dvcfile import PIPELINE_FILE, PIPELINE_LOCK, is_valid_filename
from dvc.exceptions import DvcException
from dvc.parsing import JOIN
if not target:
return None, None
match = TARGET_REGEX.match(target)
# look for first "@", so as not to assume too much about stage name
# eg: it might contain ":" in a generated stages from dict which might
# affect further parsings with the regex.
group, _, key = target.partition(JOIN)
match = TARGET_REGEX.match(group)
if not match:
return target, None
@@ -424,6 +430,10 @@ def parse_target(target, default=None):
match.group("path"),
match.group("name"),
)
if name and key:
name += f"{JOIN}{key}"
if path:
if os.path.basename(path) == PIPELINE_LOCK:
raise DvcException(
+25
View File
@@ -149,6 +149,31 @@ def test_resolve_output(inp, out, is_dir, expected, mocker):
["something.dvc:name", ("something.dvc", "name"), None],
["../something.dvc:name", ("../something.dvc", "name"), None],
["file", (None, "file"), None],
["build@15", (None, "build@15"), None],
["build@{'level': 35}", (None, "build@{'level': 35}"), None],
[":build@15", ("dvc.yaml", "build@15"), None],
[":build@{'level': 35}", ("dvc.yaml", "build@{'level': 35}"), None],
["dvc.yaml:build@15", ("dvc.yaml", "build@15"), None],
[
"dvc.yaml:build@{'level': 35}",
("dvc.yaml", "build@{'level': 35}"),
None,
],
[
"build2@{'level': [1, 2, 3]}",
(None, "build2@{'level': [1, 2, 3]}"),
None,
],
[
":build2@{'level': [1, 2, 3]}",
("dvc.yaml", "build2@{'level': [1, 2, 3]}"),
None,
],
[
"dvc.yaml:build2@{'level': [1, 2, 3]}",
("dvc.yaml", "build2@{'level': [1, 2, 3]}"),
None,
],
],
)
def test_parse_target(inp, out, default):