Uninstall one or several models.
Parameters:
Name |
Type |
Description |
Default |
model
|
string
|
Model name of the model to be uninstalled. Defaults to None.
|
None
|
all
|
bool
|
Option to uninstall all installed models. Should be called before uninstalling the sund package to make sure no files are left on the file system. Defaults to False.
|
None
|
modelname
|
string
|
Deprecated. Use 'model' instead. Defaults to None.
|
None
|
uninstallall
|
bool
|
Deprecated. Use 'all' instead. Defaults to None.
|
None
|
Raises:
Type |
Description |
ValueError
|
Model *name* has already been imported to memory, you will need to restart Python before uninstalling the model , if the model has already been imported.
|
ValueError
|
Model file for model *name* not found , the model files are missing and can thus not be uninstalled.
|
ValueError
|
Model *name* could not be uninstalled, probably because it is being used by another process. Try terminating any process that might use the model and try again , if the model cannot be uninstalled because it is being used.
|
Source code in src/sund/__init__.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314 | def uninstall_model(model=None, modelname=None, all=None, uninstallall=None):
"""Uninstall one or several models.
Args:
model (string, optional): Model name of the model to be uninstalled. Defaults to None.
all (bool, optional): Option to uninstall *all* installed models. Should be called before uninstalling the sund package to make sure no files are left on the file system. Defaults to False.
modelname (string, optional): Deprecated. Use 'model' instead. Defaults to None.
uninstallall (bool, optional): Deprecated. Use 'all' instead. Defaults to None.
Raises:
ValueError: `Model *name* has already been imported to memory, you will need to restart Python before uninstalling the model`, if the model has already been imported.
ValueError: `Model file for model *name* not found`, the model files are missing and can thus not be uninstalled.
ValueError: `Model *name* could not be uninstalled, probably because it is being used by another process. Try terminating any process that might use the model and try again`, if the model cannot be uninstalled because it is being used.
"""
# REMOVE WITH NEXT MAJOR RELEASE
# Conflicting arguments
if (model != None and modelname != None):
raise SyntaxError("Only either of 'model' and 'modelname' can be set!")
if (all != None and uninstallall != None):
raise SyntaxError("Only either of 'all' and 'uninstallall can be set!")
# Deprecated arguments
if (modelname != None):
warnings.warn("The 'modelname' argument is deprecated and will be removed in a future version. Use the 'model' argument instead!", FutureWarning, 2)
model = modelname
if (uninstallall != None):
warnings.warn("The 'uninstallall' argument is deprecated and will be removed in a future version. Use the 'all' argument instead!", FutureWarning, 2)
all = uninstallall
elif (all == None):
all = False
if (all == False and model == None):
raise SyntaxError("'model' must be set if 'all' is False!")
ModelsFolder = Path(__file__).parent / "Models"
if all:
model_names = installed_models()
uninstall_model(model_names)
print("\nAll models have been uninstalled.")
elif type(model) is list:
for m in model:
uninstall_model(m)
else:
if ("sund.Models." + model) in sys.modules:
raise ValueError(f"Model '{model}' has been imported into memory, you will need to restart Python before uninstalling the model.")
file = ModelsFolder / (model + get_config_var("EXT_SUFFIX"))
if not file.exists():
warnings.warn(f"Model file for model '{model}' not found. Had the model been installed before?")
else:
try:
file.unlink()
print(f"Model '{model}' has been uninstalled.")
except Exception as e:
raise ValueError(f"Model '{model}' could not be uninstalled, probably because it is being used by another process. Try terminating any process that might use the model and try again.") from e
|