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
Copy file name to clipboardExpand all lines: docs/user/Embedding-Build-Tools.md
+50-16
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ required for embedding Python code in Java-based applications:
12
12
-*Python application files* provided by the user, for example, Python sources which are part of the project.
13
13
-*Third-party Python packages* installed by the plugin during the build according to the plugin configuration.
14
14
15
-
Apart from physically managing and deploying those files, it is also necessary to make them available in Python at runtime by configuring the **GraalPy Context** in your Java code accordingly.
15
+
Apart from physically managing and deploying those files, it is also necessary to make them available in Python at runtime by configuring the **GraalPy Context** in your Java code accordingly.
16
16
The [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/GraalPyResources.java) API provides factory methods to create a Context preconfigured for accessing Python, embedding relevant resources with a **Virtual Filesystem** or from a dedicated **external directory**.
17
17
18
18
## Deployment
@@ -22,12 +22,15 @@ There are two modes how to deploy the resources: as Java resources using the Vir
22
22
### Virtual Filesystem
23
23
24
24
The Python related resources are embedded in the application file, either in JAR or Native Image generated
25
-
executable, as standard Java resources.
26
-
The GraalPy Virtual Filesystem accesses resource files as standard Java resources and makes them available to Python code running in GraalPy.
25
+
executable, as standard Java resources.
26
+
The GraalPy Virtual Filesystem internally accesses the resource files as standard Java resources and makes them available to Python code running in GraalPy.
27
27
This is transparent to the Python code, which can use standard Python IO to access those files.
28
28
29
-
Java resource files in a Maven or Gradle project are typically located in dedicated resources directories.
30
-
All resources subdirectories named _org.graalvm.python.vfs_ are merged and mapped to a configurable Virtual Filesystem mount point at the Python side, by default `/graalpy_vfs`.
29
+
Java resource files in a Maven or Gradle project are typically located in dedicated resources directories, such as `src/main/resources`.
30
+
Moreover, there can be multiple resources directories and Maven or Gradle usually merges them.
31
+
32
+
User can choose relative Java resources path that will be made accessible in Python through the virtual filesystem,
33
+
by default it is `org.graalvm.python.vfs`. All resources subdirectories with this path are merged during build and mapped to a configurable Virtual Filesystem mount point at the Python side, by default `/graalpy_vfs`.
31
34
For example, a Python file with the real filesystem path `${project_resources_directory}/org.graalvm.python.vfs/src/foo/bar.py` will be accessible as `/graalpy_vfs/src/foo/bar.py` in Python.
32
35
33
36
Use the following [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/GraalPyResources.java)
@@ -36,20 +39,37 @@ factory methods to create GraalPy Context preconfigured for the use of the Virtu
This is also the case of the default virtual filesystem location. When a resources directory is not
56
+
a valid Java package name, such as the recommended "GRAALPY-VFS", the resources are not subject to
57
+
the encapsulation rules and do not require additional module system configuration.*
58
+
39
59
### External Directory
40
60
41
-
As an alternative to Java resources with the Virtual Filesystem, it is also possible to configure the Maven or Gradle plugin to manage the contents of an external directory, which will **not be embedded** as a Java resource into the resulting application.
42
-
A user is then responsible for the deployment of such directory.
61
+
As an alternative to Java resources with the Virtual Filesystem, it is also possible to configure the Maven or Gradle plugin to manage the contents of an external directory, which will **not be embedded** as a Java resource into the resulting application.
62
+
A user is then responsible for the deployment of such directory.
43
63
Python code will access the files directly from the real filesystem.
44
64
45
65
Use the following [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/GraalPyResources.java) factory methods to create GraalPy Context preconfigured for the use of an external directory:
46
66
*`GraalPyResources.createContextBuilder(Path)`
47
67
48
68
## Conventions
49
69
50
-
The factory methods in [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/GraalPyResources.java) rely on the following conventions, where the `${root}` is either an external directory, or a Virtual System mount point on the Python side and `${project_resources_directory}/org.graalvm.python.vfs` on the real filesystem:
70
+
The factory methods in [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/GraalPyResources.java) rely on the following conventions, where the `${root}` is either an external directory, or a Virtual System mount point on the Python side and Java resources directories, such as `${project_resources_directory}/org.graalvm.python.vfs`, on the real filesystem:
51
71
-`${root}/src`: used for Python application files. This directory will be configured as the default search path for Python module files (equivalent to `PYTHONPATH` environment variable).
52
-
-`${root}/venv`: used for the Python virtual environment holding installed third-party Python packages.
72
+
-`${root}/venv`: used for the Python virtual environment holding installed third-party Python packages.
53
73
The Context will be configured as if it is executed from this virtual environment. Notably packages installed in this
54
74
virtual environment will be automatically available for importing.
55
75
@@ -73,8 +93,8 @@ Add the plugin configuration in the `configuration` block of `graalpy-maven-plug
73
93
...
74
94
</plugin>
75
95
```
76
-
The **packages** element declares a list of third-party Python packages to be downloaded and installed by the plugin.
77
-
-The Python packages and their versions are specified as if used with `pip`:
96
+
-The **packages** element declares a list of third-party Python packages to be downloaded and installed by the plugin.
97
+
The Python packages and their versions are specified as if used with `pip`:
78
98
```xml
79
99
<configuration>
80
100
<packages>
@@ -84,11 +104,18 @@ The **packages** element declares a list of third-party Python packages to be do
84
104
...
85
105
</configuration>
86
106
```
87
-
- If the **pythonResourcesDirectory** element is specified, then the given directory is used as an [external directory](#external-directory) and no Java resources are embedded.
88
-
Remember to use the appropriate `GraalPyResources` API to create the Context.
107
+
108
+
- The **resourceDirectory** element can specify the relative [Java resource path](#java-resource-path).
109
+
Remember to use `VirtualFileSystem$Builder#resourceDirectory` when configuring the `VirtualFileSystem` in Java.
- If the **externalDirectory** element is specified, then the given directory is used as an [external directory](#external-directory) and no Java resources are embedded.
115
+
Remember to use the appropriate `GraalPyResources` API to create the Context. This element and **resourceDirectory** are mutually exclusive.
@@ -118,11 +145,18 @@ The plugin can be configured in the `graalPy` block:
118
145
...
119
146
}
120
147
```
121
-
- If the **pythonResourcesDirectory** element is specified, then the given directory is used as an [external directory](#external-directory) and no Java resources are embedded.
148
+
149
+
- The **resourceDirectory** element can specify the relative [Java resource path](#java-resource-path).
150
+
Remember to use `VirtualFileSystem$Builder#resourceDirectory` when configuring the `VirtualFileSystem` in Java.
- If the **externalDirectory** element is specified, then the given directory is used as an [external directory](#external-directory) and no Java resources are embedded.
122
156
Remember to use the appropriate `GraalPyResources` API to create the Context.
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/GRAALPY-VFS/com.oracle.graal.python.test/integration/SomeFile
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/GRAALPY-VFS/com.oracle.graal.python.test/integration/dir1/extractme
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/GRAALPY-VFS/com.oracle.graal.python.test/integration/dir1/file2
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/GRAALPY-VFS/com.oracle.graal.python.test/integration/site-packages/testpkg-nolibs/file.tso
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/GRAALPY-VFS/com.oracle.graal.python.test/integration/site-packages/testpkg.libs/dir/dir/file1.tso
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/GRAALPY-VFS/com.oracle.graal.python.test/integration/site-packages/testpkg.libs/dir/dir/file2.tso
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/GRAALPY-VFS/com.oracle.graal.python.test/integration/site-packages/testpkg.libs/dir/file1.tso
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/GRAALPY-VFS/com.oracle.graal.python.test/integration/site-packages/testpkg.libs/dir/file2.tso
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/GRAALPY-VFS/com.oracle.graal.python.test/integration/site-packages/testpkg.libs/dir/nofilterfile
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/GRAALPY-VFS/com.oracle.graal.python.test/integration/site-packages/testpkg.libs/file1.tso
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/GRAALPY-VFS/com.oracle.graal.python.test/integration/site-packages/testpkg.libs/file2.tso
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/GRAALPY-VFS/com.oracle.graal.python.test/integration/site-packages/testpkg/file.tso
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/test/integration/GraalPyResourcesUtilsTests.java
+1
Original file line number
Diff line number
Diff line change
@@ -51,6 +51,7 @@
51
51
* Siple copy of GraalPyResourcesTests to test also the deprecated
0 commit comments