mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 23:11:44 +01:00
pipeline file: disallow punctuation characters in stage name (#3767)
except hyphen and underscore
This commit is contained in:
+3
-1
@@ -11,7 +11,9 @@ from .scm_context import scm_context
|
||||
|
||||
|
||||
def is_valid_name(name: str):
|
||||
return not {"\\", "/", "@", ":"} & set(name)
|
||||
from ..stage import INVALID_STAGENAME_CHARS
|
||||
|
||||
return not INVALID_STAGENAME_CHARS & set(name)
|
||||
|
||||
|
||||
def _get_file_path(kwargs):
|
||||
|
||||
@@ -2,6 +2,7 @@ import logging
|
||||
import os
|
||||
import pathlib
|
||||
import signal
|
||||
import string
|
||||
import subprocess
|
||||
import threading
|
||||
from itertools import chain, product
|
||||
@@ -29,6 +30,8 @@ from .exceptions import (
|
||||
from .params import OutputParams
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
# Disallow all punctuation characters except hyphen and underscore
|
||||
INVALID_STAGENAME_CHARS = set(string.punctuation) - {"_", "-"}
|
||||
|
||||
|
||||
def loads_from(cls, repo, path, wdir, data):
|
||||
|
||||
@@ -113,7 +113,4 @@ class DuplicateStageName(DvcException):
|
||||
|
||||
class InvalidStageName(DvcException):
|
||||
def __init__(self,):
|
||||
super().__init__(
|
||||
"Stage name cannot contain invalid characters: "
|
||||
"'\\', '/', '@' and ':'."
|
||||
)
|
||||
super().__init__("Stage name cannot contain punctuation characters.")
|
||||
|
||||
@@ -94,14 +94,14 @@ class TestReproCyclicGraph(SingleStageRun, TestDvc):
|
||||
deps=[self.FOO],
|
||||
outs=["bar.txt"],
|
||||
cmd="echo bar > bar.txt",
|
||||
name="copybarbar.txt",
|
||||
name="copybarbar-txt",
|
||||
)
|
||||
|
||||
self._run(
|
||||
deps=["bar.txt"],
|
||||
outs=["baz.txt"],
|
||||
cmd="echo baz > baz.txt",
|
||||
name="copybazbaz.txt",
|
||||
name="copybazbaz-txt",
|
||||
)
|
||||
|
||||
stage_dump = {
|
||||
@@ -657,7 +657,7 @@ class TestReproMetricsAddUnchanged(TestDvc):
|
||||
class TestReproPhony(TestReproChangedData):
|
||||
def test(self):
|
||||
stage = self._run(
|
||||
cmd="cat " + self.file1, deps=[self.file1], name="no_cmd?"
|
||||
cmd="cat " + self.file1, deps=[self.file1], name="no_cmd"
|
||||
)
|
||||
|
||||
self.swap_foo_with_bar()
|
||||
|
||||
@@ -160,10 +160,17 @@ def test_run_dump_on_multistage(tmp_dir, dvc):
|
||||
}
|
||||
|
||||
|
||||
def test_run_with_invalid_stage_name(tmp_dir, dvc, run_copy):
|
||||
tmp_dir.dvc_gen("foo", "foo")
|
||||
@pytest.mark.parametrize(
|
||||
"char", ["@:", "#", "$", ":", "/", "\\", ".", ";", ","]
|
||||
)
|
||||
def test_run_with_invalid_stage_name(run_copy, char):
|
||||
with pytest.raises(InvalidStageName):
|
||||
run_copy("foo", "bar", name="email@https://dvc.org")
|
||||
run_copy("foo", "bar", name="copy_name-{}".format(char))
|
||||
|
||||
|
||||
def test_run_with_name_having_hyphen_underscore(tmp_dir, dvc, run_copy):
|
||||
tmp_dir.dvc_gen("foo", "foo")
|
||||
run_copy("foo", "bar", name="copy-foo_bar")
|
||||
|
||||
|
||||
def test_run_already_exists(tmp_dir, dvc, run_copy):
|
||||
|
||||
Reference in New Issue
Block a user