Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ language runtime. The main focus is on user-observable behavior of the engine.
* Add `polyglot.gil_locked_during_interop` context manager. By default, the global interpreter lock (GIL) is unlocked when interacting with objects from another language, to give other Python threads a chance to run in parallel. While this avoids potential deadlocks, repeated unlocking and locking of the GIL can decrease performance, so this context manager can be used to keep the lock held around short-running interop.
* Add Github workflows that run our gates from the same job definitions as our internal CI. This will make it easier for contributors opening PRs on Github to ensure code contributions pass the same tests that we are running internally.
* Added support for specifying generics on foreign classes, and inheriting from such classes. Especially when using Java classes that support generics, this allows expressing the generic types in Python type annotations as well.
* Added a new `java` backend for the `pyexpat` module that uses a Java XML parser instead of the native `expat` library. It can be useful when running without native access or multiple-context scenarios. This backend is the default when embedding and can be switched back to native `expat` by setting `python.PyExpatModuleBackend` option to `native`. Standalone distribution still defaults to native expat backend.

## Version 25.0.1
* Allow users to keep going on unsupported JDK/OS/ARCH combinations at their own risk by opting out of early failure using `-Dtruffle.UseFallbackRuntime=true`, `-Dpolyglot.engine.userResourceCache=/set/to/a/writeable/dir`, `-Dpolyglot.engine.allowUnsupportedPlatform=true`, and `-Dpolyglot.python.UnsupportedPlatformEmulates=[linux|macos|windows]` and `-Dorg.graalvm.python.resources.exclude=native.files`.
Expand Down
11 changes: 4 additions & 7 deletions ci.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@
"python-unittest-arrow-storage": gpgate + require(GPY_JVM_STANDALONE) + platform_spec(no_jobs) + platform_spec({
"linux:amd64:jdk-latest" : tier2,
}),
"python-unittest-posix": gpgate + platform_spec(no_jobs) + platform_spec({
"linux:amd64:jdk-latest" : tier2 + require(GPY_JVM_STANDALONE),
"linux:aarch64:jdk-latest" : tier3 + require(GPY_JVM_STANDALONE),
"darwin:aarch64:jdk-latest" : tier3 + require(GPY_JVM_STANDALONE),
}),
"python-unittest-standalone": gpgate_maven + platform_spec(no_jobs) + platform_spec({
"linux:amd64:jdk21" : daily + t("02:00:00") + require(GPY_JVM21_STANDALONE),
"linux:aarch64:jdk21" : daily + t("02:00:00") + require(GPY_JVM21_STANDALONE),
Expand Down Expand Up @@ -277,9 +272,11 @@
"style-ecj": style_gate + task_spec({ tags:: "style,ecjbuild" }) + platform_spec(no_jobs) + platform_spec({
"linux:amd64:jdk-latest" : tier1,
}),
// tests with sandboxed backends for various modules (posix, sha3, ctypes, ...)
// tests with sandboxed backends for various modules (posix, sha3, compression, pyexpat, ...)
"python-unittest-sandboxed": gpgate_ee + platform_spec(no_jobs) + platform_spec({
"linux:amd64:jdk-latest" : tier3,
"linux:amd64:jdk-latest" : tier2,
"linux:aarch64:jdk-latest" : tier3,
"darwin:aarch64:jdk-latest" : tier3,
}),
"python-svm-unittest-sandboxed": gpgate_ee + platform_spec(no_jobs) + platform_spec({
"linux:amd64:jdk-latest" : tier3 + provide(GPYEE_NATIVE_STANDALONE),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
* Copyright (c) 2017, 2026, Oracle and/or its affiliates.
* Copyright (c) 2013, Regents of the University of California
*
* All rights reserved.
Expand Down Expand Up @@ -182,6 +182,7 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
boolean posixBackendSpecified = false;
boolean sha3BackendSpecified = false;
boolean compressionBackendSpecified = false;
boolean pyExpatBackendSpecified = false;
boolean installSignalHandlersSpecified = false;
boolean isolateNativeModulesSpecified = false;
for (Iterator<String> argumentIterator = arguments.iterator(); argumentIterator.hasNext();) {
Expand Down Expand Up @@ -272,7 +273,8 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
matchesPythonOption(arg, "CAPI") ||
matchesPythonOption(arg, "PosixModuleBackend") ||
matchesPythonOption(arg, "Sha3ModuleBackend") ||
matchesPythonOption(arg, "CompressionModulesBackend")) {
matchesPythonOption(arg, "CompressionModulesBackend") ||
matchesPythonOption(arg, "PyExpatModuleBackend")) {
addRelaunchArg(arg);
}
if (matchesPythonOption(arg, "PosixModuleBackend")) {
Expand All @@ -284,6 +286,9 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
if (matchesPythonOption(arg, "CompressionModulesBackend")) {
compressionBackendSpecified = true;
}
if (matchesPythonOption(arg, "PyExpatModuleBackend")) {
pyExpatBackendSpecified = true;
}
if (matchesPythonOption(arg, "InstallSignalHandlers")) {
installSignalHandlersSpecified = true;
}
Expand Down Expand Up @@ -451,6 +456,9 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
if (!compressionBackendSpecified) {
polyglotOptions.put("python.CompressionModulesBackend", "native");
}
if (!pyExpatBackendSpecified) {
polyglotOptions.put("python.PyExpatModuleBackend", "native");
}
if (!installSignalHandlersSpecified) {
polyglotOptions.put("python.InstallSignalHandlers", "true");
}
Expand Down
76 changes: 76 additions & 0 deletions graalpython/com.oracle.graal.python.test/src/tests/test_xml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright (c) 2026, 2026, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
#
# Subject to the condition set forth below, permission is hereby granted to any
# person obtaining a copy of this software, associated documentation and/or
# data (collectively the "Software"), free of charge and under any and all
# copyright rights in the Software, and any and all patent rights owned or
# freely licensable by each licensor hereunder covering either (i) the
# unmodified Software as contributed to or provided by such licensor, or (ii)
# the Larger Works (as defined below), to deal in both
#
# (a) the Software, and
#
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
# one is included with the Software each a "Larger Work" to which the Software
# is contributed by such licensors),
#
# without restriction, including without limitation the rights to copy, create
# derivative works of, display, perform, and distribute the Software and make,
# use, sell, offer for sale, import, export, have made, and have sold the
# Software and the Larger Work(s), and to sublicense the foregoing rights on
# either these or other terms.
#
# This license is subject to the following condition:
#
# The above copyright notice and either this complete permission notice or at a
# minimum a reference to the UPL must be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import unittest
from xml.parsers import expat


class PyExpatXmlTest(unittest.TestCase):

def test_xml_decl_handler_not_called_without_xml_declaration(self):
parser = expat.ParserCreate()
xml_decl_calls = []

parser.XmlDeclHandler = lambda *args: xml_decl_calls.append(args)
parser.Parse(b"<doc/>", True)

self.assertEqual([], xml_decl_calls)

def test_parser_create_encoding_is_used_for_byte_input(self):
parser = expat.ParserCreate(encoding="iso-8859-1")
character_data = []

parser.CharacterDataHandler = character_data.append
parser.Parse(b"<doc>\xe9</doc>", True)

self.assertEqual(["\xe9"], character_data)

def test_external_doctype_reports_no_internal_subset(self):
parser = expat.ParserCreate()
doctype_calls = []

parser.StartDoctypeDeclHandler = lambda *args: doctype_calls.append(args)
parser.ExternalEntityRefHandler = lambda *args: 1
parser.Parse(b'<!DOCTYPE doc SYSTEM "x.dtd"><doc/>', True)

self.assertEqual([("doc", "x.dtd", None, 0)], doctype_calls)


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@
}
]
},
{
"name": "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl",
"methods": [
{
"name": "<init>",
"parameterTypes": []
}
]
},
{
"name": "com.sun.crypto.provider.AESCipher$General",
"methods": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"resources":[
{"pattern":"org/graalvm/shadowed/org/jline.*"}
"resources": [
{
"pattern": "org/graalvm/shadowed/org/jline.*"
},
{
"pattern": "com/sun/org/apache/xerces/internal/impl/msg/XMLMessages.properties"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import com.oracle.graal.python.builtins.modules.PosixShMemModuleBuiltins;
import com.oracle.graal.python.builtins.modules.PosixSubprocessModuleBuiltins;
import com.oracle.graal.python.builtins.modules.PwdModuleBuiltins;
import com.oracle.graal.python.builtins.modules.pyexpat.PyExpatModuleBuiltins;
import com.oracle.graal.python.builtins.modules.QueueModuleBuiltins;
import com.oracle.graal.python.builtins.modules.RandomModuleBuiltins;
import com.oracle.graal.python.builtins.modules.ReadlineModuleBuiltins;
Expand Down Expand Up @@ -364,6 +365,7 @@
import com.oracle.graal.python.builtins.objects.tuple.InstantiableStructSequenceBuiltins;
import com.oracle.graal.python.builtins.objects.tuple.StructSequenceBuiltins;
import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins;
import com.oracle.graal.python.builtins.modules.pyexpat.XMLParserBuiltins;
import com.oracle.graal.python.builtins.objects.tuple.TupleGetterBuiltins;
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
Expand Down Expand Up @@ -658,8 +660,10 @@ private static PythonBuiltins[] initializeBuiltins(TruffleLanguage.Env env) {
new JavaModuleBuiltins(),
new JArrayModuleBuiltins(),
new CSVModuleBuiltins(),
new PyExpatModuleBuiltins(),
new JSONModuleBuiltins(),
new SREModuleBuiltins(),
new XMLParserBuiltins(),
new AstModuleBuiltins(),
PythonImageBuildOptions.WITHOUT_NATIVE_POSIX && (PythonImageBuildOptions.WITHOUT_JAVA_INET || !env.isSocketIOAllowed()) ? null : new SelectModuleBuiltins(),
PythonImageBuildOptions.WITHOUT_NATIVE_POSIX && (PythonImageBuildOptions.WITHOUT_JAVA_INET || !env.isSocketIOAllowed()) ? null : new SocketModuleBuiltins(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import com.oracle.graal.python.builtins.modules.pickle.PicklerMemoProxyBuiltins;
import com.oracle.graal.python.builtins.modules.pickle.UnpicklerBuiltins;
import com.oracle.graal.python.builtins.modules.pickle.UnpicklerMemoProxyBuiltins;
import com.oracle.graal.python.builtins.modules.pyexpat.XMLParserBuiltins;
import com.oracle.graal.python.builtins.modules.re.MatchBuiltins;
import com.oracle.graal.python.builtins.modules.re.PatternBuiltins;
import com.oracle.graal.python.builtins.modules.weakref.ProxyTypeBuiltins;
Expand Down Expand Up @@ -777,6 +778,7 @@ It can be called either on the class (e.g. C.f()) or on an instance
TimeoutError("TimeoutError", OSError, newBuilder().publishInModule(J_BUILTINS).basetype().addDict()),
ZLibError("error", Exception, newBuilder().publishInModule("zlib").basetype().addDict()),
CSVError("Error", Exception, newBuilder().publishInModule("_csv").basetype().addDict()),
PyExpatError("error", Exception, newBuilder().publishInModule("pyexpat").basetype().addDict()),
LZMAError("LZMAError", Exception, newBuilder().publishInModule("_lzma").basetype().addDict()),
StructError("StructError", Exception, newBuilder().publishInModule(J__STRUCT).basetype().addDict()),
PickleError("PickleError", Exception, newBuilder().publishInModule("_pickle").basetype().addDict()),
Expand Down Expand Up @@ -1171,6 +1173,11 @@ def takewhile(predicate, iterable):
PythonObject,
newBuilder().publishInModule("_json").basetype().slots(JSONEncoderBuiltins.SLOTS).doc("""
_iterencode(obj, _current_indent_level) -> iterable""")),
XMLParser(
"xmlparser",
PythonObject,
newBuilder().publishInModule("pyexpat").basetype().disallowInstantiation().slots(XMLParserBuiltins.SLOTS).doc("""
pyexpat XML parser object""")),

// datetime
PDate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static com.oracle.graal.python.nodes.BuiltinNames.J___GRAALPYTHON__;
import static com.oracle.graal.python.nodes.BuiltinNames.T_FORMAT;
import static com.oracle.graal.python.nodes.BuiltinNames.T_MTIME;
import static com.oracle.graal.python.nodes.BuiltinNames.T_PYEXPAT;
import static com.oracle.graal.python.nodes.BuiltinNames.T_SHA3;
import static com.oracle.graal.python.nodes.BuiltinNames.T_SIZE;
import static com.oracle.graal.python.nodes.BuiltinNames.T__IMP;
Expand Down Expand Up @@ -931,6 +932,15 @@ TruffleString sha3ModuleBackend() {
}
}

@Builtin(name = "pyexpat_module_backend", minNumOfPositionalArgs = 0)
@GenerateNodeFactory
public abstract static class PyExpatModuleBackendNode extends PythonBuiltinNode {
@Specialization
TruffleString pyexpatModuleBackend() {
return getContext().lookupBuiltinModule(T_PYEXPAT) == null ? T_NATIVE : T_JAVA;
}
}

@Builtin(name = "time_millis", minNumOfPositionalArgs = 0, maxNumOfPositionalArgs = 1, doc = "Like time.time() but in milliseconds resolution.")
@GenerateNodeFactory
public abstract static class TimeMillis extends PythonUnaryBuiltinNode {
Expand Down
Loading
Loading