Skip to content

Commit 7dd9c2c

Browse files
committed
[GR-66152][GR-64568] Run tests for GraalPy in polyglot isolates.
PullRequest: graalpython/3853
2 parents b993f30 + d35839b commit 7dd9c2c

File tree

46 files changed

+470
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+470
-295
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "7be7c92b7ccf259703be8e90dc74d9b6034f535d" }
1+
{ "overlay": "eed61bcd1e6a728edbbe22e323ca383f179faeb2" }

docs/user/Embedding-Build-Tools.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,22 @@ Remember to use the appropriate `GraalPyResources` API to create the Context. Th
161161
...
162162
</configuration>
163163
```
164-
164+
165+
- If you want to remove packages that are only needed during venv creation but not at runtime, such as setuptools or pip, you can use e.g. the `maven-jar-plugin`:
166+
```xml
167+
<plugin>
168+
<groupId>org.apache.maven.plugins</groupId>
169+
<artifactId>maven-jar-plugin</artifactId>
170+
<version>3.4.2</version>
171+
<configuration>
172+
<excludes>
173+
<exclude>**/site-packages/pip*/**</exclude>
174+
<exclude>**/site-packages/setuptools*/**</exclude>
175+
</excludes>
176+
</configuration>
177+
</plugin>
178+
```
179+
165180
### Locking Python Packages
166181
To lock the dependency tree of the specified Python packages, execute the GraalPy plugin goal `org.graalvm.python:graalpy-maven-plugin:lock-packages`.
167182
```bash

graalpython/com.oracle.graal.python.test.integration/pom.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ Additionally, one can change the polyglot artifacts version with
150150
</repository>
151151
</repositories>
152152
</profile>
153+
<profile>
154+
<id>isolate</id>
155+
<activation>
156+
<property>
157+
<name>polyglot.engine.SpawnIsolate</name>
158+
</property>
159+
</activation>
160+
<dependencies>
161+
<dependency>
162+
<groupId>org.graalvm.polyglot</groupId>
163+
<artifactId>python-isolate</artifactId>
164+
<version>${com.oracle.graal.python.test.polyglot.version}</version>
165+
<scope>runtime</scope>
166+
<type>pom</type>
167+
</dependency>
168+
</dependencies>
169+
</profile>
153170
</profiles>
154171

155172
<dependencies>
@@ -160,7 +177,7 @@ Additionally, one can change the polyglot artifacts version with
160177
</dependency>
161178
<dependency>
162179
<groupId>org.graalvm.polyglot</groupId>
163-
<artifactId>python-community</artifactId>
180+
<artifactId>python</artifactId>
164181
<version>${com.oracle.graal.python.test.polyglot.version}</version>
165182
<scope>runtime</scope>
166183
<type>pom</type>

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/EngineOptionsTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -53,11 +53,12 @@ public class EngineOptionsTests {
5353
@Test
5454
public void engineOptions() {
5555
assumeFalse(IS_WINDOWS);
56-
Engine engine = Engine.newBuilder().build();
56+
Engine engine = Engine.create("python");
5757

5858
assertEquals("java", doit(engine, null));
5959
assertEquals("java", doit(engine, "java"));
6060
assertEquals("native", doit(engine, "native"));
61+
engine.close();
6162
}
6263

6364
private static String doit(Engine engine, String backend) {

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/PythonTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class PythonTests {
5858
static final PrintStream errStream = new PrintStream(errArray);
5959
static final PrintStream outStream = new PrintStream(outArray);
6060

61-
private static final Engine engine = Engine.newBuilder().out(PythonTests.outStream).err(PythonTests.errStream).build();
61+
private static final Engine engine = Engine.newBuilder("python").out(outStream).err(errStream).build();
6262
private static Context context = null;
6363

6464
public static Context enterContext(String... newArgs) {

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/advanced/MultiContextTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,18 @@
4949
public class MultiContextTest extends PythonTests {
5050
@Test
5151
public void testSharingWithMemoryview() {
52-
Engine engine = Engine.newBuilder().build();
52+
Engine engine = Engine.create("python");
5353
for (int i = 0; i < 10; i++) {
5454
try (Context context = newContext(engine)) {
5555
context.eval("python", "memoryview(b'abc')");
5656
}
5757
}
58+
engine.close();
5859
}
5960

6061
@Test
6162
public void testTryCatch() {
62-
Engine engine = Engine.newBuilder().build();
63+
Engine engine = Engine.create("python");
6364
for (int i = 0; i < 10; i++) {
6465
try (Context context = newContext(engine)) {
6566
context.eval("python", "last_val = -1\n" +
@@ -72,6 +73,7 @@ public void testTryCatch() {
7273
"last_val");
7374
}
7475
}
76+
engine.close();
7577
}
7678

7779
private static Context newContext(Engine engine) {

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/advanced/NativeExtTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static void setUpClass() {
6363
@Test
6464
public void testSharingErrorWithCpythonSre() throws InterruptedException {
6565
// The first context is the one that will use native extensions
66-
Engine engine = Engine.newBuilder().build();
66+
Engine engine = Engine.create("python");
6767
Context cextContext = newContext(engine).option("python.IsolateNativeModules", "true").build();
6868
try {
6969
cextContext.eval("python", "import _cpython_sre\nassert _cpython_sre.ascii_tolower(88) == 120\n");
@@ -104,6 +104,7 @@ public void testSharingErrorWithCpythonSre() throws InterruptedException {
104104

105105
} finally {
106106
cextContext.close(true);
107+
engine.close();
107108
}
108109
}
109110

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/advanced/ResourcesTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -45,6 +45,7 @@
4545
import java.io.File;
4646

4747
import org.graalvm.polyglot.Context;
48+
import org.graalvm.polyglot.Engine;
4849
import org.graalvm.polyglot.io.IOAccess;
4950
import org.junit.Before;
5051
import org.junit.Test;
@@ -72,7 +73,8 @@ public void testResourcesAsHome() {
7273

7374
@Test
7475
public void testResourcesAlwaysAllowReading() {
75-
try (Context context = Context.newBuilder("python").allowIO(IOAccess.NONE).option("python.PythonHome", "/path/that/does/not/exist").build()) {
76+
try (Engine engine = Engine.create("python");
77+
Context context = Context.newBuilder("python").engine(engine).allowIO(IOAccess.NONE).option("python.PythonHome", "/path/that/does/not/exist").build()) {
7678
String foundHome = context.eval("python", "import email; email.__spec__.origin").asString();
7779
assertTrue(foundHome, foundHome.contains("python" + File.separator + "python-home"));
7880
}

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/advanced/ShutdownTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.concurrent.atomic.AtomicReference;
4646

4747
import org.graalvm.polyglot.Context;
48+
import org.graalvm.polyglot.Engine;
4849
import org.graalvm.polyglot.PolyglotException;
4950
import org.junit.Assert;
5051
import org.junit.Assume;
@@ -161,7 +162,7 @@ public void testJavaThreadNotExecutingPythonAnymore() throws InterruptedExceptio
161162
}
162163

163164
private static Context createContext() {
164-
return Context.newBuilder().allowExperimentalOptions(true).allowAllAccess(true).option("python.IsolateNativeModules", "true").build();
165+
return Context.newBuilder().engine(Engine.create("python")).allowExperimentalOptions(true).allowAllAccess(true).option("python.IsolateNativeModules", "true").build();
165166
}
166167

167168
private static void loadNativeExtension(Context context) {

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/basic/HelloWorldTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -31,6 +31,7 @@
3131
import java.io.PrintStream;
3232

3333
import org.graalvm.polyglot.Context;
34+
import org.graalvm.polyglot.Engine;
3435
import org.junit.Test;
3536

3637
import com.oracle.graal.python.test.integration.PythonTests;
@@ -53,7 +54,7 @@ public void helloworldAgain() {
5354
public void usesFrozenModules() {
5455
final ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
5556
final PrintStream printStream = new PrintStream(byteArray);
56-
try (Context c = Context.newBuilder().option("log.python.level", "FINE").out(printStream).err(printStream).build()) {
57+
try (Context c = Context.newBuilder().engine(Engine.newBuilder("python").out(printStream).err(printStream).build()).option("log.python.level", "FINE").build()) {
5758
c.initialize("python");
5859
}
5960
String result = byteArray.toString().replaceAll("\r\n", "\n");

0 commit comments

Comments
 (0)