Skip to content

Commit 00f3a25

Browse files
committed
[GR-52892] A few documentation cleanups.
1 parent 611b2d1 commit 00f3a25

3 files changed

Lines changed: 86 additions & 43 deletions

File tree

docs/user/Embedding-Build-Tools.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ This approach involves the following steps:
8989
- Smaller JAR/executable size since Python resources aren't embedded
9090

9191
To use an external directory, create your GraalPy context with:
92-
- `GraalPyResources.createContextBuilder(Path)` - Creates a context builder pointing to your external directory path
92+
- `GraalPyResources.contextBuilder(Path)` - Creates a context builder pointing to your external directory path
9393

9494
## Directory Structure
9595

@@ -229,10 +229,9 @@ To customize the lock file path, configure _graalPyLockFile_ :
229229
</configuration>
230230
```
231231

232-
> **Note:** This only changes the path (defaults to _${basedir}/graalpy.lock_).To generate the lock file, run the `lock-packages` goal.
232+
> **Note:** This only changes the path (defaults to _${basedir}/graalpy.lock_). To generate the lock file, run the `lock-packages` goal.
233233
234-
For more information of this feature, please see the
235-
[Python Dependency Management for Reproducible Builds](#python-dependency-management-for-reproducible-builds) section.
234+
For more information about dependency locking, see the [Dependency Management](#dependency-management) section.
236235

237236
## GraalPy Gradle Plugin
238237

@@ -295,8 +294,7 @@ To customize the lock file path, configure _graalPyLockFile_:
295294

296295
> **Note:** This only changes the path (defaults to _$rootDir/graalpy.lock_). To generate the lock file, run the `graalPyLockPackages` task.
297296
298-
For more information of this feature, please see the
299-
[Python Dependency Management for Reproducible Builds](#python-dependency-management-for-reproducible-builds) section.
297+
For more information about dependency locking, see the [Dependency Management](#dependency-management) section.
300298

301299
### Related Documentation
302300

docs/user/Embedding-Getting-Started.md

Lines changed: 81 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -118,45 +118,90 @@ If you prefer Gradle, here is how to set up a new project with GraalPy embedding
118118
119119
> **Note**: GraalPy's performance depends on the JDK you are using. For optimal performance, see the [Runtime Optimization Support](https://www.graalvm.org/latest/reference-manual/embed-languages/#runtime-optimization-support) guide.
120120
121-
### Adding Python Dependencies
121+
## Adding Python Dependencies
122122
123123
To use third-party Python packages like NumPy or Requests in your embedded application:
124124
125-
1. Add the GraalPy Gradle plugin and configure dependencies in _app/build.gradle_:
126-
127-
```gradle
128-
plugins {
129-
id "java"
130-
id "application"
131-
id "org.graalvm.python" version "25.0.3"
132-
}
133-
134-
graalPy {
135-
packages = ["termcolor==2.2"]
136-
}
137-
```
138-
139-
2. Update your Java code to use the Python package:
140-
141-
```java
142-
package interop;
143-
144-
import org.graalvm.polyglot.*;
145-
import org.graalvm.python.embedding.GraalPyResources;
146-
147-
class App {
148-
public static void main(String[] args) {
149-
try (Context context = GraalPyResources.contextBuilder().build()) {
150-
String src = """
151-
from termcolor import colored
152-
colored_text = colored("hello java", "red", attrs=["reverse", "blink"])
153-
print(colored_text)
154-
""";
155-
context.eval("python", src);
156-
}
157-
}
158-
}
159-
```
125+
Configure the GraalPy Maven or Gradle plugin with the packages your application needs.
126+
The plugin installs packages into a managed virtual environment, and `GraalPyResources` configures the Python context to import from it.
127+
128+
### Maven
129+
130+
Add the Python embedding dependency and GraalPy Maven plugin configuration to your _pom.xml_ file:
131+
132+
```xml
133+
<dependencies>
134+
<dependency>
135+
<groupId>org.graalvm.python</groupId>
136+
<artifactId>python-embedding</artifactId>
137+
<version>25.0.3</version>
138+
</dependency>
139+
</dependencies>
140+
141+
<build>
142+
<plugins>
143+
<plugin>
144+
<groupId>org.graalvm.python</groupId>
145+
<artifactId>graalpy-maven-plugin</artifactId>
146+
<version>25.0.3</version>
147+
<executions>
148+
<execution>
149+
<configuration>
150+
<packages>
151+
<package>termcolor==2.2</package>
152+
</packages>
153+
</configuration>
154+
<goals>
155+
<goal>process-graalpy-resources</goal>
156+
</goals>
157+
</execution>
158+
</executions>
159+
</plugin>
160+
</plugins>
161+
</build>
162+
```
163+
164+
### Gradle
165+
166+
Add the GraalPy Gradle plugin and configure dependencies in _app/build.gradle_:
167+
168+
```gradle
169+
plugins {
170+
id "java"
171+
id "application"
172+
id "org.graalvm.python" version "25.0.3"
173+
}
174+
175+
dependencies {
176+
implementation("org.graalvm.python:python-embedding:25.0.3")
177+
}
178+
179+
graalPy {
180+
packages = ["termcolor==2.2"]
181+
}
182+
```
183+
184+
Then use the Python package from Java:
185+
186+
```java
187+
package interop;
188+
189+
import org.graalvm.polyglot.*;
190+
import org.graalvm.python.embedding.GraalPyResources;
191+
192+
class App {
193+
public static void main(String[] args) {
194+
try (Context context = GraalPyResources.contextBuilder().build()) {
195+
String src = """
196+
from termcolor import colored
197+
colored_text = colored("hello java", "red", attrs=["reverse", "blink"])
198+
print(colored_text)
199+
""";
200+
context.eval("python", src);
201+
}
202+
}
203+
}
204+
```
160205
161206
For complete plugin configuration options, deployment strategies, and dependency management, see [Embedding Build Tools](Embedding-Build-Tools.md).
162207

docs/user/Native-Images-with-Python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ GraalPy supports GraalVM Native Image to generate native binaries of Java applic
44

55
## Building Executables with Python
66

7-
If you started with the [Maven archetype](Embedding-Getting-Started.md#maven), the generated _pom.xml_ file already includes the necessary configuration for creating a native executable using the [Maven plugin for Native Image building](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html).
7+
If you started with the [Maven archetype](Embedding-Getting-Started.md#maven-quick-start), the generated _pom.xml_ file already includes the necessary configuration for creating a native executable using the [Maven plugin for Native Image building](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html).
88

99
To build the application, run:
1010

0 commit comments

Comments
 (0)