@@ -211,29 +211,29 @@ private ModelArchive createModelArchive(
211
211
212
212
private void setupModelVenv (Model model )
213
213
throws IOException , InterruptedException , ModelException {
214
- ModelConfig modelConfig = model .getModelArchive ().getModelConfig ();
215
- if (model .getModelArchive ().getManifest ().getRuntime () != Manifest .RuntimeType .PYTHON
216
- || modelConfig == null
217
- || modelConfig .getUseVenv () != true ) {
214
+ if (model .getRuntimeType () != Manifest .RuntimeType .PYTHON || !model .isUseVenv ()) {
218
215
return ;
219
216
}
220
217
221
- String venvPath = EnvironmentUtils .getPythonVenvPath (model );
218
+ File venvPath = EnvironmentUtils .getPythonVenvPath (model );
222
219
List <String > commandParts = new ArrayList <>();
223
220
commandParts .add (configManager .getPythonExecutable ());
224
221
commandParts .add ("-m" );
225
222
commandParts .add ("venv" );
226
223
commandParts .add ("--clear" );
227
224
commandParts .add ("--system-site-packages" );
228
- commandParts .add (venvPath );
225
+ commandParts .add (venvPath . toString () );
229
226
230
227
ProcessBuilder processBuilder = new ProcessBuilder (commandParts );
231
228
232
229
if (isValidDependencyPath (venvPath )) {
233
- processBuilder .directory (Paths . get ( venvPath ). toFile () .getParentFile ());
230
+ processBuilder .directory (venvPath .getParentFile ());
234
231
} else {
235
232
throw new ModelException (
236
- "Invalid python venv path for model " + model .getModelName () + ": " + venvPath );
233
+ "Invalid python venv path for model "
234
+ + model .getModelName ()
235
+ + ": "
236
+ + venvPath .toString ());
237
237
}
238
238
Map <String , String > environment = processBuilder .environment ();
239
239
String [] envp =
@@ -261,12 +261,14 @@ private void setupModelVenv(Model model)
261
261
262
262
if (exitCode == 0 ) {
263
263
logger .info (
264
- "Created virtual environment for model {}: {}" , model .getModelName (), venvPath );
264
+ "Created virtual environment for model {}: {}" ,
265
+ model .getModelName (),
266
+ venvPath .toString ());
265
267
} else {
266
268
logger .error (
267
269
"Virtual environment creation for model {} at {} failed:\n {}" ,
268
270
model .getModelName (),
269
- venvPath ,
271
+ venvPath . toString () ,
270
272
outputString .toString ());
271
273
throw new ModelException (
272
274
"Virtual environment creation failed for model " + model .getModelName ());
@@ -282,24 +284,22 @@ private void setupModelDependencies(Model model)
282
284
return ;
283
285
}
284
286
285
- ModelConfig modelConfig = model .getModelArchive ().getModelConfig ();
286
287
String pythonRuntime = EnvironmentUtils .getPythonRunTime (model );
287
288
Path requirementsFilePath =
288
- Paths .get (model .getModelDir ().getAbsolutePath (), requirementsFile );
289
+ Paths .get (model .getModelDir ().getAbsolutePath (), requirementsFile ). toAbsolutePath () ;
289
290
List <String > commandParts = new ArrayList <>();
290
291
ProcessBuilder processBuilder = new ProcessBuilder ();
291
292
292
- if (modelConfig != null && modelConfig . getUseVenv () == true ) {
293
- if (!isValidDependencyPath (pythonRuntime )) {
293
+ if (model . isUseVenv () ) {
294
+ if (!isValidDependencyPath (Paths . get ( pythonRuntime ). toFile () )) {
294
295
throw new ModelException (
295
296
"Invalid python venv runtime path for model "
296
297
+ model .getModelName ()
297
298
+ ": "
298
299
+ pythonRuntime );
299
300
}
300
301
301
- processBuilder .directory (
302
- Paths .get (EnvironmentUtils .getPythonVenvPath (model )).toFile ().getParentFile ());
302
+ processBuilder .directory (EnvironmentUtils .getPythonVenvPath (model ).getParentFile ());
303
303
304
304
commandParts .add (pythonRuntime );
305
305
commandParts .add ("-m" );
@@ -311,14 +311,13 @@ private void setupModelDependencies(Model model)
311
311
commandParts .add ("-r" );
312
312
commandParts .add (requirementsFilePath .toString ());
313
313
} else {
314
- File dependencyPath = model .getModelDir ();
314
+ File dependencyPath = model .getModelDir (). getAbsolutePath () ;
315
315
if (Files .isSymbolicLink (dependencyPath .toPath ())) {
316
316
dependencyPath = dependencyPath .getParentFile ();
317
317
}
318
- if (!isValidDependencyPath (dependencyPath . getPath () )) {
318
+ if (!isValidDependencyPath (dependencyPath )) {
319
319
throw new ModelException (
320
- "Invalid 3rd party package installation path "
321
- + dependencyPath .getCanonicalPath ());
320
+ "Invalid 3rd party package installation path " + dependencyPath .toString ());
322
321
}
323
322
324
323
processBuilder .directory (dependencyPath );
@@ -329,7 +328,7 @@ private void setupModelDependencies(Model model)
329
328
commandParts .add ("install" );
330
329
commandParts .add ("-U" );
331
330
commandParts .add ("-t" );
332
- commandParts .add (dependencyPath .getAbsolutePath ());
331
+ commandParts .add (dependencyPath .toString ());
333
332
commandParts .add ("-r" );
334
333
commandParts .add (requirementsFilePath .toString ());
335
334
}
@@ -374,8 +373,9 @@ private void setupModelDependencies(Model model)
374
373
}
375
374
}
376
375
377
- private boolean isValidDependencyPath (String dependencyPath ) {
378
- if (Paths .get (dependencyPath )
376
+ private boolean isValidDependencyPath (File dependencyPath ) {
377
+ if (dependencyPath
378
+ .toPath ()
379
379
.normalize ()
380
380
.startsWith (FileUtils .getTempDirectory ().toPath ().normalize ())) {
381
381
return true ;
0 commit comments