mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
add: remove file (#9548)
* add: remove `file` Follow up to #9547. * Update add.py * fix tests
This commit is contained in:
+2
-9
@@ -51,9 +51,6 @@ def validate_args(targets: List[str], **kwargs: Any) -> None:
|
|||||||
invalid_opt = None
|
invalid_opt = None
|
||||||
to_remote = kwargs.get("to_remote")
|
to_remote = kwargs.get("to_remote")
|
||||||
|
|
||||||
if len(targets) > 1 and kwargs.get("file"):
|
|
||||||
raise InvalidArgumentError("cannot use '--file' with multiple targets")
|
|
||||||
|
|
||||||
if to_remote or kwargs.get("out"):
|
if to_remote or kwargs.get("out"):
|
||||||
message = "{option} can't be used with "
|
message = "{option} can't be used with "
|
||||||
message += "--to-remote" if to_remote else "-o"
|
message += "--to-remote" if to_remote else "-o"
|
||||||
@@ -83,7 +80,6 @@ PIPELINE_TRACKED_UPDATE_FMT = (
|
|||||||
def get_or_create_stage(
|
def get_or_create_stage(
|
||||||
repo: "Repo",
|
repo: "Repo",
|
||||||
target: str,
|
target: str,
|
||||||
file: Optional[str] = None,
|
|
||||||
external: bool = False,
|
external: bool = False,
|
||||||
out: Optional[str] = None,
|
out: Optional[str] = None,
|
||||||
to_remote: bool = False,
|
to_remote: bool = False,
|
||||||
@@ -106,7 +102,7 @@ def get_or_create_stage(
|
|||||||
stage = repo.stage.create(
|
stage = repo.stage.create(
|
||||||
single_stage=True,
|
single_stage=True,
|
||||||
validate=False,
|
validate=False,
|
||||||
fname=file or path,
|
fname=path,
|
||||||
wdir=wdir,
|
wdir=wdir,
|
||||||
outs=[out],
|
outs=[out],
|
||||||
external=external,
|
external=external,
|
||||||
@@ -225,11 +221,10 @@ def _add(stage: "Stage", source: Optional[str] = None, no_commit: bool = False)
|
|||||||
|
|
||||||
@locked
|
@locked
|
||||||
@scm_context
|
@scm_context
|
||||||
def add( # noqa: PLR0913
|
def add(
|
||||||
repo: "Repo",
|
repo: "Repo",
|
||||||
targets: Union["StrOrBytesPath", Iterator["StrOrBytesPath"]],
|
targets: Union["StrOrBytesPath", Iterator["StrOrBytesPath"]],
|
||||||
no_commit: bool = False,
|
no_commit: bool = False,
|
||||||
file: Optional[str] = None,
|
|
||||||
external: bool = False,
|
external: bool = False,
|
||||||
glob: bool = False,
|
glob: bool = False,
|
||||||
out: Optional[str] = None,
|
out: Optional[str] = None,
|
||||||
@@ -245,7 +240,6 @@ def add( # noqa: PLR0913
|
|||||||
validate_args(
|
validate_args(
|
||||||
add_targets,
|
add_targets,
|
||||||
no_commit=no_commit,
|
no_commit=no_commit,
|
||||||
file=file,
|
|
||||||
external=external,
|
external=external,
|
||||||
out=out,
|
out=out,
|
||||||
remote=remote,
|
remote=remote,
|
||||||
@@ -256,7 +250,6 @@ def add( # noqa: PLR0913
|
|||||||
target: get_or_create_stage(
|
target: get_or_create_stage(
|
||||||
repo,
|
repo,
|
||||||
target,
|
target,
|
||||||
file=file,
|
|
||||||
external=external,
|
external=external,
|
||||||
out=out,
|
out=out,
|
||||||
to_remote=to_remote,
|
to_remote=to_remote,
|
||||||
|
|||||||
@@ -645,10 +645,10 @@ def test_add_from_data_dir(tmp_dir, scm, dvc):
|
|||||||
def test_add_parent_dir(tmp_dir, scm, dvc):
|
def test_add_parent_dir(tmp_dir, scm, dvc):
|
||||||
tmp_dir.gen({"dir": {"file1": "file1 content"}})
|
tmp_dir.gen({"dir": {"file1": "file1 content"}})
|
||||||
out_path = os.path.join("dir", "file1")
|
out_path = os.path.join("dir", "file1")
|
||||||
dvc.add(out_path, file=out_path + ".dvc")
|
dvc.add(out_path)
|
||||||
|
|
||||||
with pytest.raises(OverlappingOutputPathsError) as e:
|
with pytest.raises(OverlappingOutputPathsError) as e:
|
||||||
dvc.add("dir", file="dir.dvc")
|
dvc.add("dir")
|
||||||
assert str(e.value) == (
|
assert str(e.value) == (
|
||||||
"Cannot add 'dir', because it is overlapping with other DVC "
|
"Cannot add 'dir', because it is overlapping with other DVC "
|
||||||
"tracked output: '{out}'.\n"
|
"tracked output: '{out}'.\n"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -138,10 +139,10 @@ def test_move_should_save_stage_info(tmp_dir, dvc):
|
|||||||
|
|
||||||
|
|
||||||
def test_should_move_to_dir_on_non_default_stage_file(tmp_dir, dvc):
|
def test_should_move_to_dir_on_non_default_stage_file(tmp_dir, dvc):
|
||||||
stage_file_name = "stage.dvc"
|
|
||||||
tmp_dir.gen({"file": "file_content"})
|
tmp_dir.gen({"file": "file_content"})
|
||||||
|
|
||||||
dvc.add("file", file=stage_file_name)
|
dvc.add("file")
|
||||||
|
shutil.move("file.dvc", "stage.dvc")
|
||||||
os.mkdir("directory")
|
os.mkdir("directory")
|
||||||
|
|
||||||
dvc.move("file", "directory")
|
dvc.move("file", "directory")
|
||||||
|
|||||||
Reference in New Issue
Block a user