mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab3f8fb1a4 | ||
|
|
6edca79b79 | ||
|
|
2a888970e8 | ||
|
|
73fdfc8059 | ||
|
|
8dc11417d2 | ||
|
|
b02855fb93 | ||
|
|
af255a46b4 | ||
|
|
2748492f6b |
+26
-5
@@ -1,5 +1,7 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from dvc.fs.callbacks import Callback
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from dvc.cloud import Remote
|
||||
from dvc.index import Index, IndexView
|
||||
@@ -30,7 +32,11 @@ def worktree_view(
|
||||
return True
|
||||
|
||||
def outs_filter(out: "Output") -> bool:
|
||||
if not out.is_in_repo or (push and not out.can_push):
|
||||
if (
|
||||
not out.is_in_repo
|
||||
or not out.use_cache
|
||||
or (push and not out.can_push)
|
||||
):
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -53,8 +59,12 @@ def fetch_worktree(repo: "Repo", remote: "Remote") -> int:
|
||||
remote.path,
|
||||
*key,
|
||||
)
|
||||
save(index)
|
||||
return len(index)
|
||||
total = len(index)
|
||||
with Callback.as_tqdm_callback(
|
||||
unit="file", desc="Fetch", disable=total == 0
|
||||
) as cb:
|
||||
cb.set_size(total)
|
||||
return save(index, callback=cb)
|
||||
|
||||
|
||||
def push_worktree(repo: "Repo", remote: "Remote") -> int:
|
||||
@@ -63,7 +73,18 @@ def push_worktree(repo: "Repo", remote: "Remote") -> int:
|
||||
|
||||
view = worktree_view(repo.index, push=True)
|
||||
index = view.data["repo"]
|
||||
checkout(index, remote.path, remote.fs)
|
||||
total = len(index)
|
||||
with Callback.as_tqdm_callback(
|
||||
unit="file", desc="Push", disable=total == 0
|
||||
) as cb:
|
||||
cb.set_size(total)
|
||||
pushed = checkout(
|
||||
index,
|
||||
remote.path,
|
||||
remote.fs,
|
||||
latest_only=False,
|
||||
callback=cb,
|
||||
)
|
||||
|
||||
for stage in view.stages:
|
||||
for out in stage.outs:
|
||||
@@ -97,4 +118,4 @@ def push_worktree(repo: "Repo", remote: "Remote") -> int:
|
||||
out.meta = entry.meta
|
||||
stage.dvcfile.dump(stage, with_files=True, update_pipeline=False)
|
||||
|
||||
return len(index)
|
||||
return pushed
|
||||
|
||||
+6
-4
@@ -180,7 +180,7 @@ class StageCache:
|
||||
dump_yaml(tmp, cache)
|
||||
self.repo.odb.local.move(tmp, path)
|
||||
|
||||
def restore(self, stage, run_cache=True, pull=False):
|
||||
def restore(self, stage, run_cache=True, pull=False, dry=False):
|
||||
from .serialize import to_single_stage_lockfile
|
||||
|
||||
if not _can_hash(stage):
|
||||
@@ -195,14 +195,15 @@ class StageCache:
|
||||
else:
|
||||
if not run_cache: # backward compatibility
|
||||
raise RunCacheNotFoundError(stage)
|
||||
stage.save_deps()
|
||||
if not dry:
|
||||
stage.save_deps()
|
||||
cache = self._load(stage)
|
||||
if not cache:
|
||||
raise RunCacheNotFoundError(stage)
|
||||
|
||||
cached_stage = self._create_stage(cache, wdir=stage.wdir)
|
||||
|
||||
if pull:
|
||||
if pull and not dry:
|
||||
for objs in cached_stage.get_used_objs().values():
|
||||
self.repo.cloud.pull(objs)
|
||||
|
||||
@@ -213,7 +214,8 @@ class StageCache:
|
||||
"Stage '%s' is cached - skipping run, checking out outputs",
|
||||
stage.addressing,
|
||||
)
|
||||
cached_stage.checkout()
|
||||
if not dry:
|
||||
cached_stage.checkout()
|
||||
|
||||
def transfer(self, from_odb, to_odb):
|
||||
from dvc.fs import HTTPFileSystem, LocalFileSystem
|
||||
|
||||
+6
-4
@@ -139,14 +139,16 @@ def cmd_run(stage, dry=False, checkpoint_func=None, run_env=None):
|
||||
def run_stage(
|
||||
stage, dry=False, force=False, checkpoint_func=None, run_env=None, **kwargs
|
||||
):
|
||||
if not (dry or force or checkpoint_func):
|
||||
if not (force or checkpoint_func):
|
||||
from .cache import RunCacheNotFoundError
|
||||
|
||||
try:
|
||||
stage.repo.stage_cache.restore(stage, **kwargs)
|
||||
return
|
||||
stage.repo.stage_cache.restore(stage, dry=dry, **kwargs)
|
||||
if not dry:
|
||||
return
|
||||
except RunCacheNotFoundError:
|
||||
stage.save_deps()
|
||||
if not dry:
|
||||
stage.save_deps()
|
||||
|
||||
run = cmd_run if dry else unlocked_repo(cmd_run)
|
||||
run(stage, dry=dry, checkpoint_func=checkpoint_func, run_env=run_env)
|
||||
|
||||
@@ -13,14 +13,22 @@ class TestAPI:
|
||||
assert api.get_url("foo") == expected_url
|
||||
|
||||
def test_open(self, tmp_dir, dvc, remote):
|
||||
tmp_dir.dvc_gen("foo", "foo-text")
|
||||
tmp_dir.dvc_gen(
|
||||
{
|
||||
"foo": "foo-text",
|
||||
"dir": {"bar": "bar-text"},
|
||||
}
|
||||
)
|
||||
dvc.push()
|
||||
|
||||
# Remove cache to force download
|
||||
remove(dvc.odb.local.path)
|
||||
|
||||
with api.open("foo") as fd:
|
||||
assert fd.read() == "foo-text"
|
||||
with api.open("foo") as fobj:
|
||||
assert fobj.read() == "foo-text"
|
||||
|
||||
with api.open("dir/bar") as fobj:
|
||||
assert fobj.read() == "bar-text"
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"clear_cache", [True, False], ids=["cache", "no_cache"]
|
||||
|
||||
+3
-1
@@ -270,7 +270,9 @@ class Console:
|
||||
|
||||
path = Path(file).resolve()
|
||||
url = (
|
||||
relpath(path) if "Microsoft" in uname().release else path.as_uri()
|
||||
relpath(path)
|
||||
if "microsoft" in uname().release.lower()
|
||||
else path.as_uri()
|
||||
)
|
||||
|
||||
opened = webbrowser.open(url)
|
||||
|
||||
@@ -44,6 +44,10 @@ if args.pkg == "osxpkg":
|
||||
]
|
||||
)
|
||||
else:
|
||||
if args.pkg == "rpm":
|
||||
# https://github.com/jordansissel/fpm/issues/1503
|
||||
flags.extend(["--rpm-rpmbuild-define", "_build_id_links none"])
|
||||
|
||||
bash_dir = build / "etc" / "bash_completion.d"
|
||||
dirs = ["usr", "etc"]
|
||||
flags.extend(["--depends", "git >= 1.7.0"]) # needed for gitpython
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
hiddenimports = ["win32timezone"]
|
||||
@@ -33,7 +33,7 @@ def test_restore(tmp_dir, dvc, run_copy, mocker):
|
||||
|
||||
(stage,) = dvc.reproduce("copy-foo-bar")
|
||||
|
||||
mock_restore.assert_called_once_with(stage)
|
||||
mock_restore.assert_called_once_with(stage, dry=False)
|
||||
mock_run.assert_not_called()
|
||||
assert (tmp_dir / "bar").exists() and not (tmp_dir / "foo").unlink()
|
||||
assert (tmp_dir / PIPELINE_LOCK).exists()
|
||||
@@ -100,7 +100,7 @@ def test_memory_for_multiple_runs_of_same_stage(
|
||||
assert (tmp_dir / PIPELINE_LOCK).exists()
|
||||
assert (tmp_dir / "bar").read_text() == "foobar"
|
||||
mock_run.assert_not_called()
|
||||
mock_restore.assert_called_once_with(stage)
|
||||
mock_restore.assert_called_once_with(stage, dry=False)
|
||||
mock_restore.reset_mock()
|
||||
|
||||
(tmp_dir / PIPELINE_LOCK).unlink()
|
||||
@@ -109,7 +109,7 @@ def test_memory_for_multiple_runs_of_same_stage(
|
||||
|
||||
assert (tmp_dir / "bar").read_text() == "foo"
|
||||
mock_run.assert_not_called()
|
||||
mock_restore.assert_called_once_with(stage)
|
||||
mock_restore.assert_called_once_with(stage, dry=False)
|
||||
assert (tmp_dir / "bar").exists() and not (tmp_dir / "foo").unlink()
|
||||
assert (tmp_dir / PIPELINE_LOCK).exists()
|
||||
|
||||
@@ -138,7 +138,7 @@ def test_memory_runs_of_multiple_stages(tmp_dir, dvc, run_copy, mocker):
|
||||
assert (tmp_dir / "foo.bak").read_text() == "foo"
|
||||
assert (tmp_dir / PIPELINE_LOCK).exists()
|
||||
mock_run.assert_not_called()
|
||||
mock_restore.assert_called_once_with(stage)
|
||||
mock_restore.assert_called_once_with(stage, dry=False)
|
||||
mock_restore.reset_mock()
|
||||
|
||||
(stage,) = dvc.reproduce("backup-bar")
|
||||
@@ -146,7 +146,7 @@ def test_memory_runs_of_multiple_stages(tmp_dir, dvc, run_copy, mocker):
|
||||
assert (tmp_dir / "bar.bak").read_text() == "bar"
|
||||
assert (tmp_dir / PIPELINE_LOCK).exists()
|
||||
mock_run.assert_not_called()
|
||||
mock_restore.assert_called_once_with(stage)
|
||||
mock_restore.assert_called_once_with(stage, dry=False)
|
||||
|
||||
|
||||
def test_restore_pull(tmp_dir, dvc, run_copy, mocker, local_remote):
|
||||
@@ -168,7 +168,7 @@ def test_restore_pull(tmp_dir, dvc, run_copy, mocker, local_remote):
|
||||
|
||||
(stage,) = dvc.reproduce("copy-foo-bar", pull=True)
|
||||
|
||||
mock_restore.assert_called_once_with(stage, pull=True)
|
||||
mock_restore.assert_called_once_with(stage, pull=True, dry=False)
|
||||
mock_run.assert_not_called()
|
||||
assert mock_checkout.call_count == 2
|
||||
assert (tmp_dir / "bar").exists() and not (tmp_dir / "foo").unlink()
|
||||
|
||||
@@ -178,7 +178,7 @@ def test_plots_diff_open(tmp_dir, dvc, mocker, capsys, plots_data, auto_open):
|
||||
def test_plots_diff_open_WSL(tmp_dir, dvc, mocker, plots_data):
|
||||
mocked_open = mocker.patch("webbrowser.open", return_value=True)
|
||||
mocked_uname_result = mocker.MagicMock()
|
||||
mocked_uname_result.release = "Microsoft"
|
||||
mocked_uname_result.release = "microsoft"
|
||||
mocker.patch("platform.uname", return_value=mocked_uname_result)
|
||||
|
||||
cli_args = parse_args(
|
||||
|
||||
@@ -13,9 +13,9 @@ from dvc.stage.run import run_stage
|
||||
(["mycmd1 arg1", "mycmd2 arg2"], ["> mycmd1 arg1", "> mycmd2 arg2"]),
|
||||
],
|
||||
)
|
||||
def test_run_stage_dry(caplog, cmd, expected):
|
||||
def test_run_stage_dry(caplog, dvc, cmd, expected):
|
||||
with caplog.at_level(level=logging.INFO, logger="dvc"):
|
||||
stage = Stage(None, "stage.dvc", cmd=cmd)
|
||||
stage = Stage(dvc, "stage.dvc", cmd=cmd)
|
||||
run_stage(stage, dry=True)
|
||||
|
||||
expected.insert(0, "Running stage 'stage.dvc':")
|
||||
|
||||
Reference in New Issue
Block a user