Skip to content

Commit

Permalink
pip3 on macOS can install in funny directories
Browse files Browse the repository at this point in the history
Like:

/Users/ecurtin/Library/Python//3.9/bin/omlmd

Signed-off-by: Eric Curtin <ecurtin@redhat.com>
  • Loading branch information
ericcurtin committed Sep 25, 2024
1 parent 209dc6c commit eedd3d9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ramalama/oci.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@
import os
import re
import subprocess
import sys

from ramalama.model import Model
from ramalama.common import run_cmd, exec_cmd, perror
from ramalama.common import run_cmd, exec_cmd, perror, available


class OCI(Model):
def __init__(self, model):
super().__init__(model.removeprefix("oci://").removeprefix("docker://"))
self.type = "OCI"
if available("omlmd"):
self.omlmd = "omlmd"
else:
for i in sys.path:
self.omlmd = f"{i}/../../../bin/omlmd"
if os.path.exists(self.omlmd):
break

def login(self, args):
conman_args = [self.conman, "login"]
Expand Down Expand Up @@ -53,7 +61,7 @@ def push(self, args):
model_file = Path(local_model_path).resolve()
try:
# Push the model using omlmd, using cwd the model's file parent directory
run_cmd(["omlmd", "push", target, str(model_file), "--empty-metadata"], cwd=model_file.parent)
run_cmd([self.omlmd, "push", target, str(model_file), "--empty-metadata"], cwd=model_file.parent)
except subprocess.CalledProcessError as e:
perror(f"Failed to push model to OCI: {e}")
raise e
Expand All @@ -71,7 +79,7 @@ def pull(self, args):
print(f"Downloading {self.model}...")
# note: in the current way ramalama is designed, cannot do Helper(OMLMDRegistry()).pull(target, outdir)
# since cannot use modules/sdk, can use only cli bindings from pip installs
run_cmd(["omlmd", "pull", self.model, "--output", outdir])
run_cmd([self.omlmd, "pull", self.model, "--output", outdir])
ggufs = [file for file in os.listdir(outdir) if file.endswith(".gguf")]
if len(ggufs) != 1:
raise KeyError(f"unable to identify .gguf file in: {outdir}")
Expand Down

0 comments on commit eedd3d9

Please sign in to comment.