-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade Java and Python Integration Example for GraalPy 23.1 unchaine…
…d integration
- Loading branch information
Showing
8 changed files
with
171 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,20 @@ | ||
# Java and Python Integration Example for GraalVM | ||
# Java and Python Integration Example | ||
|
||
This example demonstrates how to integrate Python in a Java application and run on GraalVM. | ||
|
||
### Prerequisites | ||
|
||
- [GraalVM](https://www.graalvm.org/) | ||
- [GraalPy](https://www.graalvm.org/latest/reference-manual/python/) | ||
|
||
>Note: As of GraalVM for JDK 21, the Python runtime (GraalPy) is available as a standalone distribution. | ||
## Preparation | ||
|
||
1. Download and install the latest GraalVM JDK using [SDKMAN!](https://sdkman.io/). | ||
```bash | ||
sdk install java 21.0.1-graal | ||
``` | ||
2. Download and install GraalPy using `pyenv`: | ||
```bash | ||
pyenv install graalpy-23.1.0 | ||
``` | ||
Alternatively, download a compressed GraalPy installation file appropriate for your platform from [GitHub releases](https://github.com/oracle/graalpython/releases). | ||
|
||
3. Set the `GRAALPY_HOME` environment variable: | ||
```bash | ||
export GRAALPY_HOME=/.pyenv/versions/graalpy-23.1.0 | ||
``` | ||
2. Download or clone GraalVM demos repository and navigate into the `graalpy-notebook-example` directory: | ||
```bash | ||
git clone https://github.com/graalvm/graalvm-demos | ||
``` | ||
```bash | ||
cd graalvm-demos/graalpy-notebook-example | ||
``` | ||
|
||
## Build and Run Demo | ||
|
||
1. Compile the example: | ||
```bash | ||
mvn compile | ||
``` | ||
|
||
2. Install the dependencies: | ||
2. Run the example: | ||
```bash | ||
./install-deps.sh | ||
``` | ||
|
||
3. Run the example: | ||
```bash | ||
mvn exec:java | ||
mvn exec:java -Dexec.mainClass=com.oracle.example.javapython.Main | ||
``` | ||
|
||
In the application, try loading the _test1.py_ example notebook and experiment with it. | ||
|
||
This demo works on Open JDK, Oracle JDK or GraalVM. | ||
GraalVM offers (much) better performance than the other two. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@echo off | ||
REM Invoke the GraalPy launcher through Maven, passing any arguments passed to | ||
REM this script via GRAAL_PYTHON_ARGS. To avoid having to deal with multiple | ||
REM layers of escaping, we store the arguments into GRAAL_PYTHON_ARGS delimited | ||
REM with vertical tabs. | ||
|
||
REM Since BAT files cannot easily generate vertical tabs, we create a helper | ||
REM script to do it for us. We're calling Maven soon anyway, so Java must be | ||
REM available. | ||
set JAVA="%JAVA_HOME%/bin/java" | ||
if not defined JAVA_HOME set JAVA=java | ||
echo class VTabCreator { public static void main(String[] args) { System.out.print('\013'); } } > VTabCreator.java | ||
for /f "delims=" %%i in ('%JAVA% VTabCreator.java') do set VTAB=%%i | ||
del VTabCreator.java | ||
|
||
REM Store each argument separated by vtab | ||
set GRAAL_PYTHON_ARGS= | ||
:loop | ||
set GRAAL_PYTHON_ARGS=%GRAAL_PYTHON_ARGS%%VTAB%%~1 | ||
shift /1 | ||
if not "%~1"=="" goto loop | ||
|
||
mvn -f "%~dp0pom.xml" exec:exec -Dexec.executable=java -Dexec.args="--module-path %%classpath -Dorg.graalvm.launcher.executablename=%~0 --module org.graalvm.py.launcher/com.oracle.graal.python.shell.GraalPythonMain" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
|
||
source="${BASH_SOURCE[0]}" | ||
while [ -h "$source" ] ; do | ||
prev_source="$source" | ||
source="$(readlink "$source")"; | ||
if [[ "$source" != /* ]]; then | ||
# if the link was relative, it was relative to where it came from | ||
dir="$( cd -P "$( dirname "$prev_source" )" && pwd )" | ||
source="$dir/$source" | ||
fi | ||
done | ||
location="$( cd -P "$( dirname "$source" )" && pwd )" | ||
|
||
if [ -z "$JAVA_HOME" ]; then | ||
JAVA=java | ||
else | ||
JAVA="${JAVA_HOME}/bin/java" | ||
fi | ||
|
||
for var in "$@"; do | ||
args="${args}$(printf "\v")${var}" | ||
done | ||
|
||
curdir=`pwd` | ||
export GRAAL_PYTHON_ARGS="${args}$(printf "\v")" | ||
mvn -f "${location}/pom.xml" exec:exec -Dexec.executable="${JAVA}" -Dexec.workingdir="${curdir}" -Dexec.args="--module-path %classpath '-Dorg.graalvm.launcher.executablename=$0' --module org.graalvm.py.launcher/com.oracle.graal.python.shell.GraalPythonMain" |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.