Skip to content

Commit

Permalink
cli: opt-in to Push with empty Metadata
Browse files Browse the repository at this point in the history
Signed-off-by: tarilabs <[email protected]>
  • Loading branch information
tarilabs committed Aug 21, 2024
1 parent c5c2797 commit 0864618
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
1 change: 1 addition & 0 deletions e2e/test_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pip install dist/omlmd-*.whl

echo "Running E2E test for CLI ..."

omlmd push localhost:5001/mmortari/mlartifact:v1 README.md --empty-metadata --plain-http
omlmd push localhost:5001/mmortari/mlartifact:v1 README.md --metadata tests/data/md.json --plain-http

omlmd pull localhost:5001/mmortari/mlartifact:v1 -o tmp/a --plain-http
Expand Down
37 changes: 24 additions & 13 deletions omlmd/cli.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
"""Command line interface for OMLMD."""

from __future__ import annotations
from pathlib import Path

import click
import cloup
import logging

from omlmd.helpers import Helper
from omlmd.model_metadata import deserialize_mdfile
from omlmd.provider import OMLMDRegistry


logger = logging.getLogger(__name__)


plain_http = click.option(
"--plain-http",
help="allow insecure connections to registry without SSL check",
help="Allow insecure connections to registry without SSL check",
is_flag=True,
default=False,
show_default=True,
Expand All @@ -21,9 +27,9 @@ def get_OMLMDRegistry(plain_http: bool) -> OMLMDRegistry:
return OMLMDRegistry(insecure=plain_http)


@click.group()
@cloup.group()
def cli():
pass
logging.basicConfig(level=logging.INFO)


@cli.command()
Expand Down Expand Up @@ -71,16 +77,21 @@ def crawl(plain_http: bool, targets: tuple[str]):
required=True,
type=click.Path(path_type=Path, exists=True, resolve_path=True),
)
@click.option(
"-m",
"--metadata",
required=True,
type=click.Path(path_type=Path, exists=True, resolve_path=True),
@cloup.option_group(
"Metadata options",
cloup.option(
"-m",
"--metadata",
type=click.Path(path_type=Path, exists=True, resolve_path=True),
help="Metadata file in JSON or YAML format"
),
cloup.option('--empty-metadata', help='Push with empty metadata', is_flag=True),
constraint=cloup.constraints.require_one,
)
def push(plain_http: bool, target: str, path: Path, metadata: Path):
def push(plain_http: bool, target: str, path: Path, metadata: Path | None, empty_metadata: bool):
"""Pushes an OCI Artifact containing ML model and metadata, supplying metadata from file as necessary"""
import logging

logging.basicConfig(level=logging.DEBUG)
md = deserialize_mdfile(metadata)
if empty_metadata:
logger.warning(f"Pushing to {target} with empty metadata.")
md = deserialize_mdfile(metadata) if metadata else {}
click.echo(Helper(get_OMLMDRegistry(plain_http)).push(target, path, **md))
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 @@ -18,6 +18,7 @@ oras = "^0.1.30"
pyyaml = "^6.0.1"
nbconvert = "^7.16.4"
click = "^8.1.7"
cloup = "^3.0.5"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.2"
Expand Down

0 comments on commit 0864618

Please sign in to comment.