Skip to content

Commit

Permalink
fix: compare bento with pretty diff
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Sep 24, 2024
1 parent 907dc78 commit 01b8386
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/bentoml/_internal/cloud/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,18 +812,31 @@ def watch_filter(change: watchfiles.Change, path: str) -> bool:
assert isinstance(bento_info, Bento)
target = self._refetch_target(False)

def is_bento_changed(bento_info: Bento) -> bool:
if target is None or target.bento is None:
return True
bento_manifest = bento_info.get_manifest()
if target.bento.manifest == bento_manifest:
return False
try:
from deepdiff import DeepDiff
except ModuleNotFoundError:
pass
else:
diff = DeepDiff(
target.bento.manifest, bento_manifest, ignore_order=True
)
console.print(f"[blue]{diff.pretty()}[/]")
return True

spinner = Spinner(console=console)
try:
spinner.start()
upload_id = spinner.transmission_progress.add_task(
"Dummy upload task", visible=False
)
while True:
if (
target is None
or target.bento is None
or target.bento.manifest != bento_info.get_manifest()
):
if is_bento_changed(bento_info):
console.print("✨ [green bold]Bento change detected[/]")
spinner.update("🔄 Pushing Bento to BentoCloud")
bento_api._do_push_bento(bento_info, upload_id, bare=True) # type: ignore
Expand Down Expand Up @@ -861,11 +874,7 @@ def watch_filter(change: watchfiles.Change, path: str) -> bool:
_client=self._client,
)
assert isinstance(bento_info, Bento)
if (
target is None
or target.bento is None
or target.bento.manifest != bento_info.get_manifest()
):
if is_bento_changed(bento_info):
# stop log tail and reset the deployment
break

Expand Down

0 comments on commit 01b8386

Please sign in to comment.