@@ -198,7 +198,12 @@ private GraalPyResources() {
198
198
* location</li>
199
199
* <li><code>/org.graalvm.python.vfs/src</code> - is set as the python sources location</li>
200
200
* </ul>
201
- * </p>
201
+ * <p>
202
+ * When the virtual filesystem is located in other than the default resource directory,
203
+ * {@code org.graalvm.python.vfs}, i.e., using Maven or Gradle option {@code resourceDirectory},
204
+ * use {@link #contextBuilder(VirtualFileSystem)} and
205
+ * {@link VirtualFileSystem.Builder#resourceDirectory(String)} when building the
206
+ * {@link VirtualFileSystem}.
202
207
*
203
208
* @return a new {@link Context} instance
204
209
* @since 24.2.0
@@ -233,6 +238,12 @@ public static Context createContext() {
233
238
* }
234
239
* }
235
240
* </pre>
241
+ * <p>
242
+ * When the virtual filesystem is located in other than the default resource directory,
243
+ * {@code org.graalvm.python.vfs}, i.e., using Maven or Gradle option {@code resourceDirectory},
244
+ * use {@link #contextBuilder(VirtualFileSystem)} and
245
+ * {@link VirtualFileSystem.Builder#resourceDirectory(String)} when building the
246
+ * {@link VirtualFileSystem}.
236
247
*
237
248
* @see <a href=
238
249
* "https://github.com/oracle/graalpython/blob/master/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java">PythonOptions</a>
@@ -308,13 +319,14 @@ public static Context.Builder contextBuilder(VirtualFileSystem vfs) {
308
319
309
320
/**
310
321
* Creates a GraalPy context preconfigured with GraalPy and polyglot Context configuration
311
- * options for use with resources located in a real filesystem.
322
+ * options for use with resources located in an external directory in real filesystem.
312
323
* <p>
313
324
* Following resource paths are preconfigured:
314
325
* <ul>
315
- * <li><code>${resourcesDirectory}/venv</code> - is set as the python virtual environment
326
+ * <li><code>${externalResourcesDirectory}/venv</code> - is set as the python virtual
327
+ * environment location</li>
328
+ * <li><code>${externalResourcesDirectory}/src</code> - is set as the python sources
316
329
* location</li>
317
- * <li><code>${resourcesDirectory}/src</code> - is set as the python sources location</li>
318
330
* </ul>
319
331
* </p>
320
332
* <p>
@@ -343,19 +355,20 @@ public static Context.Builder contextBuilder(VirtualFileSystem vfs) {
343
355
* </ul>
344
356
* </p>
345
357
*
346
- * @param resourcesDirectory the root directory with GraalPy specific embedding resources
358
+ * @param externalResourcesDirectory the root directory with GraalPy specific embedding
359
+ * resources
347
360
* @return a new {@link org.graalvm.polyglot.Context.Builder} instance
348
361
* @since 24.2.0
349
362
*/
350
- public static Context .Builder contextBuilder (Path resourcesDirectory ) {
363
+ public static Context .Builder contextBuilder (Path externalResourcesDirectory ) {
351
364
String execPath ;
352
365
if (VirtualFileSystemImpl .isWindows ()) {
353
- execPath = resourcesDirectory .resolve (VirtualFileSystemImpl .VFS_VENV ).resolve ("Scripts" ).resolve ("python.exe" ).toAbsolutePath ().toString ();
366
+ execPath = externalResourcesDirectory .resolve (VirtualFileSystemImpl .VFS_VENV ).resolve ("Scripts" ).resolve ("python.exe" ).toAbsolutePath ().toString ();
354
367
} else {
355
- execPath = resourcesDirectory .resolve (VirtualFileSystemImpl .VFS_VENV ).resolve ("bin" ).resolve ("python" ).toAbsolutePath ().toString ();
368
+ execPath = externalResourcesDirectory .resolve (VirtualFileSystemImpl .VFS_VENV ).resolve ("bin" ).resolve ("python" ).toAbsolutePath ().toString ();
356
369
}
357
370
358
- String srcPath = resourcesDirectory .resolve (VirtualFileSystemImpl .VFS_SRC ).toAbsolutePath ().toString ();
371
+ String srcPath = externalResourcesDirectory .resolve (VirtualFileSystemImpl .VFS_SRC ).toAbsolutePath ().toString ();
359
372
return createContextBuilder ().
360
373
// allow all IO access
361
374
allowIO (IOAccess .ALL ).
@@ -437,8 +450,9 @@ public static Path getNativeExecutablePath() {
437
450
* The structure of the created resource directory will stay the same like the embedded Python
438
451
* resources structure:
439
452
* <ul>
440
- * <li><code>${resourcesDirectory}/venv</code> - the python virtual environment location</li>
441
- * <li><code>${resourcesDirectory}/src</code> - the python sources location</li>
453
+ * <li><code>${externalResourcesDirectory}/venv</code> - the python virtual environment
454
+ * location</li>
455
+ * <li><code>${externalResourcesDirectory}/src</code> - the python sources location</li>
442
456
* </ul>
443
457
* </p>
444
458
* </p>
@@ -456,17 +470,17 @@ public static Path getNativeExecutablePath() {
456
470
* </p>
457
471
*
458
472
* @param vfs the {@link VirtualFileSystem} from which resources are to be extracted
459
- * @param resourcesDirectory the target directory to extract the resources to
473
+ * @param externalResourcesDirectory the target directory to extract the resources to
460
474
* @throws IOException if resources isn't a directory
461
475
* @see #contextBuilder(Path)
462
476
* @see VirtualFileSystem.Builder#resourceLoadingClass(Class)
463
477
*
464
478
* @since 24.2.0
465
479
*/
466
- public static void extractVirtualFileSystemResources (VirtualFileSystem vfs , Path resourcesDirectory ) throws IOException {
467
- if (Files .exists (resourcesDirectory ) && !Files .isDirectory (resourcesDirectory )) {
468
- throw new IOException (String .format ("%s has to be a directory" , resourcesDirectory .toString ()));
480
+ public static void extractVirtualFileSystemResources (VirtualFileSystem vfs , Path externalResourcesDirectory ) throws IOException {
481
+ if (Files .exists (externalResourcesDirectory ) && !Files .isDirectory (externalResourcesDirectory )) {
482
+ throw new IOException (String .format ("%s has to be a directory" , externalResourcesDirectory .toString ()));
469
483
}
470
- vfs .impl .extractResources (resourcesDirectory );
484
+ vfs .impl .extractResources (externalResourcesDirectory );
471
485
}
472
486
}
0 commit comments