Skip to content

Commit 7886cf4

Browse files
committed
[GR-57413] Cleanup of exposed embedding APIs.
PullRequest: graalpython/3552
2 parents 0d362b1 + 86ea54d commit 7886cf4

File tree

7 files changed

+1512
-1336
lines changed

7 files changed

+1512
-1336
lines changed
Lines changed: 30 additions & 400 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/utils/test/VirtualFileSystemTest.java

Lines changed: 489 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,17 @@
141141
* </ul>
142142
* </p>
143143
*
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+
*
144148
* @see VirtualFileSystem
145149
* @see VirtualFileSystem.Builder
146150
*/
147-
// TODO: link to user guide
148-
public class GraalPyResources {
151+
public final class GraalPyResources {
152+
153+
private GraalPyResources() {
154+
}
149155

150156
/**
151157
* Creates a GraalPy context preconfigured with a {@link VirtualFileSystem} and other GraalPy
@@ -194,9 +200,10 @@ public static Context createContext() {
194200
* }
195201
* }
196202
* </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>
198206
*/
199-
// TODO add link to python options doc
200207
public static Context.Builder contextBuilder() {
201208
VirtualFileSystem vfs = VirtualFileSystem.create();
202209
return contextBuilder(vfs);
@@ -252,17 +259,17 @@ public static Context.Builder contextBuilder() {
252259
public static Context.Builder contextBuilder(VirtualFileSystem vfs) {
253260
return createContextBuilder().
254261
// 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()).
256263
// The sys.executable path, a virtual path that is used by the interpreter
257264
// 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")).
259266
// Set the python home to be read from the embedded resources
260-
option("python.PythonHome", vfs.vfsHomePath()).
267+
option("python.PythonHome", vfs.impl.vfsHomePath()).
261268
// Set python path to point to sources stored in
262269
// src/main/resources/org.graalvm.python.vfs/src
263-
option("python.PythonPath", vfs.vfsSrcPath()).
270+
option("python.PythonPath", vfs.impl.vfsSrcPath()).
264271
// pass the path to be executed
265-
option("python.InputFilePath", vfs.vfsSrcPath());
272+
option("python.InputFilePath", vfs.impl.vfsSrcPath());
266273
}
267274

268275
/**
@@ -308,14 +315,14 @@ public static Context.Builder contextBuilder(VirtualFileSystem vfs) {
308315
*/
309316
public static Context.Builder contextBuilder(Path resourcesDirectory) {
310317
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();
313320
} 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();
315322
}
316323

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();
319326
return createContextBuilder().
320327
// allow all IO access
321328
allowIO(IOAccess.ALL).
@@ -362,7 +369,7 @@ private static Context.Builder createContextBuilder() {
362369
* <p>
363370
* <b>Example </b> creating a GraalPy context precofigured with an external resource directory
364371
* located next to a native image executable.
365-
*
372+
*
366373
* <pre>
367374
* Path resourcesDir = GraalPyResources.getNativeExecutablePath().getParent().resolve("python-resources");
368375
* try (Context context = GraalPyResources.contextBuilder(resourcesDir).build()) {
@@ -405,7 +412,7 @@ public static Path getNativeExecutablePath() {
405412
* </p>
406413
* <p>
407414
* <b>Example</b>
408-
*
415+
*
409416
* <pre>
410417
* Path resourcesDir = Path.of(System.getProperty("user.home"), ".cache", "my.java.python.app.resources");
411418
* FileSystem fs = GraalPyResources.createVirtualFileSystem();
@@ -423,6 +430,6 @@ public static void extractVirtualFileSystemResources(VirtualFileSystem vfs, Path
423430
if (Files.exists(resourcesDirectory) && !Files.isDirectory(resourcesDirectory)) {
424431
throw new IOException(String.format("%s has to be a directory", resourcesDirectory.toString()));
425432
}
426-
vfs.extractResources(resourcesDirectory);
433+
vfs.impl.extractResources(resourcesDirectory);
427434
}
428435
}

0 commit comments

Comments
 (0)