141
141
* </ul>
142
142
* </p>
143
143
*
144
+ * For <b>more examples</b> on how to use this class refer to
145
+ * <a href="https://github.com/graalvm/graal-languages-demos/tree/main/graalpy">GraalPy Demos and
146
+ * Guides</a>.
147
+ *
144
148
* @see VirtualFileSystem
145
149
* @see VirtualFileSystem.Builder
146
150
*/
147
- // TODO: link to user guide
148
- public class GraalPyResources {
151
+ public final class GraalPyResources {
152
+
153
+ private GraalPyResources () {
154
+ }
149
155
150
156
/**
151
157
* Creates a GraalPy context preconfigured with a {@link VirtualFileSystem} and other GraalPy
@@ -194,9 +200,10 @@ public static Context createContext() {
194
200
* }
195
201
* }
196
202
* </pre>
197
- *
203
+ *
204
+ * @see <a href=
205
+ * "https://github.com/oracle/graalpython/blob/master/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java">PythonOptions</a>
198
206
*/
199
- // TODO add link to python options doc
200
207
public static Context .Builder contextBuilder () {
201
208
VirtualFileSystem vfs = VirtualFileSystem .create ();
202
209
return contextBuilder (vfs );
@@ -252,17 +259,17 @@ public static Context.Builder contextBuilder() {
252
259
public static Context .Builder contextBuilder (VirtualFileSystem vfs ) {
253
260
return createContextBuilder ().
254
261
// allow access to the virtual and the host filesystem, as well as sockets
255
- allowIO (IOAccess .newBuilder ().allowHostSocketAccess (true ).fileSystem (vfs ).build ()).
262
+ allowIO (IOAccess .newBuilder ().allowHostSocketAccess (true ).fileSystem (vfs . impl ).build ()).
256
263
// The sys.executable path, a virtual path that is used by the interpreter
257
264
// to discover packages
258
- option ("python.Executable" , vfs .vfsVenvPath () + (VirtualFileSystem .isWindows () ? "\\ Scripts\\ python.exe" : "/bin/python" )).
265
+ option ("python.Executable" , vfs .impl . vfsVenvPath () + (VirtualFileSystemImpl .isWindows () ? "\\ Scripts\\ python.exe" : "/bin/python" )).
259
266
// Set the python home to be read from the embedded resources
260
- option ("python.PythonHome" , vfs .vfsHomePath ()).
267
+ option ("python.PythonHome" , vfs .impl . vfsHomePath ()).
261
268
// Set python path to point to sources stored in
262
269
// src/main/resources/org.graalvm.python.vfs/src
263
- option ("python.PythonPath" , vfs .vfsSrcPath ()).
270
+ option ("python.PythonPath" , vfs .impl . vfsSrcPath ()).
264
271
// pass the path to be executed
265
- option ("python.InputFilePath" , vfs .vfsSrcPath ());
272
+ option ("python.InputFilePath" , vfs .impl . vfsSrcPath ());
266
273
}
267
274
268
275
/**
@@ -308,14 +315,14 @@ public static Context.Builder contextBuilder(VirtualFileSystem vfs) {
308
315
*/
309
316
public static Context .Builder contextBuilder (Path resourcesDirectory ) {
310
317
String execPath ;
311
- if (VirtualFileSystem .isWindows ()) {
312
- execPath = resourcesDirectory .resolve (VirtualFileSystem .VFS_VENV ).resolve ("Scripts" ).resolve ("python.exe" ).toAbsolutePath ().toString ();
318
+ if (VirtualFileSystemImpl .isWindows ()) {
319
+ execPath = resourcesDirectory .resolve (VirtualFileSystemImpl .VFS_VENV ).resolve ("Scripts" ).resolve ("python.exe" ).toAbsolutePath ().toString ();
313
320
} else {
314
- execPath = resourcesDirectory .resolve (VirtualFileSystem .VFS_VENV ).resolve ("bin" ).resolve ("python" ).toAbsolutePath ().toString ();
321
+ execPath = resourcesDirectory .resolve (VirtualFileSystemImpl .VFS_VENV ).resolve ("bin" ).resolve ("python" ).toAbsolutePath ().toString ();
315
322
}
316
323
317
- String homePath = resourcesDirectory .resolve (VirtualFileSystem .VFS_HOME ).toAbsolutePath ().toString ();
318
- String srcPath = resourcesDirectory .resolve (VirtualFileSystem .VFS_SRC ).toAbsolutePath ().toString ();
324
+ String homePath = resourcesDirectory .resolve (VirtualFileSystemImpl .VFS_HOME ).toAbsolutePath ().toString ();
325
+ String srcPath = resourcesDirectory .resolve (VirtualFileSystemImpl .VFS_SRC ).toAbsolutePath ().toString ();
319
326
return createContextBuilder ().
320
327
// allow all IO access
321
328
allowIO (IOAccess .ALL ).
@@ -362,7 +369,7 @@ private static Context.Builder createContextBuilder() {
362
369
* <p>
363
370
* <b>Example </b> creating a GraalPy context precofigured with an external resource directory
364
371
* located next to a native image executable.
365
- *
372
+ *
366
373
* <pre>
367
374
* Path resourcesDir = GraalPyResources.getNativeExecutablePath().getParent().resolve("python-resources");
368
375
* try (Context context = GraalPyResources.contextBuilder(resourcesDir).build()) {
@@ -405,7 +412,7 @@ public static Path getNativeExecutablePath() {
405
412
* </p>
406
413
* <p>
407
414
* <b>Example</b>
408
- *
415
+ *
409
416
* <pre>
410
417
* Path resourcesDir = Path.of(System.getProperty("user.home"), ".cache", "my.java.python.app.resources");
411
418
* FileSystem fs = GraalPyResources.createVirtualFileSystem();
@@ -423,6 +430,6 @@ public static void extractVirtualFileSystemResources(VirtualFileSystem vfs, Path
423
430
if (Files .exists (resourcesDirectory ) && !Files .isDirectory (resourcesDirectory )) {
424
431
throw new IOException (String .format ("%s has to be a directory" , resourcesDirectory .toString ()));
425
432
}
426
- vfs .extractResources (resourcesDirectory );
433
+ vfs .impl . extractResources (resourcesDirectory );
427
434
}
428
435
}
0 commit comments