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 `packages` section lists all Python packages optionally with [requirement specifiers](https://pip.pypa.io/en/stable/reference/requirement-specifiers/).
@@ -183,18 +179,18 @@ If you use Maven, paste them in the `pom.xml` section of the packages and wrap t
Add the required dependencies for GraalPy in the `<dependencies>` section of the POM or to the `dependencies` block in the `build.gradle.kts` file.
55
+
Add the required dependencies for GraalPy in the `<dependencies>` section of the POM file for Maven.
56
+
For Gradle, the GraalPy Gradle plugin that we will add in the next section will inject these
57
+
dependencies automatically.
56
58
57
59
`pom.xml`
58
60
```xml
@@ -72,14 +74,6 @@ Add the required dependencies for GraalPy in the `<dependencies>` section of the
72
74
</dependencies>
73
75
```
74
76
75
-
`build.gradle.kts`
76
-
```kotlin
77
-
dependencies {
78
-
implementation("org.graalvm.python:python:24.2.0") // ①
79
-
implementation("org.graalvm.python:python-embedding:24.2.0") // ③
80
-
}
81
-
```
82
-
83
77
❶ The `python` dependency is a meta-package that transitively depends on all resources and libraries to run GraalPy.
84
78
85
79
❷ Note that the `python` package is not a JAR - it is simply a `pom` that declares more dependencies.
@@ -94,37 +88,30 @@ You can use the GraalPy plugins for Maven or Gradle to manage Python packages fo
94
88
95
89
`pom.xml`
96
90
```xml
97
-
<build>
98
-
<plugins>
99
-
<plugin>
100
-
<groupId>org.graalvm.python</groupId>
101
-
<artifactId>graalpy-maven-plugin</artifactId>
102
-
<version>24.2.0</version>
103
-
<executions>
104
-
<execution>
105
-
<configuration>
106
-
<packages> <!-- ① -->
107
-
<package>qrcode==7.4.2</package>
108
-
</packages>
109
-
<pythonHome> <!-- ② -->
110
-
<includes>
111
-
</includes>
112
-
<excludes>
113
-
<exclude>.*</exclude>
114
-
</excludes>
115
-
</pythonHome>
116
-
<pythonResourcesDirectory> <!-- ③ -->
117
-
${project.basedir}/python-resources
118
-
</pythonResourcesDirectory>
119
-
</configuration>
120
-
<goals>
121
-
<goal>process-graalpy-resources</goal>
122
-
</goals>
123
-
</execution>
124
-
</executions>
125
-
</plugin>
126
-
</plugins>
127
-
</build>
91
+
<build>
92
+
<plugins>
93
+
<plugin>
94
+
<groupId>org.graalvm.python</groupId>
95
+
<artifactId>graalpy-maven-plugin</artifactId>
96
+
<version>24.2.0</version>
97
+
<configuration>
98
+
<packages> <!-- ① -->
99
+
<package>qrcode==7.4.2</package>
100
+
</packages>
101
+
<externalDirectory> <!-- ② -->
102
+
${project.basedir}/python-resources
103
+
</externalDirectory>
104
+
</configuration>
105
+
<executions>
106
+
<execution>
107
+
<goals>
108
+
<goal>process-graalpy-resources</goal>
109
+
</goals>
110
+
</execution>
111
+
</executions>
112
+
</plugin>
113
+
</plugins>
114
+
</build>
128
115
```
129
116
130
117
`build.gradle.kts`
@@ -136,21 +123,15 @@ plugins {
136
123
137
124
graalPy {
138
125
packages =setOf("qrcode==7.4.2") // ①
139
-
pythonHome { includes =setOf(); excludes =setOf(".*") } // ②
140
-
pythonResourcesDirectory = file("${project.projectDir}/python-resources") // ③
126
+
externalDirectory = file("${project.projectDir}/python-resources") // ②
141
127
}
142
128
```
143
129
144
130
❶ The `packages` section lists all Python packages optionally with [requirement specifiers](https://pip.pypa.io/en/stable/reference/requirement-specifiers/).
145
131
In this case, we install the `qrcode` package and pin it to version `7.4.2`.
146
132
147
-
<aname="external-or-embedded-stdlib-pom"></a>
148
-
❷ The GraalPy plugin can copy the Python standard library resources.
149
-
This is mainly useful when creating a [GraalVM Native Image](https://www.graalvm.org/latest/reference-manual/native-image/), a use-case that we are not going to cover right now.
150
-
We disable this by specifying that we want to exclude all standard library files matching the regular expression `.*`, i.e., all of them, from the included Python home.
❸ We can specify where the plugin should place Python files for packages and the standard library that the application will use.
134
+
❷ We can specify where the plugin should place Python files for packages that the application will use.
154
135
Omit this section if you want to include the Python packages into the Java resources (and, for example, ship them in the Jar).
155
136
[Later in the Java code](#external-or-embedded-python-code-java) we can configure the GraalPy runtime to load the package from the filesystem or from resources.
156
137
@@ -177,27 +158,21 @@ public class GraalPy {
177
158
staticVirtualFileSystem vfs;
178
159
179
160
publicstaticContextcreatePythonContext(StringpythonResourcesDirectory) { // ①
❶ [If we set the `pythonResourcesDirectory` property](#external-or-embedded-python-code-pom) in our build config, we use this factory method to tell GraalPy where that folder is at runtime.
195
174
196
-
❷ We [excluded](#external-or-embedded-stdlib-pom) all of the Python standard library from the resources in our build config.
197
-
The GraalPy VirtualFileSystem is set up to ship even the standard library in the resources.
198
-
Since we did not include any standard library, we set the `"python.PythonHome"` option to an empty string.
199
-
200
-
❸ [If we do not set the `pythonResourcesDirectory` property](#external-or-embedded-python-code-pom), the GraalPy Maven plugin will place the packages inside the Java resources.
175
+
❷ [If we do not set the `externalDirectory` property](#external-or-embedded-python-code-pom), the GraalPy Maven or Gradle plugin will place the packages inside the Java resources.
201
176
Because Python libraries assume they are running from a filesystem, not a resource location, GraalPy provides the `VirtualFileSystem`, and API to make Java resource locations available to Python code as if it were in the real filesystem.
202
177
VirtualFileSystem instances can be configured to allow different levels of through-access to the underlying host filesystem.
203
178
In this demo we use the same VirtualFileSystem instance in multiple Python contexts.
0 commit comments