Skip to content

Commit

Permalink
chore: refactor for constants (#12)
Browse files Browse the repository at this point in the history
* chore: refactor for constants

Signed-off-by: tarilabs <[email protected]>

* Update omlmd/helpers.py

Signed-off-by: Matteo Mortari <[email protected]>

Co-authored-by: Isabella Basso <[email protected]>

---------

Signed-off-by: tarilabs <[email protected]>
Co-authored-by: Isabella Basso <[email protected]>
  • Loading branch information
tarilabs and isinyaaa authored Sep 3, 2024
1 parent 3c87873 commit 410c173
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions omlmd/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FILENAME_METADATA_JSON = "model_metadata.omlmd.json"
FILENAME_METADATA_YAML = "model_metadata.omlmd.yaml"
MIME_APPLICATION_CONFIG = "application/x-config"
MIME_APPLICATION_MLMODEL = "application/x-mlmodel"
16 changes: 11 additions & 5 deletions omlmd/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
from dataclasses import fields
from pathlib import Path

from omlmd.constants import (
FILENAME_METADATA_JSON,
FILENAME_METADATA_YAML,
MIME_APPLICATION_CONFIG,
MIME_APPLICATION_MLMODEL,
)
from omlmd.listener import Event, Listener, PushEvent
from omlmd.model_metadata import ModelMetadata
from omlmd.provider import OMLMDRegistry
Expand Down Expand Up @@ -65,8 +71,8 @@ def push(
if isinstance(path, str):
path = Path(path)

json_meta = path.parent / "model_metadata.omlmd.json"
yaml_meta = path.parent / "model_metadata.omlmd.yaml"
json_meta = path.parent / FILENAME_METADATA_JSON
yaml_meta = path.parent / FILENAME_METADATA_YAML
if model_metadata.is_empty() and json_meta.exists() and yaml_meta.exists():
owns_meta_files = False
logger.warning("No metadata supplied, but reusing md files found in path.")
Expand All @@ -81,11 +87,11 @@ def push(
json_meta.write_text(model_metadata.to_json())
yaml_meta.write_text(model_metadata.to_yaml())

manifest_cfg = f"{json_meta}:application/x-config"
manifest_cfg = f"{json_meta}:{MIME_APPLICATION_CONFIG}"
files = [
f"{path}:application/x-mlmodel",
f"{path}:{MIME_APPLICATION_MLMODEL}",
manifest_cfg,
f"{yaml_meta}:application/x-config",
f"{yaml_meta}:{MIME_APPLICATION_CONFIG}",
]
try:
# print(target, files, model_metadata.to_annotations_dict())
Expand Down
3 changes: 2 additions & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from omlmd.constants import MIME_APPLICATION_MLMODEL
from omlmd.helpers import Helper
from omlmd.listener import Event, Listener
from omlmd.model_metadata import ModelMetadata, deserialize_mdfile
Expand Down Expand Up @@ -89,5 +90,5 @@ def test_e2e_push_pull_with_filters(tmp_path, target):
author="John Doe",
accuracy=0.987,
)
omlmd.pull(target, tmp_path, media_types=["application/x-mlmodel"])
omlmd.pull(target, tmp_path, media_types=[MIME_APPLICATION_MLMODEL])
assert len(list(tmp_path.iterdir())) == 1

0 comments on commit 410c173

Please sign in to comment.