Skip to content

Commit e959b7d

Browse files
committed
[GR-48482] Python: backport multiple fixes.
PullRequest: graalpython/2952
2 parents 812f7fa + 939fa45 commit e959b7d

File tree

121 files changed

+2671
-2045
lines changed

Some content is hidden

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

121 files changed

+2671
-2045
lines changed

CHANGELOG.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@ This changelog summarizes major changes between GraalVM versions of the Python
44
language runtime. The main focus is on user-observable behavior of the engine.
55

66
## Version 23.1.0
7-
* Oracle GraalPy standalones (also known as GraalPy Enterprise) are now available under GFTC. The community builds published on Github have been renamed to `graalpy-community-<version>-<os>-<arch>.tar.gz`.
7+
* Oracle GraalPy distributions (also known as GraalPy Enterprise) are now available under the [GFTC license](https://www.oracle.com/downloads/licenses/graal-free-license.html). The community builds published on Github have been renamed to `graalpy-community-<version>-<os>-<arch>.tar.gz`.
88
* Add support for the sqlite3 module. This allows many packages like `coverage` or `Flask-SQLAlchemy` to work on top of this embedded database.
9-
* The GraalPy standalone tool was updated to build single-file executable Python binaries for Linux, Windows, and macOS.
10-
* The GraalPy standalone tool was updated to generate skeleton Maven projects the demonstrate polyglot embedding.
11-
* Support venv and pip installation of with pure Python wheels on Windows. This is the first preview of Windows support for this feature, and there are limitations, but pure Python packages like Pygal can be installed with `python -m pip --no-cache install pygal`.
12-
* Support compilation and execution of C extensions using the native MSVC toolchain on Windows. This feature allows building C extensions from source, installation via pip is not possible at this time.
13-
* We have [contributed](https://github.com/actions/setup-python/pull/694) support for GraalPy to GitHub's `setup-python` action. We hope it will be available in the default repository soon, until then you can try it from the fork to run your Python workloads on GraalPy.
14-
* Added support for the sqlite3 module. This allows many packages like `coverage` or `Flask-SQLAlchemy` to work on top of this embedded database.
15-
* The GraalPy standalone tool was updated. You can now build single-file executable Python binaries for Linux, Windows, and macOS as well as generate skeleton Maven projects that set up a polyglot embedding of Python packages into Java.
16-
* Support venv and pip installation of with pure Python wheels on Windows. This is the first preview of Windows support for this feature, and there are limitations, but pure Python packages like Pygal can be installed with `python -m pip --no-cache install pygal`.
17-
* Support compilation and execution of C extensions using the native MSVC toolchain on Windows. This feature allows building C extensions from source, installation via pip is not possible at this time.
9+
* Provide Windows distributions of GraalPy. This is the first preview of Windows support for this feature, and there are limitations, but pure Python packages like Pygal can be installed with `python -m pip --no-cache install pygal`.
10+
* The GraalPy standalone tool was updated. You can now build single-file executable Python binaries for Linux, Windows, and macOS. The tool can also generate a skeleton Maven project that sets up a polyglot embedding of Python packages into Java.
1811

1912
## Version 23.0.0
2013
* Update `numpy` and `pandas` versions, add support for `scipy` and `scikit_learn` with `ginstall`. This automatically applies some fixes that make it possible to use these new versions with GraalPy.

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "911d7988b155cbf44fb0e4d545dd42083d8b3c90" }
1+
{ "overlay": "307e5a817ece2f16b7500db068a58c0538cf2101" }

graalpython/com.oracle.graal.python.hpy.test/src/hpytest/debug/test_charptr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def test_charptr_write_ptr(compiler, python_subprocess):
210210
assert result.stderr == b""
211211

212212

213-
@pytest.mark.xfail(__graalpython__.platform_id == "managed", reason="unaligned memcpy is not supported")
213+
@pytest.mark.xfail(__graalpython__.get_platform_id() == "managed", reason="unaligned memcpy is not supported")
214214
def test_charptr_correct_usage(compiler):
215215
mod = compiler.make_module("""
216216
#include <string.h>

graalpython/com.oracle.graal.python.hpy.test/src/hpytest/support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
PY2 = sys.version_info[0] == 2
3434
GRAALPYTHON = sys.implementation.name == 'graalpy'
35-
GRAALPYTHON_NATIVE = GRAALPYTHON and __graalpython__.platform_id == 'native'
36-
DARWIN_NATIVE = sys.platform == 'darwin' and (not GRAALPYTHON or __graalpython__.platform_id == 'native')
35+
GRAALPYTHON_NATIVE = GRAALPYTHON and __graalpython__.get_platform_id() == 'native'
36+
DARWIN_NATIVE = sys.platform == 'darwin' and (not GRAALPYTHON or __graalpython__.get_platform_id() == 'native')
3737

3838
HPY_ROOT = Path(__file__).parent.parent
3939
LOCK = FileLock(HPY_ROOT / ".hpy.lock")

graalpython/com.oracle.graal.python.hpy.test/src/hpytest/test_hpybuildvalue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_formats(self):
107107
actual = mod.f(i)
108108
assert actual == expected, code
109109

110-
@pytest.mark.xfail(__graalpython__.platform_id == "managed", reason="GR-38126")
110+
@pytest.mark.xfail(__graalpython__.get_platform_id() == "managed", reason="GR-38126")
111111
def test_bad_formats(self):
112112
test_cases = [
113113
('return HPy_BuildValue(ctx, "(q)", 42);',

graalpython/com.oracle.graal.python.resources/src/com/oracle/graal/python/resources/PythonResource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@
4848

4949
import com.oracle.truffle.api.CompilerDirectives;
5050
import com.oracle.truffle.api.InternalResource;
51-
import com.oracle.truffle.api.InternalResource.Id;
5251

5352
/**
5453
* This code needs to be kept in sync somehow with the suite.py code. In particular, the layouts
5554
* produced by the unpacking logic in {@link #unpackFiles} should produce the same layout as the
5655
* GRAALPYTHON_GRAALVM_SUPPORT distribution in the suite.py.
5756
*/
58-
@Id("python-home")
57+
@InternalResource.Id(value = "python-home", componentId = "python", optional = true)
5958
public final class PythonResource implements InternalResource {
6059
private static final int PYTHON_MAJOR;
6160
private static final int PYTHON_MINOR;

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advance/ExclusionsTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, 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
@@ -41,11 +41,26 @@
4141
package com.oracle.graal.python.test.advance;
4242

4343
import org.graalvm.polyglot.Context;
44+
import org.junit.Test;
4445

4546
public class ExclusionsTest {
4647
public static void main(String[] args) {
4748
try (Context context = Context.create()) {
4849
context.eval("python", "print('Hello Python!');");
4950
}
5051
}
52+
53+
@Test
54+
public void testDatetimeWithoutPlatformAccess() {
55+
if (!"true".equals(System.getProperty("python.WithoutPlatformAccess"))) {
56+
return;
57+
}
58+
var builder = Context.newBuilder().allowExperimentalOptions(true);
59+
if (System.getenv("GRAAL_PYTHONHOME") != null) {
60+
builder.option("python.PythonHome", System.getenv("GRAAL_PYTHONHOME"));
61+
}
62+
try (Context context = builder.build()) {
63+
context.eval("python", "import datetime; datetime.datetime.strptime('2014 7 2 6 14 0 742 +0700', '%Y %m %d %H %M %S %f %z')");
64+
}
65+
}
5166
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advance/ResourcesTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
import static org.junit.Assert.assertTrue;
4444

4545
import java.io.File;
46+
4647
import org.graalvm.polyglot.Context;
48+
import org.graalvm.polyglot.io.IOAccess;
4749
import org.junit.Test;
4850

4951
public class ResourcesTest {
@@ -59,4 +61,12 @@ public void testResourcesAsHome() {
5961
assertTrue(foundHome, !foundHome.contains("graalpython"));
6062
}
6163
}
64+
65+
@Test
66+
public void testResourcesAlwaysAllowReading() {
67+
try (Context context = Context.newBuilder("python").allowIO(IOAccess.NONE).option("python.PythonHome", "/path/that/does/not/exist").build()) {
68+
String foundHome = context.eval("python", "import email; email.__spec__.origin").asString();
69+
assertTrue(foundHome, foundHome.contains("python" + File.separator + "python-home"));
70+
}
71+
}
6272
}

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_gc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from . import CPyExtTestCase, CPyExtFunction, CPyExtType
4444
__dir__ = __file__.rpartition("/")[0]
4545

46-
GRAALPYTHON_NATIVE = sys.implementation.name == 'graalpy' and __graalpython__.platform_id == 'native'
46+
GRAALPYTHON_NATIVE = sys.implementation.name == 'graalpy' and __graalpython__.get_platform_id() == 'native'
4747

4848
# typedef PyObject * (*unaryfunc)(PyObject *);
4949
# typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
@@ -92,7 +92,7 @@
9292
// printf("free\\n");
9393
free_cnt++;
9494
PyObject_Del(a);
95-
}
95+
}
9696
static int dealloc_cnt = 0;
9797
void test_dealloc(PyObject *self) {
9898
// printf("dealloc\\n");
@@ -116,9 +116,9 @@
116116
tp_dealloc = "test_dealloc",
117117
tp_methods='{"getCounters", (PyCFunction)getCounters, METH_NOARGS | METH_STATIC, ""}, {"resetCounters", (PyCFunction)resetCounters, METH_NOARGS | METH_STATIC, ""}',
118118
)
119-
119+
120120
class TestGC1():
121-
121+
122122
def test_native_class(self):
123123
if GRAALPYTHON_NATIVE:
124124
gc.enable()
@@ -152,13 +152,13 @@ def test_native_class(self):
152152
# Py_ssize_t r2 = Py_REFCNT(o);
153153
# Py_DecRef(o);
154154
# Py_ssize_t r3 = Py_REFCNT(o);
155-
# return Py_BuildValue("(ii)", r2 - r1, r3 - r1);
155+
# return Py_BuildValue("(ii)", r2 - r1, r3 - r1);
156156
# }''',
157157
# resultspec="O",
158158
# argspec='O',
159159
# arguments=("PyObject* o", ),
160160
# callfunction="wrap_simple",
161-
# )
161+
# )
162162
#
163163
#
164164
# test_create = CPyExtFunction(
@@ -171,10 +171,10 @@ def test_native_class(self):
171171
# Py_ssize_t r2 = Py_REFCNT(o);
172172
# Py_DecRef(o);
173173
# Py_ssize_t r3 = Py_REFCNT(o);
174-
# return Py_BuildValue("(ii)", r2 - r1, r3 - r1);
174+
# return Py_BuildValue("(ii)", r2 - r1, r3 - r1);
175175
# }''',
176176
# resultspec="O",
177177
# argspec='O',
178178
# arguments=("PyObject* o", ),
179179
# callfunction="wrap_simple",
180-
# )
180+
# )

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_memoryview.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -39,6 +39,7 @@
3939

4040
import itertools
4141
import sys
42+
import struct
4243

4344
from . import CPyExtTestCase, CPyExtFunction, CPyExtType, unhandled_error_compare_with_message, unhandled_error_compare
4445

@@ -445,6 +446,29 @@ def compile_module(self, name):
445446

446447

447448
class TestObject(object):
449+
def test_memoryview_fromobject_multidim(self):
450+
TestType = CPyExtType(
451+
"TestMemoryViewMultidim",
452+
"""
453+
PyObject* get_converted_view(PyObject* self, PyObject* obj) {
454+
PyObject *mv = PyMemoryView_FromObject(obj);
455+
if (!mv) {
456+
return NULL;
457+
}
458+
459+
Py_buffer *view = PyMemoryView_GET_BUFFER(mv);
460+
// int i = (int)PyNumber_AsSsize_t(idx, NULL);
461+
return PyMemoryView_FromBuffer(view);
462+
}
463+
""",
464+
tp_methods='{"get_converted_view", get_converted_view, METH_O, ""}',
465+
)
466+
467+
obj = TestType()
468+
t1_buf = struct.pack("d"*12, *[1.5*x for x in range(12)])
469+
t1_mv = memoryview(t1_buf).cast('d', shape=[3,4])
470+
assert t1_mv == obj.get_converted_view(t1_mv)
471+
448472
def test_memoryview_acquire_release(self):
449473
TestType = CPyExtType(
450474
"TestMemoryViewBuffer1",

0 commit comments

Comments
 (0)