Skip to content

Commit

Permalink
log changes to cloud versioned remotes
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Feb 21, 2024
1 parent 4e25f63 commit 0b3a065
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions dvc/commands/dataset.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING, Any, Optional

from dvc.cli import formatter
from dvc.cli.command import CmdBase
from dvc.cli.utils import append_doc_link
from dvc.log import logger
from dvc.repo.datasets import URLDatasetLock

if TYPE_CHECKING:
from rich.text import Text
Expand All @@ -13,6 +14,17 @@
logger = logger.getChild(__name__)


def diff_files(old: list[dict[str, Any]], new: list[dict[str, Any]]):
old_files = {d["relpath"]: d for d in old}
new_files = {d["relpath"]: d for d in new}
rest = old_files.keys() & new_files.keys()
return {
"added": list(new_files.keys() - old_files.keys()),
"deleted": list(old_files.keys() - new_files.keys()),
"modified": [p for p in rest if new_files[p] != old_files[p]],
}


class CmdDatasetAdd(CmdBase):
@classmethod
def display(cls, dataset: "Dataset", action: str = "Adding"):
Expand Down Expand Up @@ -61,6 +73,7 @@ def run(self):

class CmdDatasetUpdate(CmdBase):
def display(self, dataset: "Dataset", new: "Dataset"):
from dvc.commands.checkout import log_changes
from dvc.repo.datasets import DVCDatasetLock, DVCXDatasetLock
from dvc.ui import ui

Expand All @@ -77,7 +90,6 @@ def display(self, dataset: "Dataset", new: "Dataset"):
if isinstance(dataset.lock, DVCDatasetLock):
assert isinstance(new.lock, DVCDatasetLock)
v = (f"{dataset.lock.rev_lock[:9]}", f"{new.lock.rev_lock[:9]}")

if v:
part = ui.rich_text.assemble(
(v[0], "repr.number"),
Expand All @@ -88,6 +100,10 @@ def display(self, dataset: "Dataset", new: "Dataset"):
part = ui.rich_text(dataset.url, "repr.url")
changes = ui.rich_text.assemble("(", part, ")")
ui.write("Updating", ui.rich_text(dataset.name, "cyan"), changes, styled=True)
if isinstance(dataset.lock, URLDatasetLock):
assert isinstance(new.lock, URLDatasetLock)
stats = diff_files(dataset.lock.files, new.lock.files)
log_changes(stats)

def run(self):
with self.repo.scm_context:
Expand Down

0 comments on commit 0b3a065

Please sign in to comment.