Skip to content

Commit ded5688

Browse files
committed
[GR-57192] Basic suport for MLX library
PullRequest: graalpython/3435
2 parents fb43e41 + 8fd9e9a commit ded5688

File tree

12 files changed

+1263
-100
lines changed

12 files changed

+1263
-100
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ PY_TRUFFLE_TYPE(UnionType_Type, "_ctypes.UnionType", &PyType_Type, sizeof(PyO
342342
PY_TRUFFLE_TYPE(PyCPointerType_Type, "PyCPointerType", &PyType_Type, sizeof(PyObject)) \
343343
PY_TRUFFLE_TYPE(PyCArrayType_Type, "PyCArrayType", &PyType_Type, sizeof(PyObject)) \
344344
PY_TRUFFLE_TYPE(PyCoro_Type, "coroutine", &PyType_Type, sizeof(PyCoroObject)) \
345+
PY_TRUFFLE_TYPE(Py_GenericAliasType, "types.GenericAlias", &PyType_Type, sizeof(PyObject)) \
345346
/* PyPickleBufferObject (PyObject_HEAD + Py_buffer + PyObject*) is defined within Objects/picklebufobject.c, so its not exposed. */ \
346347
PY_TRUFFLE_TYPE(PyPickleBuffer_Type, "_pickle.PickleBuffer", &PyType_Type, sizeof(PyPickleBufferObject)) \
347348
PY_TRUFFLE_TYPE_UNIMPLEMENTED(_PyAIterWrapper_Type) \

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ def CPyExtHeapType(name, bases=(object), code='', slots=None, **kwargs):
767767
{slots}
768768
}};
769769
770-
PyType_Spec spec = {{ "{name}Type", sizeof({name}Object), 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, slots }};
770+
PyType_Spec spec = {{ "{name}", sizeof({name}Object), 0, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, slots }};
771771
772772
static PyObject* create(PyObject* unused, PyObject* bases) {{
773773
{ready_code}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
import sys
4141

42-
from . import CPyExtTestCase, CPyExtFunction
42+
from . import CPyExtTestCase, CPyExtFunction, CPyExtType, assert_raises, CPyExtHeapType
4343

4444
__dir__ = __file__.rpartition("/")[0]
4545

@@ -53,7 +53,6 @@ def foo(self):
5353

5454

5555
class TestClassobject(CPyExtTestCase):
56-
5756
testmod = type(sys)("foo")
5857

5958
test_PyMethod_Function = CPyExtFunction(
@@ -79,3 +78,18 @@ class TestClassobject(CPyExtTestCase):
7978
argspec="O",
8079
arguments=["PyObject* func"],
8180
)
81+
82+
def test_name_qualname(self):
83+
TypeWithName = CPyExtType('TypeWithName')
84+
assert TypeWithName.__name__ == 'TypeWithName'
85+
assert TypeWithName.__qualname__ == 'TypeWithName'
86+
assert_raises(TypeError, setattr, '__name__', TypeWithName, "foo")
87+
assert_raises(TypeError, setattr, '__qualname__', TypeWithName, "foo")
88+
89+
HeapTypeWithName = CPyExtHeapType('HeapTypeWithName')
90+
assert HeapTypeWithName.__name__ == 'HeapTypeWithName'
91+
assert HeapTypeWithName.__qualname__ == 'HeapTypeWithName'
92+
HeapTypeWithName.__name__ = 'HeapTypeWithNameRenamed'
93+
assert HeapTypeWithName.__name__ == 'HeapTypeWithNameRenamed'
94+
HeapTypeWithName.__qualname__ = 'foo.HeapTypeWithNameRenamed'
95+
assert HeapTypeWithName.__qualname__ == 'foo.HeapTypeWithNameRenamed'

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,11 @@ private static PythonManagedClass lookupBuiltinTypeWithName(PythonContext contex
17051705
}
17061706
Object attribute = PyObjectGetAttr.getUncached().execute(null, moduleObject, toTruffleStringUncached(name));
17071707
if (attribute != PNone.NO_VALUE) {
1708-
clazz = (PythonManagedClass) attribute;
1708+
if (attribute instanceof PythonBuiltinClassType builtinType) {
1709+
clazz = core.lookupType(builtinType);
1710+
} else {
1711+
clazz = (PythonManagedClass) attribute;
1712+
}
17091713
}
17101714

17111715
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java

Lines changed: 116 additions & 64 deletions
Large diffs are not rendered by default.

graalpython/lib-graalpython/patches/cmake/cmake.patch

Lines changed: 0 additions & 26 deletions
This file was deleted.

graalpython/lib-graalpython/patches/cmake/metadata.toml

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[[add-sources]]
2+
version = '0.16.3'
3+
url = 'https://github.com/ml-explore/mlx/archive/refs/tags/v0.16.3.tar.gz'
4+
5+
[[add-sources]]
6+
version = '0.16.2'
7+
url = 'https://github.com/ml-explore/mlx/archive/refs/tags/v0.16.2.tar.gz'
8+
9+
[[add-sources]]
10+
version = '0.16.1'
11+
url = 'https://github.com/ml-explore/mlx/archive/refs/tags/v0.16.1.tar.gz'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[rules]]
2+
patch = 'nanobind.patch'
3+
license = 'BSD-3-Clause'

0 commit comments

Comments
 (0)