Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Java and Python Integration Example #225

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't install 'python' component on GraalVM for JDK 21. We should keep this demo testing on java-version: '17'.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's one option. As I understand, you need to install GraalPy JVM standalone 23.1.1 and export GRAALPY_HOME to to using GitHub actions workflow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide to update this demo to a newer version of GraalPy, we no longer can/should use the setup-graalvm action, but you may be able to use setup-python, which supports GraalPy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This demo is about an embedding, it should not install GraalPy in the action at all, only through the pom dependency

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already graalpy-23.1.1

```
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this file should be removed

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this entire pom.xml needs to be rewritten to use the graalpy-maven-plugin for 24.0, is it worth updating now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to publish our graalpy-maven-plugin? That's great news if so!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it goes out with the next release

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So @olyagpl we wait and refactor the Maven plugin for GraalPy (when it comes out)? Leave GitHub workflow running with JDK 17?

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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to change the env name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn’t change the env name. The name of env is here <argument>venv</argument>.

<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