Skip to content

Commit

Permalink
Updates to graalpy-freeze-dependencies-guide
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-s committed Nov 5, 2024
1 parent ae44d51 commit ba65fd7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
24 changes: 21 additions & 3 deletions graalpy/graalpy-freeze-dependencies-guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ Most Python packages are hosted on [PyPI](https://pypi.org) and can be installed
The Python ecosystem has conventions about the filesystem layout of installed packages that need to be kept in mind when embedding into Java.
You can use the GraalPy plugins for Maven or Gradle to manage Python packages for you.

For Maven, add dependency on GraalPy runtime, and configure the GraalPy Maven plugin:

`pom.xml`
```xml
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>python</artifactId>
<version>24.1.1</version>
<type>pom</type>
</dependency>
```

`pom.xml`
```xml
<build>
Expand All @@ -86,6 +98,8 @@ You can use the GraalPy plugins for Maven or Gradle to manage Python packages fo
</build>
```

For Gradle, add the GraalPy plugin, configure it, and add the dependency on the GraalPy runtime:

`build.gradle.kts`
```kotlin
plugins {
Expand All @@ -99,6 +113,10 @@ plugins {
graalPy {
packages = setOf("vaderSentiment==3.3.2") //
}

dependencies {
implementation("org.graalvm.python:python:24.1.1")
}
```

❶ The `packages` section lists all Python packages optionally with [requirement specifiers](https://pip.pypa.io/en/stable/reference/requirement-specifiers/).
Expand All @@ -116,7 +134,7 @@ in a newly created [virtual environment](https://docs.python.org/3/library/venv.
```

```shell
./gradlew build
./gradlew assemble
```

If the compilation is successful, one can run the following command to get versions of all the installed Python packages if you use Maven:
Expand All @@ -135,12 +153,12 @@ If you are using Gradle, run the following command:

On macOS and Linux:
```shell
./build/generated/graalpy/resources/org.graalvm.python.vfs/venv/bin/pip3 freeze -l
./app/build/generated/graalpy/resources/org.graalvm.python.vfs/venv/bin/pip3 freeze -l
```

On Windows:
```shell
.\build\generated\graalpy\resources\org.graalvm.python.vfs\venv\Scripts\pip3.exe freeze -l
.\app\build\generated\graalpy\resources\org.graalvm.python.vfs\venv\Scripts\pip3.exe freeze -l
```

The output will look something like this:
Expand Down
16 changes: 12 additions & 4 deletions graalpy/graalpy-freeze-dependencies-guide/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ plugins {
id("org.graalvm.python") version "24.1.1"
}

// To make the paths of this reference solution (without 'app' subdirectory for sources)
// and "gradle init ..." based solution (with sources in 'app') the same for README.md
layout.buildDirectory.set(layout.projectDirectory.dir("app/build"))

if ("true".equals(System.getProperty("no.transitive.dependencies"))) {
graalPy {
packages = setOf("vaderSentiment==3.3.2") //
}
dependencies {
implementation("org.graalvm.python:python:24.1.1")
}
} else {
// The default profile shows the end result: all our transitive
// dependencies are explicitly pinned to a specific version.
Expand All @@ -20,6 +27,9 @@ if ("true".equals(System.getProperty("no.transitive.dependencies"))) {
"urllib3==2.2.2"
)
}
dependencies {
implementation("org.graalvm.python:python:24.1.1")
}
}

repositories {
Expand All @@ -29,10 +39,8 @@ repositories {
}
}

dependencies {
implementation("org.graalvm.python:python:24.1.1") //
implementation("org.graalvm.python:python-embedding:24.1.1") //
}
// This dependency is necessary only for the example Java code, not for building and running pip freeze:
dependencies.add("implementation", "org.graalvm.python:python-embedding:24.1.1")

group = "org.example"
version = "1.0-SNAPSHOT"
Expand Down
7 changes: 4 additions & 3 deletions graalpy/graalpy-freeze-dependencies-guide/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
<dependencies>
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>python</artifactId> <!---->
<artifactId>python</artifactId>
<version>24.1.1</version>
<type>pom</type> <!---->
<type>pom</type>
</dependency>

<!-- This dependency is necessary only for the example Java code, not for building and running pip freeze -->
<dependency>
<groupId>org.graalvm.python</groupId>
<artifactId>python-embedding</artifactId> <!---->
<artifactId>python-embedding</artifactId>
<version>24.1.1</version>
</dependency>
</dependencies>
Expand Down

0 comments on commit ba65fd7

Please sign in to comment.