Skip to content

Commit

Permalink
store entire response on push
Browse files Browse the repository at this point in the history
Signed-off-by: Isabella do Amaral <[email protected]>
  • Loading branch information
isinyaaa committed Oct 28, 2024
1 parent c2ed213 commit bb445ec
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
14 changes: 3 additions & 11 deletions omlmd/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ def download_file(uri: str):

@dataclass
class Helper:
_registry: OMLMDRegistry = (
field( # TODO: this is a bit limiting when used from CLI, to be refactored
default_factory=lambda: OMLMDRegistry(insecure=True)
)
_registry: OMLMDRegistry = field(
default_factory=lambda: OMLMDRegistry(insecure=True)
)
_listeners: list[Listener] = field(default_factory=list)

Expand Down Expand Up @@ -99,13 +97,7 @@ def push(
manifest_config=manifest_cfg,
do_chunked=True,
)
self.notify_listeners(
PushEvent(
result.headers["Docker-Content-Digest"],
target,
model_metadata,
)
)
self.notify_listeners(PushEvent(result, target, model_metadata))
return result
finally:
if owns_meta_files:
Expand Down
11 changes: 10 additions & 1 deletion omlmd/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass

import requests

from .model_metadata import ModelMetadata


Expand All @@ -26,6 +28,13 @@ class Event(ABC):

@dataclass
class PushEvent(Event):
digest: str
response: requests.Response
target: str
metadata: ModelMetadata

@property
def ok(self) -> bool:
return self.response.status_code == 200

def get_digest(self) -> str:
return self.response.headers["Docker-Content-Digest"] if self.ok else ""
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ model-registry = ">=0.2.9,<0.3.0"
ruff = "^0.6.1"
mypy = "^1.11.1"
types-pyyaml = "^6.0.12.20240808"
types-requests = "^2.32.0.20241016"

[tool.poetry.scripts]
omlmd = "omlmd.cli:cli"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_e2e_model_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class ListenerForModelRegistry(Listener):

def update(self, source: Helper, event: Event) -> None:
if isinstance(event, PushEvent):
self.sha = event.digest
self.rm = from_oci_to_kfmr(model_registry, event, event.digest)
self.sha = event.get_digest()
self.rm = from_oci_to_kfmr(model_registry, event, self.sha)

listener = ListenerForModelRegistry()
omlmd = Helper()
Expand Down

0 comments on commit bb445ec

Please sign in to comment.