mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
dvc : renamed --outs-only to --dvc-only (#3797)
* Renamed --outs-only to --dvc-only * Changed outs_only to dvc_only * replace output_only with dvc_only * Restyled by black Co-authored-by: Restyled.io <[email protected]>
This commit is contained in:
co-authored by
Restyled.io
parent
184028f176
commit
19eaced304
@@ -31,7 +31,7 @@ class CmdList(CmdBaseNoRepo):
|
||||
self.args.path,
|
||||
rev=self.args.rev,
|
||||
recursive=self.args.recursive,
|
||||
outs_only=self.args.outs_only,
|
||||
dvc_only=self.args.dvc_only,
|
||||
)
|
||||
if entries:
|
||||
entries = _prettify(entries, sys.stdout.isatty())
|
||||
@@ -62,7 +62,7 @@ def add_parser(subparsers, parent_parser):
|
||||
help="Recursively list files.",
|
||||
)
|
||||
list_parser.add_argument(
|
||||
"--outs-only", action="store_true", help="Show only DVC outputs."
|
||||
"--dvc-only", action="store_true", help="Show only DVC outputs."
|
||||
)
|
||||
list_parser.add_argument(
|
||||
"--rev",
|
||||
|
||||
@@ -9,7 +9,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CmdRemove(CmdBase):
|
||||
def _is_outs_only(self, target):
|
||||
def _is_dvc_only(self, target):
|
||||
if not self.args.purge:
|
||||
return True
|
||||
|
||||
@@ -31,8 +31,8 @@ class CmdRemove(CmdBase):
|
||||
def run(self):
|
||||
for target in self.args.targets:
|
||||
try:
|
||||
outs_only = self._is_outs_only(target)
|
||||
self.repo.remove(target, outs_only=outs_only)
|
||||
dvc_only = self._is_dvc_only(target)
|
||||
self.repo.remove(target, dvc_only=dvc_only)
|
||||
except DvcException:
|
||||
logger.exception(f"failed to remove '{target}'")
|
||||
return 1
|
||||
|
||||
+4
-8
@@ -294,19 +294,15 @@ class PathMissingError(DvcException):
|
||||
"The path '{}' does not exist in the target repository '{}'"
|
||||
" neither as a DVC output nor as a Git-tracked file."
|
||||
)
|
||||
default_msg_output_only = (
|
||||
default_msg_dvc_only = (
|
||||
"The path '{}' does not exist in the target repository '{}'"
|
||||
" as an DVC output."
|
||||
)
|
||||
|
||||
def __init__(self, path, repo, output_only=False):
|
||||
msg = (
|
||||
self.default_msg
|
||||
if not output_only
|
||||
else self.default_msg_output_only
|
||||
)
|
||||
def __init__(self, path, repo, dvc_only=False):
|
||||
msg = self.default_msg if not dvc_only else self.default_msg_dvc_only
|
||||
super().__init__(msg.format(path, repo))
|
||||
self.output_only = output_only
|
||||
self.dvc_only = dvc_only
|
||||
|
||||
|
||||
class RemoteCacheRequiredError(DvcException):
|
||||
|
||||
+4
-4
@@ -4,7 +4,7 @@ from dvc.path_info import PathInfo
|
||||
|
||||
@staticmethod
|
||||
def ls(
|
||||
url, path=None, rev=None, recursive=None, outs_only=False,
|
||||
url, path=None, rev=None, recursive=None, dvc_only=False,
|
||||
):
|
||||
"""Methods for getting files and outputs for the repo.
|
||||
|
||||
@@ -13,7 +13,7 @@ def ls(
|
||||
path (str, optional): relative path into the repo
|
||||
rev (str, optional): SHA commit, branch or tag name
|
||||
recursive (bool, optional): recursively walk the repo
|
||||
outs_only (bool, optional): show only DVC-artifacts
|
||||
dvc_only (bool, optional): show only DVC-artifacts
|
||||
|
||||
Returns:
|
||||
list of `entry`
|
||||
@@ -40,13 +40,13 @@ def ls(
|
||||
ret = _ls(repo, path_info, recursive, True)
|
||||
|
||||
nondvc = {}
|
||||
if not outs_only:
|
||||
if not dvc_only:
|
||||
nondvc = _ls(repo, path_info, recursive, False)
|
||||
|
||||
ret.update(nondvc)
|
||||
|
||||
if path and not ret:
|
||||
raise PathMissingError(path, repo, output_only=outs_only)
|
||||
raise PathMissingError(path, repo, dvc_only=dvc_only)
|
||||
|
||||
ret_list = []
|
||||
for path, info in ret.items():
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@locked
|
||||
def remove(self, target, outs_only=False):
|
||||
def remove(self, target, dvc_only=False):
|
||||
from ..dvcfile import Dvcfile
|
||||
|
||||
path, name = parse_target(target)
|
||||
@@ -16,7 +16,7 @@ def remove(self, target, outs_only=False):
|
||||
for stage in stages:
|
||||
stage.remove_outs(force=True)
|
||||
|
||||
if not outs_only:
|
||||
if not dvc_only:
|
||||
dvcfile.remove()
|
||||
|
||||
return stages
|
||||
|
||||
@@ -31,7 +31,7 @@ _dvc_import='-o --out --rev'
|
||||
_dvc_import_url='-f --file'
|
||||
_dvc_init='--no-scm -f --force'
|
||||
_dvc_install=''
|
||||
_dvc_list='-R --recursive --outs-only --rev'
|
||||
_dvc_list='-R --recursive --dvc-only --rev'
|
||||
_dvc_list_COMPGEN=_dvc_compgen_files
|
||||
_dvc_lock=''
|
||||
_dvc_lock_COMPGEN=_dvc_compgen_DVCFiles
|
||||
|
||||
@@ -170,7 +170,7 @@ _dvc_lock=(
|
||||
_dvc_list=(
|
||||
"--rev[Git revision (e.g. branch, tag, SHA)]:Revision:"
|
||||
{-R,--recursive}"[Recursively add each file under the directory.]"
|
||||
"--outs-only[Only outputs DVC-outs.]"
|
||||
"--dvc-only[Only outputs DVC-outs.]"
|
||||
"1:URL:"
|
||||
"2:Path:"
|
||||
)
|
||||
|
||||
@@ -68,7 +68,7 @@ class TestGCBranchesTags(TestDvcGit):
|
||||
self.dvc.scm.tag("v1.0")
|
||||
|
||||
self.dvc.scm.checkout("test", create_new=True)
|
||||
self.dvc.remove(stages[0].relpath, outs_only=True)
|
||||
self.dvc.remove(stages[0].relpath, dvc_only=True)
|
||||
with open(fname, "w+") as fobj:
|
||||
fobj.write("test")
|
||||
stages = self.dvc.add(fname)
|
||||
@@ -77,7 +77,7 @@ class TestGCBranchesTags(TestDvcGit):
|
||||
self.dvc.scm.commit("test")
|
||||
|
||||
self.dvc.scm.checkout("master")
|
||||
self.dvc.remove(stages[0].relpath, outs_only=True)
|
||||
self.dvc.remove(stages[0].relpath, dvc_only=True)
|
||||
with open(fname, "w+") as fobj:
|
||||
fobj.write("trash")
|
||||
stages = self.dvc.add(fname)
|
||||
@@ -85,7 +85,7 @@ class TestGCBranchesTags(TestDvcGit):
|
||||
self.dvc.scm.add([".gitignore", stages[0].relpath])
|
||||
self.dvc.scm.commit("trash")
|
||||
|
||||
self.dvc.remove(stages[0].relpath, outs_only=True)
|
||||
self.dvc.remove(stages[0].relpath, dvc_only=True)
|
||||
with open(fname, "w+") as fobj:
|
||||
fobj.write("master")
|
||||
stages = self.dvc.add(fname)
|
||||
|
||||
+13
-13
@@ -123,11 +123,11 @@ def test_ls_repo_recursive(tmp_dir, dvc, scm):
|
||||
)
|
||||
|
||||
|
||||
def test_ls_repo_outs_only_recursive(tmp_dir, dvc, scm):
|
||||
def test_ls_repo_dvc_only_recursive(tmp_dir, dvc, scm):
|
||||
tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
files = Repo.ls(os.fspath(tmp_dir), recursive=True, outs_only=True)
|
||||
files = Repo.ls(os.fspath(tmp_dir), recursive=True, dvc_only=True)
|
||||
match_files(
|
||||
files,
|
||||
(
|
||||
@@ -156,13 +156,13 @@ def test_ls_repo_with_path_dir(tmp_dir, dvc, scm):
|
||||
)
|
||||
|
||||
|
||||
def test_ls_repo_with_path_dir_outs_only_empty(tmp_dir, dvc, scm):
|
||||
def test_ls_repo_with_path_dir_dvc_only_empty(tmp_dir, dvc, scm):
|
||||
tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
tmp_dir.scm_gen({"folder/.keep": "content"}, commit="add .keep")
|
||||
|
||||
with pytest.raises(PathMissingError):
|
||||
Repo.ls(os.fspath(tmp_dir), path="folder", outs_only=True)
|
||||
Repo.ls(os.fspath(tmp_dir), path="folder", dvc_only=True)
|
||||
|
||||
|
||||
def test_ls_repo_with_path_subdir(tmp_dir, dvc, scm):
|
||||
@@ -182,21 +182,21 @@ def test_ls_repo_with_path_subdir(tmp_dir, dvc, scm):
|
||||
)
|
||||
|
||||
|
||||
def test_ls_repo_with_path_subdir_outs_only(tmp_dir, dvc, scm):
|
||||
def test_ls_repo_with_path_subdir_dvc_only(tmp_dir, dvc, scm):
|
||||
tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
path = os.path.join("data", "subcontent")
|
||||
files = Repo.ls(os.fspath(tmp_dir), path, outs_only=True)
|
||||
files = Repo.ls(os.fspath(tmp_dir), path, dvc_only=True)
|
||||
match_files(files, ((("data.xml",), True), (("statistics",), False),))
|
||||
|
||||
|
||||
def test_ls_repo_with_path_subdir_outs_only_recursive(tmp_dir, dvc, scm):
|
||||
def test_ls_repo_with_path_subdir_dvc_only_recursive(tmp_dir, dvc, scm):
|
||||
tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
path = os.path.join("data", "subcontent")
|
||||
files = Repo.ls(os.fspath(tmp_dir), path, outs_only=True, recursive=True)
|
||||
files = Repo.ls(os.fspath(tmp_dir), path, dvc_only=True, recursive=True)
|
||||
match_files(
|
||||
files, ((("data.xml",), True), (("statistics", "data.csv"), True),)
|
||||
)
|
||||
@@ -226,10 +226,10 @@ def test_ls_repo_with_missed_path(tmp_dir, dvc, scm):
|
||||
|
||||
with pytest.raises(PathMissingError) as exc_info:
|
||||
Repo.ls(os.fspath(tmp_dir), path="missed_path")
|
||||
assert not exc_info.value.output_only
|
||||
assert not exc_info.value.dvc_only
|
||||
|
||||
|
||||
def test_ls_repo_with_missed_path_outs_only(tmp_dir, dvc, scm):
|
||||
def test_ls_repo_with_missed_path_dvc_only(tmp_dir, dvc, scm):
|
||||
tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
|
||||
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
|
||||
|
||||
@@ -238,9 +238,9 @@ def test_ls_repo_with_missed_path_outs_only(tmp_dir, dvc, scm):
|
||||
os.fspath(tmp_dir),
|
||||
path="missed_path",
|
||||
recursive=True,
|
||||
outs_only=True,
|
||||
dvc_only=True,
|
||||
)
|
||||
assert exc_info.value.output_only
|
||||
assert exc_info.value.dvc_only
|
||||
|
||||
|
||||
def test_ls_repo_with_removed_dvc_dir(tmp_dir, dvc, scm):
|
||||
@@ -440,5 +440,5 @@ def test_ls_shows_pipeline_tracked_outs(tmp_dir, dvc, scm, run_copy):
|
||||
dvc.scm.add([PIPELINE_FILE, PIPELINE_LOCK])
|
||||
dvc.scm.commit("add pipeline stage")
|
||||
|
||||
files = Repo.ls(os.curdir, outs_only=True)
|
||||
files = Repo.ls(os.curdir, dvc_only=True)
|
||||
match_files(files, ((("bar",), True),))
|
||||
|
||||
@@ -17,7 +17,7 @@ class TestRemove(TestDvc):
|
||||
self.assertEqual(len(stages), 1)
|
||||
stage = stages[0]
|
||||
self.assertTrue(stage is not None)
|
||||
(stage_removed,) = self.dvc.remove(stage.path, outs_only=True)
|
||||
(stage_removed,) = self.dvc.remove(stage.path, dvc_only=True)
|
||||
|
||||
self.assertIsInstance(stage_removed, Stage)
|
||||
self.assertEqual(stage.path, stage_removed.path)
|
||||
|
||||
@@ -971,7 +971,7 @@ class TestReproExternalBase(SingleStageRun, TestDvc):
|
||||
self.dvc.gc(workspace=True)
|
||||
self.assertEqual(self.dvc.status(), {})
|
||||
|
||||
self.dvc.remove(cmd_stage.path, outs_only=True)
|
||||
self.dvc.remove(cmd_stage.path, dvc_only=True)
|
||||
self.assertNotEqual(self.dvc.status([cmd_stage.addressing]), {})
|
||||
|
||||
self.dvc.checkout([cmd_stage.path], force=True)
|
||||
@@ -1223,7 +1223,7 @@ class TestReproExternalHTTP(TestReproExternalBase):
|
||||
self.assertTrue(os.path.exists(run_output))
|
||||
|
||||
# Pull
|
||||
self.dvc.remove(import_stage.path, outs_only=True)
|
||||
self.dvc.remove(import_stage.path, dvc_only=True)
|
||||
self.assertFalse(os.path.exists(import_output))
|
||||
|
||||
shutil.move(self.local_cache, cache_id)
|
||||
|
||||
@@ -17,7 +17,7 @@ def test_list(mocker):
|
||||
url = "local_dir"
|
||||
m = _test_cli(mocker, url)
|
||||
m.assert_called_once_with(
|
||||
url, None, recursive=False, rev=None, outs_only=False
|
||||
url, None, recursive=False, rev=None, dvc_only=False
|
||||
)
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ def test_list_recursive(mocker):
|
||||
url = "local_dir"
|
||||
m = _test_cli(mocker, url, "-R")
|
||||
m.assert_called_once_with(
|
||||
url, None, recursive=True, rev=None, outs_only=False
|
||||
url, None, recursive=True, rev=None, dvc_only=False
|
||||
)
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ def test_list_git_ssh_rev(mocker):
|
||||
url = "[email protected]:repo"
|
||||
m = _test_cli(mocker, url, "--rev", "123")
|
||||
m.assert_called_once_with(
|
||||
url, None, recursive=False, rev="123", outs_only=False
|
||||
url, None, recursive=False, rev="123", dvc_only=False
|
||||
)
|
||||
|
||||
|
||||
@@ -42,13 +42,13 @@ def test_list_targets(mocker):
|
||||
target = "subdir"
|
||||
m = _test_cli(mocker, url, target)
|
||||
m.assert_called_once_with(
|
||||
url, target, recursive=False, rev=None, outs_only=False
|
||||
url, target, recursive=False, rev=None, dvc_only=False
|
||||
)
|
||||
|
||||
|
||||
def test_list_outputs_only(mocker):
|
||||
url = "local_dir"
|
||||
m = _test_cli(mocker, url, None, "--outs-only")
|
||||
m = _test_cli(mocker, url, None, "--dvc-only")
|
||||
m.assert_called_once_with(
|
||||
url, None, recursive=False, rev=None, outs_only=True
|
||||
url, None, recursive=False, rev=None, dvc_only=True
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user