Skip to content

Commit 3b46423

Browse files
committed
Improve the GraalPyResources docs
1 parent ce7f385 commit 3b46423

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ private GraalPyResources() {
198198
* location</li>
199199
* <li><code>/org.graalvm.python.vfs/src</code> - is set as the python sources location</li>
200200
* </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}.
202207
*
203208
* @return a new {@link Context} instance
204209
* @since 24.2.0
@@ -233,6 +238,12 @@ public static Context createContext() {
233238
* }
234239
* }
235240
* </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}.
236247
*
237248
* @see <a href=
238249
* "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) {
308319

309320
/**
310321
* 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.
312323
* <p>
313324
* Following resource paths are preconfigured:
314325
* <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
316329
* location</li>
317-
* <li><code>${resourcesDirectory}/src</code> - is set as the python sources location</li>
318330
* </ul>
319331
* </p>
320332
* <p>
@@ -343,19 +355,20 @@ public static Context.Builder contextBuilder(VirtualFileSystem vfs) {
343355
* </ul>
344356
* </p>
345357
*
346-
* @param resourcesDirectory the root directory with GraalPy specific embedding resources
358+
* @param externalResourcesDirectory the root directory with GraalPy specific embedding
359+
* resources
347360
* @return a new {@link org.graalvm.polyglot.Context.Builder} instance
348361
* @since 24.2.0
349362
*/
350-
public static Context.Builder contextBuilder(Path resourcesDirectory) {
363+
public static Context.Builder contextBuilder(Path externalResourcesDirectory) {
351364
String execPath;
352365
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();
354367
} 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();
356369
}
357370

358-
String srcPath = resourcesDirectory.resolve(VirtualFileSystemImpl.VFS_SRC).toAbsolutePath().toString();
371+
String srcPath = externalResourcesDirectory.resolve(VirtualFileSystemImpl.VFS_SRC).toAbsolutePath().toString();
359372
return createContextBuilder().
360373
// allow all IO access
361374
allowIO(IOAccess.ALL).
@@ -437,8 +450,9 @@ public static Path getNativeExecutablePath() {
437450
* The structure of the created resource directory will stay the same like the embedded Python
438451
* resources structure:
439452
* <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>
442456
* </ul>
443457
* </p>
444458
* </p>
@@ -456,17 +470,17 @@ public static Path getNativeExecutablePath() {
456470
* </p>
457471
*
458472
* @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
460474
* @throws IOException if resources isn't a directory
461475
* @see #contextBuilder(Path)
462476
* @see VirtualFileSystem.Builder#resourceLoadingClass(Class)
463477
*
464478
* @since 24.2.0
465479
*/
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()));
469483
}
470-
vfs.impl.extractResources(resourcesDirectory);
484+
vfs.impl.extractResources(externalResourcesDirectory);
471485
}
472486
}

0 commit comments

Comments
 (0)