You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The GraalPy Maven and Gradle plugins provide functionality to manage resources required for embedding Python in Java-based applications:
10
+
The GraalPy **Maven** and **Gradle** plugins provide functionality to manage resources required for embedding Python in Java-based applications:
11
11
12
12
This embedding relevant resources can be one of the following:
13
13
- Python application files, for example, Python sources which are part of the project.
14
14
- Third-party Python packages which can be accessed either from the projects Python sources or from Java.
15
15
- The Standard library which is necessary to make a generated native executable self-contained.
16
16
17
17
Besides physically managing and distributing this files by the plugins, it is also necessary to make them available at runtime by accordingly
18
-
configuring the GraalPy context in your Java code. `GraalPyResources.java` TODO - how link to file/javadoc? provides factory methods
19
-
to create a **GraalPy context** suitable for accessing Python embedding relevant resources with a **virtual filessystem** or from a dedicated **external directory**.
18
+
configuring the GraalPy **context** in your Java code. [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/GraalPyResources.java) provides factory methods
19
+
to create a context suitable for accessing Python embedding relevant resources with a **virtual filessystem** or from a dedicated **external directory**.
20
20
21
-
### Virtual filesystem
21
+
### Virtual Filesystem
22
22
23
23
Resource files in a Maven or Gradle project are typically located in dedicated project resource directories, and then distributed in
24
24
one application file (JAR or native image).
25
25
26
26
The GraalPy virtual filesystem can access resource files as standard Java resources and make them available to Python code running in GraalPy so
27
-
that it can use standard Python IO to access those files.
27
+
that it can use standard Python IO to access those files. In order to make this work, it is necessary for the resource files to have their resource root directory
28
+
set to `/org.graalvm.python.vfs` which then becomes the virtual filesystem root and is in python code mapped to the
29
+
virtual filesystem mount point, by default `/graalpy_vfs`. For example a python file with the real filesystem path `${project_resources_directory}/org.graalvm.python.vfs/src/foo/bar.py`
30
+
will have at runtime the path `/graalpy_vfs/src/foo/bar.py`.
28
31
29
32
Each kind of the resource files is held in a different project resource directory:
30
33
-`${project_resources_directory}/org.graalvm.python.vfs/src` - is used for Python application files. Contents of this directory are not directly managed by the plugin,
@@ -34,13 +37,12 @@ and its contents are generated and managed entirely by the plugin. Any manual ch
34
37
-`${project_generated_resources_directory}/org.graalvm.python.vfs/home` - this directory is used for the Standard library
35
38
and its contents are generated and managed entirely by the plugin. Any manual changes may be overwritten.
36
39
37
-
`GraalPyResources.java` provides factory methods to create a GraalPy context with a default or custom virtual filesystem configuration.
38
-
For more information on how to configure a virtual filesystem, refer to `VirtualFileSystem.Builder` TODO - how link to file/javadoc?.
40
+
[GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/GraalPyResources.java) provides factory methods to create a GraalPy context with a default or custom virtual filesystem configuration. For more information on how to configure a virtual filesystem, refer to [VirtualFileSystem.Builder](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/VirtualFileSystem.java).
39
41
40
-
### Resources in an external directory
42
+
### Resources in an External Directory
41
43
42
44
As an alternative to the virtual filesystem, it is also possible to configure the plugin to hold the resource files in an external directory.
43
-
`GraalPyResources.java` provides methods to create a GraalPy context preconfigured to work with a dedicated resources directory as long at it has the following structure:
45
+
[GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/GraalPyResources.java) provides methods to create a GraalPy context preconfigured to work with a dedicated resources directory as long at it has the following structure:
44
46
-`${resources_directory}/src` - is used for Python application files. Contents of this directory are not directly managed by the plugin,
45
47
only added to the final application file (JAR or native image).
46
48
-`${resources_directory}/venv` - this directory is used for the Python virtual environment holding third-party Python packages
@@ -52,7 +54,8 @@ Note, that by storing the resource files in an external directory, they are not
52
54
53
55
### GraalPy Context
54
56
55
-
Regarding the particular resource paths, a GraalPy context instance created by factory methods in `GraalPyResources` is preconfigured in the following way:
57
+
Regarding the particular resource paths, a GraalPy context instance created by factory methods in [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/GraalPyResources.java)
58
+
is preconfigured in the following way:
56
59
-`${resources_root_directory}/home` - is reserved for the GraalPy Standard Library. GraalPy context will be configured to
57
60
use this standard library as if set in `PYTHONHOME` environment variable.
58
61
-`${resources_root_directory}/venv` - is reserved for a Python virtual environment holding third-party packages.
Copy file name to clipboardExpand all lines: docs/user/README.md
+7-14Lines changed: 7 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ In order to distribute the resulting application for other systems, follow these
67
67
68
68
## Gradle
69
69
70
-
1. Create a Java application with Gradle using the command below and follow the prompts (select a build script language, selectatest framework, and so on):
70
+
1. Create a Java application with Gradle using the command below and follow the prompts (select the Groovy build script language, selectatest framework, and so on):
71
71
```bash
72
72
gradle init --type java-application \
73
73
--project-name interop \
@@ -123,28 +123,21 @@ In order to distribute the resulting application for other systems, follow these
123
123
5.1. In _app/build.gradle_:
124
124
- add the graalpy-gradle-plugin to the `plugins` section:
125
125
```
126
-
id "org.graalvm.python"
126
+
id "org.graalvm.python" version "24.2.0"
127
127
```
128
128
129
129
- configure the GraalPy Gradle plugin:
130
130
```
131
131
graalPy {
132
-
packages = ["termcolor==2.2"]
132
+
packages = ["termcolor==2.2"]
133
133
}
134
134
```
135
135
136
-
5.2, In _settings.gradle_, add the following build script configuration.
137
-
Note that all buildscript blocks must appear before any plugins blocks.
136
+
5.2, In _settings.gradle_, add the following `pluginManagement` configuration.
0 commit comments