@@ -180,28 +180,27 @@ def install_path(
180
180
self ,
181
181
model_path : Union [Path , str ],
182
182
config : Optional [ModelRecordChanges ] = None ,
183
- ) -> str : # noqa D102
183
+ ) -> str :
184
184
model_path = Path (model_path )
185
185
config = config or ModelRecordChanges ()
186
186
info : AnyModelConfig = self ._probe (Path (model_path ), config ) # type: ignore
187
187
188
- if preferred_name := config .name :
189
- if Path (model_path ).is_file ():
190
- # Careful! Don't use pathlib.Path(...).with_suffix - it can will strip everything after the first dot.
191
- preferred_name = f"{ preferred_name } { model_path .suffix } "
192
-
193
- dest_path = (
194
- self .app_config .models_path / info .base .value / info .type .value / (preferred_name or model_path .name )
195
- )
188
+ dest_dir = self .app_config .models_path / info .key
196
189
try :
197
- new_path = self ._move_model (model_path , dest_path )
190
+ dest_dir .mkdir (parents = True )
191
+ dest_path = dest_dir / model_path .name if model_path .is_file () else dest_dir
192
+ if dest_path .exists ():
193
+ raise FileExistsError (
194
+ f"Cannot install model { model_path .name } to { dest_path } : destination already exists"
195
+ )
196
+ move (model_path , dest_path )
198
197
except FileExistsError as excp :
199
198
raise DuplicateModelException (
200
- f"A model named { model_path .name } is already installed at { dest_path .as_posix ()} "
199
+ f"A model named { model_path .name } is already installed at { dest_dir .as_posix ()} "
201
200
) from excp
202
201
203
202
return self ._register (
204
- new_path ,
203
+ dest_path ,
205
204
config ,
206
205
info ,
207
206
)
@@ -589,49 +588,6 @@ def on_model_found(model_path: Path) -> bool:
589
588
found_models = search .search (self ._app_config .models_path )
590
589
self ._logger .info (f"{ len (found_models )} new models registered" )
591
590
592
- def sync_model_path (self , key : str ) -> AnyModelConfig :
593
- """
594
- Move model into the location indicated by its basetype, type and name.
595
-
596
- Call this after updating a model's attributes in order to move
597
- the model's path into the location indicated by its basetype, type and
598
- name. Applies only to models whose paths are within the root `models_dir`
599
- directory.
600
-
601
- May raise an UnknownModelException.
602
- """
603
- model = self .record_store .get_model (key )
604
- models_dir = self .app_config .models_path
605
- old_path = self .app_config .models_path / model .path
606
-
607
- if not old_path .is_relative_to (models_dir ):
608
- # The model is not in the models directory - we don't need to move it.
609
- return model
610
-
611
- new_path = models_dir / model .base .value / model .type .value / old_path .name
612
-
613
- if old_path == new_path or new_path .exists () and old_path == new_path .resolve ():
614
- return model
615
-
616
- self ._logger .info (f"Moving { model .name } to { new_path } ." )
617
- new_path = self ._move_model (old_path , new_path )
618
- model .path = new_path .relative_to (models_dir ).as_posix ()
619
- self .record_store .update_model (key , ModelRecordChanges (path = model .path ))
620
- return model
621
-
622
- def _move_model (self , old_path : Path , new_path : Path ) -> Path :
623
- if old_path == new_path :
624
- return old_path
625
-
626
- if new_path .exists ():
627
- raise FileExistsError (f"Cannot move { old_path } to { new_path } : destination already exists" )
628
-
629
- new_path .parent .mkdir (parents = True , exist_ok = True )
630
-
631
- move (old_path , new_path )
632
-
633
- return new_path
634
-
635
591
def _probe (self , model_path : Path , config : Optional [ModelRecordChanges ] = None ):
636
592
config = config or ModelRecordChanges ()
637
593
hash_algo = self ._app_config .hashing_algorithm
0 commit comments