Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: opt-in to Push with empty Metadata #10

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install Poetry
run: |
pipx install poetry
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
make install
- name: Run Ruff
run: |
ruff check --config=pyproject.toml --output-format=github .
poetry run ruff check --config=pyproject.toml --output-format=github .
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))
54 changes: 34 additions & 20 deletions poetry.lock

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

6 changes: 5 additions & 1 deletion 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 All @@ -27,7 +28,7 @@ scikit-learn = "^1.5.0"
ipykernel = "^6.29.4"
markdown-it-py = "^3.0.0"
model-registry = "^0.2.4a1"
ruff = "^0.5.7"
ruff = "^0.6.1"
mypy = "^1.11.1"
types-pyyaml = "^6.0.12.20240808"

Expand All @@ -48,6 +49,9 @@ markers = [
target-version = "py39"
respect-gitignore = true

[tool.ruff.lint.per-file-ignores]
"*.ipynb" = ["E402"] # exclude https://docs.astral.sh/ruff/rules/module-import-not-at-top-of-file/#notebook-behavior from linting, especially for demos.

[tool.mypy]
python_version = "3.9"
strict = false
Expand Down
Loading