Skip to content

Commit 75abe6a

Browse files
committed
Add patch for pydantic-core 2.17.1
1 parent cf544f1 commit 75abe6a

File tree

2 files changed

+171
-1
lines changed

2 files changed

+171
-1
lines changed

graalpython/lib-graalpython/patches/metadata.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,18 @@ license = 'BSD-3-Clause'
451451

452452
[[pydantic.rules]]
453453
# Pin to match our pinned pydantic-core
454-
version = '== 2.4.2'
454+
version = '== 2.10.3'
455455

456456
[[pydantic-core.rules]]
457457
version = '== 2.10.1'
458458
patch = 'pydantic-core-2.10.1.patch'
459459
license = 'MIT'
460460

461+
[[pydantic-core.rules]]
462+
version = '== 2.27.1'
463+
patch = 'pydantic-core-2.27.1.patch'
464+
license = 'MIT'
465+
461466
[[pydantic-core.rules]]
462467
version = '== 2.26.0'
463468
patch = 'pydantic-core-2.26.0.patch'
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
diff --git a/Cargo.toml b/Cargo.toml
2+
index 3b3b8a9..718029a 100644
3+
--- a/Cargo.toml
4+
+++ b/Cargo.toml
5+
@@ -29,7 +29,7 @@ rust-version = "1.75"
6+
[dependencies]
7+
# TODO it would be very nice to remove the "py-clone" feature as it can panic,
8+
# but needs a bit of work to make sure it's not used in the codebase
9+
-pyo3 = { version = "0.22.6", features = ["generate-import-lib", "num-bigint", "py-clone"] }
10+
+pyo3 = { version = "0.22.6", features = ["generate-import-lib", "num-bigint", "py-clone"], path = "patched_crates/pyo3" }
11+
regex = "1.11.1"
12+
strum = { version = "0.26.3", features = ["derive"] }
13+
strum_macros = "0.26.4"
14+
@@ -46,7 +46,7 @@ base64 = "0.22.1"
15+
num-bigint = "0.4.6"
16+
python3-dll-a = "0.2.10"
17+
uuid = "1.11.0"
18+
-jiter = { version = "0.7.1", features = ["python"] }
19+
+jiter = { version = "0.7.1", features = ["python"], path = "patched_crates/jiter/crates/jiter" }
20+
hex = "0.4.3"
21+
22+
[lib]
23+
@@ -74,12 +74,12 @@ debug = true
24+
strip = false
25+
26+
[dev-dependencies]
27+
-pyo3 = { version = "0.22.6", features = ["auto-initialize"] }
28+
+pyo3 = { version = "0.22.6", features = ["auto-initialize"], path = "patched_crates/pyo3" }
29+
30+
[build-dependencies]
31+
version_check = "0.9.5"
32+
# used where logic has to be version/distribution specific, e.g. pypy
33+
-pyo3-build-config = { version = "0.22.6" }
34+
+pyo3-build-config = { version = "0.22.6", path = "patched_crates/pyo3/pyo3-build-config" }
35+
36+
[lints.clippy]
37+
dbg_macro = "warn"
38+
diff --git a/build_backend.py b/build_backend.py
39+
new file mode 100644
40+
index 0000000..bf9c44a
41+
--- /dev/null
42+
+++ b/build_backend.py
43+
@@ -0,0 +1,23 @@
44+
+import maturin
45+
+import os
46+
+import shutil
47+
+import subprocess
48+
+
49+
+build_sdist = maturin.build_sdist
50+
+
51+
+def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
52+
+ shutil.rmtree('patched_crates', ignore_errors=True)
53+
+ os.makedirs('patched_crates')
54+
+ subprocess.check_call([
55+
+ 'git', 'clone', 'https://github.com/PyO3/pyo3.git',
56+
+ 'patched_crates/pyo3',
57+
+ '--branch', 'v0.22.6',
58+
+ ])
59+
+ subprocess.check_call(['patch', '-p1', '-d', 'patched_crates/pyo3', '-i', '../../patches/pyo3.patch'])
60+
+ subprocess.check_call([
61+
+ 'git', 'clone', 'https://github.com/pydantic/jiter.git',
62+
+ 'patched_crates/jiter',
63+
+ '--branch', 'v0.7.1',
64+
+ ])
65+
+ subprocess.check_call(['patch', '-p1', '-d', 'patched_crates/jiter', '-i', '../../patches/jiter.patch'])
66+
+ return maturin.build_wheel(wheel_directory, config_settings, metadata_directory)
67+
diff --git a/patches/jiter.patch b/patches/jiter.patch
68+
new file mode 100644
69+
index 0000000..3fc59ee
70+
--- /dev/null
71+
+++ b/patches/jiter.patch
72+
@@ -0,0 +1,12 @@
73+
+diff --git a/Cargo.toml b/Cargo.toml
74+
+index 122e111..9ec9e6d 100644
75+
+--- a/Cargo.toml
76+
++++ b/Cargo.toml
77+
+@@ -29,5 +29,5 @@ inherits = "release"
78+
+ debug = true
79+
+
80+
+ [workspace.dependencies]
81+
+-pyo3 = { version = "0.22.0" }
82+
+-pyo3-build-config = { version = "0.22.0" }
83+
++pyo3 = { version = "0.22.6", path = "../pyo3" }
84+
++pyo3-build-config = { version = "0.22.6", path = "../pyo3/pyo3-build-config" }
85+
diff --git a/patches/pyo3.patch b/patches/pyo3.patch
86+
new file mode 100644
87+
index 0000000..e488ffb
88+
--- /dev/null
89+
+++ b/patches/pyo3.patch
90+
@@ -0,0 +1,31 @@
91+
+diff --git a/pyo3-ffi/src/cpython/pyerrors.rs b/pyo3-ffi/src/cpython/pyerrors.rs
92+
+index 6d17ebc812..1d206f9b18 100644
93+
+--- a/pyo3-ffi/src/cpython/pyerrors.rs
94+
++++ b/pyo3-ffi/src/cpython/pyerrors.rs
95+
+@@ -6,19 +6,19 @@ use crate::Py_ssize_t;
96+
+ #[derive(Debug)]
97+
+ pub struct PyBaseExceptionObject {
98+
+ pub ob_base: PyObject,
99+
+- #[cfg(not(any(PyPy, GraalPy)))]
100+
++ #[cfg(not(PyPy))]
101+
+ pub dict: *mut PyObject,
102+
+- #[cfg(not(any(PyPy, GraalPy)))]
103+
++ #[cfg(not(PyPy))]
104+
+ pub args: *mut PyObject,
105+
+- #[cfg(all(Py_3_11, not(any(PyPy, GraalPy))))]
106+
++ #[cfg(all(Py_3_11, not(PyPy)))]
107+
+ pub notes: *mut PyObject,
108+
+- #[cfg(not(any(PyPy, GraalPy)))]
109+
++ #[cfg(not(PyPy))]
110+
+ pub traceback: *mut PyObject,
111+
+- #[cfg(not(any(PyPy, GraalPy)))]
112+
++ #[cfg(not(PyPy))]
113+
+ pub context: *mut PyObject,
114+
+- #[cfg(not(any(PyPy, GraalPy)))]
115+
++ #[cfg(not(PyPy))]
116+
+ pub cause: *mut PyObject,
117+
+- #[cfg(not(any(PyPy, GraalPy)))]
118+
++ #[cfg(not(PyPy))]
119+
+ pub suppress_context: char,
120+
+ }
121+
+
122+
diff --git a/pyproject.toml b/pyproject.toml
123+
index de04a39..8db6756 100644
124+
--- a/pyproject.toml
125+
+++ b/pyproject.toml
126+
@@ -3,7 +3,8 @@ requires = [
127+
'maturin>=1,<2',
128+
'typing-extensions >=4.6.0,!=4.7.0'
129+
]
130+
-build-backend = 'maturin'
131+
+backend-path = ['.']
132+
+build-backend = 'build_backend'
133+
134+
[project]
135+
name = 'pydantic_core'
136+
diff --git a/src/input/return_enums.rs b/src/input/return_enums.rs
137+
index c91a6e2..d0da05a 100644
138+
--- a/src/input/return_enums.rs
139+
+++ b/src/input/return_enums.rs
140+
@@ -10,7 +10,7 @@ use pyo3::exceptions::PyTypeError;
141+
use pyo3::ffi;
142+
use pyo3::intern;
143+
use pyo3::prelude::*;
144+
-#[cfg(not(PyPy))]
145+
+#[cfg(all(not(PyPy),not(GraalPy)))]
146+
use pyo3::types::PyFunction;
147+
use pyo3::types::{PyBytes, PyComplex, PyFloat, PyFrozenSet, PyIterator, PyMapping, PySet, PyString};
148+
149+
@@ -330,14 +330,14 @@ pub(crate) fn iterate_attributes<'a, 'py>(
150+
// the PyFunction::is_type_of(attr) catches `staticmethod`, but also any other function,
151+
// I think that's better than including static methods in the yielded attributes,
152+
// if someone really wants fields, they can use an explicit field, or a function to modify input
153+
- #[cfg(not(PyPy))]
154+
+ #[cfg(all(not(PyPy),not(GraalPy)))]
155+
if !is_bound && !attr.is_instance_of::<PyFunction>() {
156+
return Some(Ok((name, attr)));
157+
}
158+
// MASSIVE HACK! PyFunction doesn't exist for PyPy,
159+
// is_instance_of::<PyFunction> crashes with a null pointer, hence this hack, see
160+
// https://github.com/pydantic/pydantic-core/pull/161#discussion_r917257635
161+
- #[cfg(PyPy)]
162+
+ #[cfg(any(PyPy,GraalPy))]
163+
if !is_bound && attr.get_type().to_string() != "<class 'function'>" {
164+
return Some(Ok((name, attr)));
165+
}

0 commit comments

Comments
 (0)