Skip to content

Commit 2eed308

Browse files
committed
[GR-65639][GR-67183][GR-59702] Multiple smaller fixes for release.
PullRequest: graalpython/3909
2 parents db78ed6 + a7672c0 commit 2eed308

File tree

22 files changed

+334
-225
lines changed

22 files changed

+334
-225
lines changed

ci.jsonnet

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@
303303
"python-unittest-retagger": ut_retagger + platform_spec(no_jobs) + platform_spec({
304304
"linux:amd64:jdk-latest" : weekly + t("20:00:00"),
305305
"linux:aarch64:jdk-latest" : weekly + t("20:00:00"),
306-
"darwin:amd64:jdk-latest" : weekly + t("20:00:00"),
307306
"darwin:aarch64:jdk-latest" : weekly + t("20:00:00"),
308307
"windows:amd64:jdk-latest" : weekly + t("20:00:00"),
309308
}),

docs/site/01-docs.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ permalink: docs/
88
{% gfm_docs ../user/Python-Runtime.md %}
99
{% gfm_docs ../user/Performance.md %}
1010
{% gfm_docs ../user/Python-on-JVM.md %}
11+
12+
<h3 id="python-context-options">
13+
<a href="#python-context-options" class="anchor-link">Python Context Options</a>
14+
</h3>
15+
Below are the options you can set on contexts for GraalPy.
16+
{% python_options ../../graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java %}
17+
1118
{% gfm_docs ../user/Native-Images-with-Python.md %}
1219
{% gfm_docs ../user/Python-Standalone-Applications.md %}
1320
{% gfm_docs ../user/Interoperability.md %}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
require 'cgi'
2+
require 'kramdown'
3+
require 'kramdown-parser-gfm'
4+
5+
module GraalPy
6+
class PythonOptions < Liquid::Tag
7+
def initialize(tag_name, text, tokens)
8+
super
9+
@text = text.strip
10+
end
11+
12+
def render(context)
13+
content = File.read(@text)
14+
options = {}
15+
16+
regexp = /
17+
^(\s*@EngineOption\s*)? # Optional @EngineOption
18+
\s*@Option\s*\( # @Option(
19+
(.*?) # non-greedy match content
20+
\)\s*(?:\/\/)?\s* # )
21+
public\s+static\s+final\s+OptionKey<[^>]+>\s+(\w+) # field name (e.g. InitialLocale)
22+
/mx
23+
24+
help_regexp = /
25+
help\s*=\s*((?:"[^"]*"\s*(?:\+\s*"[^"]*"\s*)*)) # help = "..."+ "...",
26+
/mx
27+
28+
stability_regexp = /stability\s*=\s*OptionStability\.(\w+)/
29+
30+
category_regexp = /category\s*=\s*OptionCategory\.(\w+)/
31+
32+
usage_regexp = /usageSyntax\s*=\s*((?:"[^"]*"\s*(?:\+\s*"[^"]*"\s*)*))/
33+
34+
content.scan(regexp) do |engine_option, content, field|
35+
engine_option = !!engine_option
36+
37+
help = content.match(help_regexp)
38+
help = help[1].scan(/"([^"]*)"/).flatten.join(" ").gsub(/\s+/, " ").strip if help
39+
40+
stable = content.match(stability_regexp)
41+
stable = stable[1] == "STABLE" if stable
42+
43+
category = content.match(category_regexp)
44+
category = category[1] if category
45+
46+
usage = content.match(usage_regexp)
47+
usage = usage[1].scan(/"([^"]*)"/).flatten.join(" ").gsub(/\s+/, " ").strip if usage
48+
49+
if help && !help.empty?
50+
help << "." unless help.end_with? "."
51+
help = CGI::escapeHTML help
52+
help << " Accepts: <code>#{CGI::escapeHTML usage}</code>" if usage and !usage.empty?
53+
options[field] = { help: help, category: category, stable: stable, engine_option: engine_option }
54+
end
55+
end
56+
57+
doc_content = options.select do |name, opt|
58+
opt[:stable] && ["USER", "EXPERT"].include?(opt[:category])
59+
end.sort_by do |name, opt|
60+
[opt[:category] == "USER" ? 0 : 1, name.downcase]
61+
end.map do |name, opt|
62+
<<~HTML
63+
<p>
64+
<strong>#{name}</strong>
65+
#{' (Has to be the same for all Contexts in an Engine)' if opt[:engine_option]}
66+
</p>
67+
<p>
68+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#{opt[:help]}
69+
</p>
70+
HTML
71+
end.join("\n")
72+
end
73+
end
74+
end
75+
76+
Liquid::Template.register_tag('python_options', GraalPy::PythonOptions)

docs/user/Troubleshooting.md

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
11
# GraalPy Troubleshooting
22

3-
[[TOC]]
4-
53
## GraalPy Embedding
64

7-
#### VirtualFileSystem cannot load a file
5+
### VirtualFileSystem cannot load a file
6+
87
There are situations where a file cannot be loaded even though it is part of the Virtual Filesystem resources.
9-
GraalPy tries to prevent such situations by automatically [extracting](Embedding-Build-Tools.md#extracting-files-from-virtual-filesystem)
8+
GraalPy tries to prevent such situations by automatically [extracting](Embedding-Build-Tools.md#extracting-files-from-virtual-filesystem)
109
some well known files to the real filesystem, but if you see an error like:
10+
11+
```bash
12+
ImportError: cannot load /graalpy_vfs/venv/lib/python3.11/site-packages/_cffi_backend.graalpy250dev09433ef706-311-native-aarch64-darwin.so:
13+
NFIUnsatisfiedLinkError: dlopen(/graalpy_vfs/venv/lib/python3.11/site-packages/_cffi_backend.graalpy250dev09433ef706-311-native-aarch64-darwin.so, 0x0002):
1114
```
12-
ImportError: cannot load /graalpy_vfs/venv/lib/python3.11/site-packages/_cffi_backend.graalpy250dev09433ef706-311-native-aarch64-darwin.so:
13-
NFIUnsatisfiedLinkError: dlopen(/graalpy_vfs/venv/lib/python3.11/site-packages/_cffi_backend.graalpy250dev09433ef706-311-native-aarch64-darwin.so, 0x0002):
14-
```
15+
1516
then the default behavior did not work as intended.
1617

1718
Depending on how you [deploy Python resources](Embedding-Build-Tools.md#deployment) in your application, you can try one of the following:
1819
- if you need to package resources within your Jar or Native Image executable:
19-
- if the problematic file is not one of the following types: `.so`, `.dylib`, `.pyd`, `.dll`, or `.ttf`, which are extracted to
20-
the real filesystem by default, you can simply attempt to add it to the extraction filter using:
21-
```java
20+
- if the problematic file is not one of the following types: `.so`, `.dylib`, `.pyd`, `.dll`, or `.ttf`, which are extracted to
21+
the real filesystem by default, you can simply attempt to add it to the extraction filter using:
22+
23+
```java
2224
VirtualFileSystem.Builder.extractFilter(filter);
2325
```
26+
2427
- if the previous does not help, it is also possible to extract all Python resources into a user-defined directory before creating a GraalPy
2528
context, and then configure the context to use that directory:
29+
2630
```java
2731
// extract the Python resources from the jar or native image into a given directory
2832
GraalPyResources.extractVirtualFileSystemResources(VirtualFileSystem.create(), externalResourceDirectoryPath);
2933
// create a GraalPy context configured with an external Python resource directory
3034
Context context = GraalPyResources.contextBuilder(externalResourceDirectoryPath).build();
3135
```
32-
- or if you're able to ship resources in a separate directory, you have to set the `externalDirectory` tag in
33-
[Maven](Embedding-Build-Tools.md#graalpy-maven-plugin) or `externalDirectory` field in [Gradle](Embedding-Build-Tools.md#graalpy-gradle-plugin)
34-
and also configure the GraalPy context to use that directory as well:
36+
- or if you're able to ship resources in a separate directory, you have to set the `externalDirectory` tag in
37+
[Maven](Embedding-Build-Tools.md#graalpy-maven-plugin) or `externalDirectory` field in [Gradle](Embedding-Build-Tools.md#graalpy-gradle-plugin)
38+
and also configure the GraalPy context to use that directory as well:
39+
3540
```java
3641
// create a Context configured with an external Python resource directory
3742
Context context = GraalPyResources.contextBuilder(externalResourceDirectoryPath).build();
3843
```
44+
3945
Please **note**, that if switching from Virtual FileSystem to an external directory, also all **user files** from the previous
4046
Virtual FileSystem resource root have to be moved into that directory as well.
4147

@@ -44,35 +50,36 @@ For more details about the Python resources in GraalPy Embedding please refer to
4450
For more details about GraalPy context and Virtual FileSystem configuration please refer to [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java) and
4551
[VirtualFileSystem](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/VirtualFileSystem.java) javadoc.
4652

47-
#### Issues with GraalPy 'java' posix backend
48-
The Virtual FileSystem is built on the Truffle filesystem and relies on the GraalPy Java POSIX backend.
49-
Unfortunately, certain Python packages bypass Python's I/O and directly access files through their
53+
### Issues with GraalPy 'java' posix backend
54+
55+
The Virtual FileSystem is built on the Truffle filesystem and relies on the GraalPy Java POSIX backend.
56+
Unfortunately, certain Python packages bypass Python's I/O and directly access files through their
5057
native extensions. If you encounter an error like:
5158
```
5259
NotImplementedError: 'PyObject_AsFileDescriptor' not supported when using 'java' posix backend
5360
```
5461
then you have to override the default `java` GraalPy backend option byt setting the `native` POSIX backend
55-
and completely omit the Virtual FileSystem at runtime.
62+
and completely omit the Virtual FileSystem at runtime.
5663

57-
Depending on how you [deploy Python resources](Embedding-Build-Tools.md#deployment) in your application,
64+
Depending on how you [deploy Python resources](Embedding-Build-Tools.md#deployment) in your application,
5865
you can do one of the following:
5966

6067
- if you need to package Python resources within your Jar or Native Image executable, then:
6168
```java
6269
// extract the Python resources from the jar or native image into a given directory
6370
GraalPyResources.extractVirtualFileSystemResources(VirtualFileSystem.create(), externalResourceDirectoryPath);
64-
// create a Context.Builder configured with an external python resource directory
71+
// create a Context.Builder configured with an external python resource directory
6572
Builder builder = GraalPyResources.contextBuilder(externalResourceDirectoryPath);
6673
// override the python.PosixModuleBackend option with "native"
6774
builder.option("python.PosixModuleBackend", "native");
6875
// create a context
6976
Context context = builder.build();
7077
```
71-
- or if you're able to ship Python resources in a separate directory, you have to set the `externalDirectory` tag in
78+
- or if you're able to ship Python resources in a separate directory, you have to set the `externalDirectory` tag in
7279
[Maven](Embedding-Build-Tools.md#graalpy-maven-plugin) or `externalDirectory` field in [Gradle](Embedding-Build-Tools.md#graalpy-gradle-plugin)
7380
and configure the GraalPy context accordingly:
7481
```java
75-
// create a Context.Builder configured with an external python resource directory
82+
// create a Context.Builder configured with an external python resource directory
7683
Builder builder = GraalPyResources.contextBuilder(externalResourceDirectoryPath);
7784
// override the python.PosixModuleBackend option with "native"
7885
builder.option("python.PosixModuleBackend", "native");
@@ -87,55 +94,65 @@ For more details about the Python resources in GraalPy Embedding please refer to
8794
For more details about GraalPy context and Virtual FileSystem configuration please refer to [GraalPyResources](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java) and
8895
[VirtualFileSystem](https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/VirtualFileSystem.java) javadoc.
8996

90-
### Maven and Gradle applications
97+
### ImportError reports "unknown location"
9198

92-
#### ImportError reports "unknown location"
93-
A possible cause of an `ImportError` ending with `(unknown location)` when running a GraalPy Java Embedding project might be
99+
A possible cause of an `ImportError` ending with `(unknown location)` when running a GraalPy Java Embedding project might be
94100
that an embedded Python package was built for a different operating system. If you see an error like the following:
95-
```
101+
102+
```bash
96103
ImportError: cannot import name 'exceptions' from 'cryptography.hazmat.bindings._rust' (unknown location)
97-
```
104+
```
105+
98106
You probably need to rebuild your project on the correct operating system before running it.
99107

100-
#### GraalVM JDK Compatibility
101-
To enable runtime compilation when running GraalPy from a Maven or Gradle application,
102-
you must use versions of GraalPy and the Polyglot API dependencies that are compatible
108+
### GraalVM JDK Compatibility
109+
110+
To enable runtime compilation when running GraalPy from a Maven or Gradle application,
111+
you must use versions of GraalPy and the Polyglot API dependencies that are compatible
103112
with the specified GraalVM JDK version. If you see errors like the following:
104113

105-
```
114+
```bash
106115
Your Java runtime '23.0.1+11-jvmci-b01' with compiler version '24.1.1' is incompatible with polyglot version '24.1.0'.
107116
```
108-
You need to keep the versions of your GraalPy and Polyglot dependencies according to the error message,
109-
so either upgrade the version of your JDK or your polyglot and GraalPy dependencies.
110117

111-
Note, this can also apply to cases when your dependencies are transitively pulled in by another artifact,
118+
You need to keep the versions of your GraalPy and Polyglot dependencies according to the error message,
119+
so either upgrade the version of your JDK or your polyglot and GraalPy dependencies.
120+
121+
Note, this can also apply to cases when your dependencies are transitively pulled in by another artifact,
112122
e.g. micronaut-graalpy.
113123

114-
#### The following artifacts could not be resolved: org.graalvm.python:python-language-enterprise
124+
### The following artifacts could not be resolved: org.graalvm.python:python-language-enterprise
125+
115126
`python-language-enterprise` was discontinued, use `org.graalvm.polyglot:python` instead.
116127

117-
#### Issues with Meson build system when installing Python packages on OSX with Maven or Gradle GraalPy plugin
128+
### Issues with Meson build system when installing Python packages on OSX with Maven or Gradle GraalPy plugin
129+
118130
Errors like the following:
119-
```
131+
132+
```bash
120133
../meson.build:1:0: ERROR: Failed running 'cython', binary or interpreter not executable.
121134
```
122135

123-
could be caused by the GraalPy launcher used internally by the Maven or Gradle GraalPy plugin
124-
for installing Python packages. Currently, there is no straightforward solution. However,
125-
a workaround is to set the Java system property graalpy.vfs.venvLauncher to a launcher from
136+
could be caused by the GraalPy launcher used internally by the Maven or Gradle GraalPy plugin
137+
for installing Python packages. Currently, there is no straightforward solution. However,
138+
a workaround is to set the Java system property graalpy.vfs.venvLauncher to a launcher from
126139
a downloaded [GraalPy](https://github.com/oracle/graalpython/releases/) distribution with a version
127140
matching the GraalPy Maven artifacts version.
128141

129142
e.g.
130-
```
143+
144+
```bash
131145
mvn package -Dgraalpy.vfs.venvLauncher={graalpy_directroy}/Contents/Home/bin/graalpy
132146
```
133147

134-
#### No language and polyglot implementation was found on the module-path.
148+
### No language and polyglot implementation was found on the module-path.
149+
135150
If you see an error like:
151+
152+
```bash
153+
java.lang.IllegalStateException: No language and polyglot implementation was found on the module-path. Make sure at last one language is added to the module-path.
136154
```
137-
java.lang.IllegalStateException: No language and polyglot implementation was found on the module-path. Make sure at last one language is added to the module-path.
138-
```
139-
you are probably missing the python langauge dependency in your Maven of Gradle configuration file.
155+
156+
you are probably missing the python langauge dependency in your Maven of Gradle configuration file.
140157
You need to add either `org.graalvm.polyglot:python` or `org.graalvm.polyglot:python-community` to your dependencies.
141158

graalpython/com.oracle.graal.python.cext/include/cpython/floatobject.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
1+
/* Copyright (c) 2023, 2025, Oracle and/or its affiliates.
22
* Copyright (C) 1996-2023 Python Software Foundation
33
*
44
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -12,6 +12,12 @@ typedef struct {
1212
double ob_fval;
1313
} PyFloatObject;
1414

15+
// GraalPy addition
16+
typedef struct {
17+
GraalPyObject ob_base;
18+
double ob_fval;
19+
} GraalPyFloatObject;
20+
1521
#define _PyFloat_CAST(op) \
1622
(assert(PyFloat_Check(op)), _Py_CAST(PyFloatObject*, op))
1723

@@ -21,7 +27,11 @@ static inline double PyFloat_AS_DOUBLE(PyObject *op) {
2127
#if 0 // GraalPy change
2228
return _PyFloat_CAST(op)->ob_fval;
2329
#else // GraalPy change
24-
return PyFloat_AsDouble(op);
30+
if (points_to_py_handle_space(op)) {
31+
return ((GraalPyFloatObject*) pointer_to_stub(op))->ob_fval;
32+
} else {
33+
return _PyFloat_CAST(op)->ob_fval;
34+
}
2535
#endif // GraalPy change
2636
}
2737
#define PyFloat_AS_DOUBLE(op) PyFloat_AS_DOUBLE(_PyObject_CAST(op))

graalpython/com.oracle.graal.python.cext/include/object.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,8 +1036,20 @@ static inline int PyType_CheckExact(PyObject *op) {
10361036
# define PyType_CheckExact(op) PyType_CheckExact(_PyObject_CAST(op))
10371037
#endif
10381038

1039+
// GraalPy additions
10391040
PyAPI_FUNC(void) _PyTruffle_DebugTrace(void);
10401041

1042+
typedef struct {
1043+
PyObject_HEAD
1044+
int32_t handle_table_index;
1045+
} GraalPyObject;
1046+
1047+
typedef struct {
1048+
GraalPyObject ob_base;
1049+
Py_ssize_t ob_size;
1050+
PyObject **ob_item;
1051+
} GraalPyVarObject;
1052+
10411053
#ifdef __cplusplus
10421054
}
10431055
#endif

graalpython/com.oracle.graal.python.cext/src/capi.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,6 @@ typedef struct {
112112
int getter_doc;
113113
} propertyobject;
114114

115-
typedef struct {
116-
PyObject_HEAD
117-
int32_t handle_table_index;
118-
} GraalPyObject;
119-
120-
typedef struct {
121-
GraalPyObject ob_base;
122-
Py_ssize_t ob_size;
123-
PyObject **ob_item;
124-
} GraalPyVarObject;
125-
126-
typedef struct {
127-
GraalPyObject ob_base;
128-
double ob_fval;
129-
} GraalPyFloatObject;
130-
131115
/* GraalPy GC support */
132116

133117
typedef struct _cycle_node {

0 commit comments

Comments
 (0)