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
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,14 @@
1
1
# Embedding Build Tools
2
2
3
+
**Note: The GraalPy build tools are being developed as part of the GraalPy Extensions project in a separate [repository](https://github.com/oracle/graalpy-extensions) on GitHub.**
4
+
3
5
The GraalPy **Maven** and **Gradle** plugins provide functionality to manage Python related resources
4
6
required for embedding Python code in Java-based applications:
5
7
-*Python application files* provided by the user, for example, Python sources which are part of the project.
6
8
-*Third-party Python packages* installed by the plugin during the build according to the plugin configuration.
7
9
8
10
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.
9
-
The [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/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**.
11
+
The [GraalPyResources](https://github.com/oracle/graalpy-extensions/blob/main/org.graalvm.python.embedding/src/main/java/org/graalvm/python/embedding/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**.
10
12
11
13
## Deployment
12
14
@@ -26,7 +28,7 @@ User can choose relative Java resources path that will be made accessible in Pyt
26
28
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`.
27
29
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.
28
30
29
-
Use the following [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java)
31
+
Use the following [GraalPyResources](https://github.com/oracle/graalpy-extensions/blob/main/org.graalvm.python.embedding/src/main/java/org/graalvm/python/embedding/GraalPyResources.java)
30
32
factory methods to create GraalPy Context preconfigured for the use of the Virtual Filesystem:
31
33
*`GraalPyResources.createContext()`
32
34
*`GraalPyResources.contextBuilder()`
@@ -49,16 +51,16 @@ This is also the case of the default virtual filesystem location.
49
51
When a resources directory is not a valid Java package name, such as the recommended "GRAALPY-VFS", the resources are not subject to the encapsulation rules and do not require additional module system configuration.*
50
52
51
53
#### Extracting files from Virtual Filesystem
52
-
Normally, Virtual Filesystem resources are loaded like java resources, but there are cases when files need to be accessed
54
+
Normally, Virtual Filesystem resources are loaded like java resources, but there are cases when files need to be accessed
53
55
outside the Truffle sandbox, e.g. Python C extension files which need to be accessed by the operating system loader.
54
56
55
-
By default, files which are of type `.so`, `.dylib`, `.pyd`, `.dll`, or `.ttf`, are automatically extracted to a temporary directory
57
+
By default, files which are of type `.so`, `.dylib`, `.pyd`, `.dll`, or `.ttf`, are automatically extracted to a temporary directory
56
58
in the real filesystem when accessed for the first time and the Virtual Filesystem then delegates to those real files.
57
59
58
60
The default extract rule can be enhanced using the `VirtualFileSystem$Builder#extractFilter` API.
59
61
60
-
Alternatively, it is possible to extract all Python resources into a user-defined directory before creating a GraalPy
61
-
context, and then configure the context to use that directory. Please refer to the following [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java)
62
+
Alternatively, it is possible to extract all Python resources into a user-defined directory before creating a GraalPy
63
+
context, and then configure the context to use that directory. Please refer to the following [GraalPyResources](https://github.com/oracle/graalpy-extensions/blob/main/org.graalvm.python.embedding/src/main/java/org/graalvm/python/embedding/GraalPyResources.java)
@@ -69,12 +71,12 @@ As an alternative to Java resources with the Virtual Filesystem, it is also poss
69
71
A user is then responsible for the deployment of such directory.
70
72
Python code will access the files directly from the real filesystem.
71
73
72
-
Use the following [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java) factory methods to create GraalPy Context preconfigured for the use of an external directory:
74
+
Use the following [GraalPyResources](https://github.com/oracle/graalpy-extensions/blob/main/org.graalvm.python.embedding/src/main/java/org/graalvm/python/embedding/GraalPyResources.java) factory methods to create GraalPy Context preconfigured for the use of an external directory:
73
75
*`GraalPyResources.createContextBuilder(Path)`
74
76
75
77
## Conventions
76
78
77
-
The factory methods in [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/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:
79
+
The factory methods in [GraalPyResources](https://github.com/oracle/graalpy-extensions/blob/main/org.graalvm.python.embedding/src/main/java/org/graalvm/python/embedding/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:
78
80
-`${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).
79
81
-`${root}/venv`: used for the Python virtual environment holding installed third-party Python packages.
80
82
The Context will be configured as if it is executed from this virtual environment. Notably packages installed in this
@@ -146,7 +148,7 @@ The Python packages and their versions are specified as if used with `pip`:
146
148
...
147
149
</configuration>
148
150
```
149
-
151
+
150
152
- The **resourceDirectory** element can specify the relative [Java resource path](#java-resource-path).
151
153
Remember to use `VirtualFileSystem$Builder#resourceDirectory` when configuring the `VirtualFileSystem` in Java.
152
154
```xml
@@ -178,11 +180,11 @@ Remember to use the appropriate `GraalPyResources` API to create the Context. Th
178
180
```
179
181
180
182
### Locking Python Packages
181
-
To lock the dependency tree of the specified Python packages, execute the GraalPy plugin goal `org.graalvm.python:graalpy-maven-plugin:lock-packages`.
183
+
To lock the dependency tree of the specified Python packages, execute the GraalPy plugin goal `org.graalvm.python:graalpy-maven-plugin:lock-packages`.
0 commit comments