Skip to content

Commit 5843e38

Browse files
committed
Always use absolute path for --store option
Fixes: #1634 Signed-off-by: Daniel J Walsh <[email protected]>
1 parent 162e2e5 commit 5843e38

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

ramalama/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ def get_description():
148148
"""
149149

150150

151+
def abspath(astring):
152+
return os.path.abspath(astring)
153+
154+
151155
def create_argument_parser(description: str):
152156
"""Create and configure the argument parser for the CLI."""
153157
parser = ArgumentParserWithDefaults(
@@ -222,6 +226,7 @@ def configure_arguments(parser):
222226
parser.add_argument(
223227
"--store",
224228
default=CONFIG.store,
229+
type=abspath,
225230
help="store AI Models in the specified directory",
226231
)
227232
parser.add_argument(

ramalama/model_factory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(
3636

3737
self.pruned_model = self.prune_model_input()
3838
self.draft_model = None
39-
if getattr(args, 'model_draft', None):
39+
if hasattr(args, 'model_draft') and args.model_draft:
4040
dm_args = copy.deepcopy(args)
4141
dm_args.model_draft = None
4242
self.draft_model = ModelFactory(args.model_draft, dm_args, ignore_stderr=True).create()
@@ -63,7 +63,7 @@ def __init__(
6363
def detect_model_model_type(
6464
self,
6565
) -> Tuple[type[Union[Huggingface, Ollama, OCI, URL]], Callable[[], Union[Huggingface, Ollama, OCI, URL]]]:
66-
for prefix in ["huggingface://", "hf://", "hf.co/"]:
66+
for prefix in ["huggingface://", "hfq://", "hf.co/"]:
6767
if self.model.startswith(prefix):
6868
return Huggingface, self.create_huggingface
6969
for prefix in ["modelscope://", "ms://"]:
@@ -137,7 +137,7 @@ def create_oci(self) -> OCI:
137137
def create_url(self) -> URL:
138138
model = URL(self.pruned_model, self.store_path, urlparse(self.model).scheme)
139139
model.draft_model = self.draft_model
140-
if getattr(self, 'split_model', None):
140+
if hasattr(self, 'split_model'):
141141
model.split_model = self.split_model
142142
model.mnt_path = self.mnt_path
143143
return model

test/system/060-info.bats

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,11 @@ Store | $store
5959

6060
}
6161

62+
@test "ramalama info --store" {
63+
store=$PWD/store
64+
run_ramalama --store ./store info
65+
actual=$(echo "$output" | jq -r ".Store")
66+
is "$actual" "$store" "Verify relative paths translated to absolute path"
67+
}
68+
6269
# vim: filetype=sh

0 commit comments

Comments
 (0)