Skip to content

Commit

Permalink
Upgrade Java and Python Integration Example
Browse files Browse the repository at this point in the history
  • Loading branch information
LesiaChaban committed Dec 11, 2023
1 parent 6f5c234 commit 2f99a72
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 26 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/graalpy-notebook-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,19 @@ jobs:
timeout-minutes: 40
strategy:
matrix:
include:
- version: '22.3.1' # temporarily locked to 22.3.1
java-version: '17'
java-version: ['21']
steps:
- uses: actions/checkout@v3
- uses: graalvm/setup-graalvm@v1
with:
version: ${{ matrix.version }}
java-version: ${{ matrix.java-version }}
distribution: 'graalvm'
components: 'python'
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: 'maven'
- name: Run 'graalpy-notebook-example'
run: |
cd graalpy-notebook-example
mvn --no-transfer-progress compile
./install-deps.sh
#./install-deps.sh (only for local running)
# mvn exec:java (skip running the example)
21 changes: 16 additions & 5 deletions graalpy-notebook-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@ This example demonstrates how to integrate Python in a Java application and run

### Prerequisites

- GraalVM
- [Python support](https://www.graalvm.org/latest/reference-manual/python/)
- [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 with the Python support using the [GraalVM JDK Downloader](https://github.com/graalvm/graalvm-jdk-downloader).
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
bash <(curl -sL https://get.graalvm.org/jdk) -c 'python'
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
Expand Down
6 changes: 3 additions & 3 deletions graalpy-notebook-example/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
set -u
set -o pipefail

$JAVA_HOME/bin/graalpy -Im ensurepip --upgrade --default-pip
$JAVA_HOME/bin/graalpy -m venv venv
source venv/bin/activate
VIRTUAL_ENV=${PWD}/venv
venv/bin/graalpy -m ginstall install matplotlib,Pillow,pandas
venv/bin/python -m ginstall install matplotlib Pillow pandas
41 changes: 28 additions & 13 deletions graalpy-notebook-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,30 @@
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>22.1.0</version>
<artifactId>collections</artifactId>
<version>23.1.1</version>
</dependency>
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>polyglot</artifactId>
<version>23.1.1</version>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>word</artifactId>
<version>23.1.1</version>
</dependency>
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>python</artifactId>
<version>23.1.0</version>
<type>pom</type>
</dependency>
</dependencies>
<profiles>
Expand All @@ -25,7 +41,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<version>3.1.1</version>
<executions>
<execution>
<!--
Expand All @@ -39,7 +55,7 @@
<goal>exec</goal>
</goals>
<configuration>
<executable>${env.JAVA_HOME}/bin/graalpy</executable>
<executable>${env.GRAALPY_HOME}/bin/graalpy</executable>
<arguments>
<argument>-m</argument>
<argument>venv</argument>
Expand Down Expand Up @@ -89,7 +105,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<version>3.1.1</version>
<executions>
<execution>
<id>default-cli</id>
Expand Down Expand Up @@ -117,7 +133,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<version>3.4.1</version>
<executions>
<execution>
<id>enforce-graalvm-python</id>
Expand All @@ -128,9 +144,8 @@
<configuration>
<rules>
<requireFilesExist>
<message>You must set JAVA_HOME to a GraalVM with Python installed.</message>
<files>
<file>${env.JAVA_HOME}/bin/graalpy</file>
<file>${env.GRAALPY_HOME}/bin/graalpy</file>
</files>
</requireFilesExist>
</rules>
Expand All @@ -143,10 +158,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
</plugins>
Expand Down

0 comments on commit 2f99a72

Please sign in to comment.