|
| 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..4710e3f |
| 41 | +--- /dev/null |
| 42 | ++++ b/build_backend.py |
| 43 | +@@ -0,0 +1,30 @@ |
| 44 | ++import maturin |
| 45 | ++import os |
| 46 | ++import shutil |
| 47 | ++import subprocess |
| 48 | ++import tarfile |
| 49 | ++ |
| 50 | ++from pathlib import Path |
| 51 | ++from urllib.request import urlopen |
| 52 | ++ |
| 53 | ++build_sdist = maturin.build_sdist |
| 54 | ++ |
| 55 | ++ |
| 56 | ++def get_crate_and_patch(namespace, name, version, patched_crates): |
| 57 | ++ with ( |
| 58 | ++ urlopen(f'https://github.com/{namespace}/{name}/archive/refs/tags/v{version}.tar.gz') as f, |
| 59 | ++ tarfile.open(fileobj=f, mode='r:gz') as tar, |
| 60 | ++ ): |
| 61 | ++ tar.extractall(patched_crates, filter='data') |
| 62 | ++ crate = patched_crates / f'{name}-{version}' |
| 63 | ++ crate = crate.rename(patched_crates / name) |
| 64 | ++ subprocess.check_call(['patch', '-p1', '-d', str(crate), '-i', str((Path('patches') / f'{name}.patch').absolute())]) |
| 65 | ++ |
| 66 | ++ |
| 67 | ++def build_wheel(wheel_directory, config_settings=None, metadata_directory=None): |
| 68 | ++ patched_crates = Path('patched_crates') |
| 69 | ++ shutil.rmtree(patched_crates, ignore_errors=True) |
| 70 | ++ patched_crates.mkdir() |
| 71 | ++ get_crate_and_patch('PyO3', 'pyo3', '0.22.6', patched_crates) |
| 72 | ++ get_crate_and_patch('pydantic', 'jiter', '0.7.1', patched_crates) |
| 73 | ++ return maturin.build_wheel(wheel_directory, config_settings, metadata_directory) |
| 74 | +diff --git a/patches/jiter.patch b/patches/jiter.patch |
| 75 | +new file mode 100644 |
| 76 | +index 0000000..3fc59ee |
| 77 | +--- /dev/null |
| 78 | ++++ b/patches/jiter.patch |
| 79 | +@@ -0,0 +1,12 @@ |
| 80 | ++diff --git a/Cargo.toml b/Cargo.toml |
| 81 | ++index 122e111..9ec9e6d 100644 |
| 82 | ++--- a/Cargo.toml |
| 83 | +++++ b/Cargo.toml |
| 84 | ++@@ -29,5 +29,5 @@ inherits = "release" |
| 85 | ++ debug = true |
| 86 | ++ |
| 87 | ++ [workspace.dependencies] |
| 88 | ++-pyo3 = { version = "0.22.0" } |
| 89 | ++-pyo3-build-config = { version = "0.22.0" } |
| 90 | +++pyo3 = { version = "0.22.6", path = "../pyo3" } |
| 91 | +++pyo3-build-config = { version = "0.22.6", path = "../pyo3/pyo3-build-config" } |
| 92 | +diff --git a/patches/pyo3.patch b/patches/pyo3.patch |
| 93 | +new file mode 100644 |
| 94 | +index 0000000..e488ffb |
| 95 | +--- /dev/null |
| 96 | ++++ b/patches/pyo3.patch |
| 97 | +@@ -0,0 +1,31 @@ |
| 98 | ++diff --git a/pyo3-ffi/src/cpython/pyerrors.rs b/pyo3-ffi/src/cpython/pyerrors.rs |
| 99 | ++index 6d17ebc812..1d206f9b18 100644 |
| 100 | ++--- a/pyo3-ffi/src/cpython/pyerrors.rs |
| 101 | +++++ b/pyo3-ffi/src/cpython/pyerrors.rs |
| 102 | ++@@ -6,19 +6,19 @@ use crate::Py_ssize_t; |
| 103 | ++ #[derive(Debug)] |
| 104 | ++ pub struct PyBaseExceptionObject { |
| 105 | ++ pub ob_base: PyObject, |
| 106 | ++- #[cfg(not(any(PyPy, GraalPy)))] |
| 107 | +++ #[cfg(not(PyPy))] |
| 108 | ++ pub dict: *mut PyObject, |
| 109 | ++- #[cfg(not(any(PyPy, GraalPy)))] |
| 110 | +++ #[cfg(not(PyPy))] |
| 111 | ++ pub args: *mut PyObject, |
| 112 | ++- #[cfg(all(Py_3_11, not(any(PyPy, GraalPy))))] |
| 113 | +++ #[cfg(all(Py_3_11, not(PyPy)))] |
| 114 | ++ pub notes: *mut PyObject, |
| 115 | ++- #[cfg(not(any(PyPy, GraalPy)))] |
| 116 | +++ #[cfg(not(PyPy))] |
| 117 | ++ pub traceback: *mut PyObject, |
| 118 | ++- #[cfg(not(any(PyPy, GraalPy)))] |
| 119 | +++ #[cfg(not(PyPy))] |
| 120 | ++ pub context: *mut PyObject, |
| 121 | ++- #[cfg(not(any(PyPy, GraalPy)))] |
| 122 | +++ #[cfg(not(PyPy))] |
| 123 | ++ pub cause: *mut PyObject, |
| 124 | ++- #[cfg(not(any(PyPy, GraalPy)))] |
| 125 | +++ #[cfg(not(PyPy))] |
| 126 | ++ pub suppress_context: char, |
| 127 | ++ } |
| 128 | ++ |
| 129 | +diff --git a/pyproject.toml b/pyproject.toml |
| 130 | +index de04a39..8db6756 100644 |
| 131 | +--- a/pyproject.toml |
| 132 | ++++ b/pyproject.toml |
| 133 | +@@ -3,7 +3,8 @@ requires = [ |
| 134 | + 'maturin>=1,<2', |
| 135 | + 'typing-extensions >=4.6.0,!=4.7.0' |
| 136 | + ] |
| 137 | +-build-backend = 'maturin' |
| 138 | ++backend-path = ['.'] |
| 139 | ++build-backend = 'build_backend' |
| 140 | + |
| 141 | + [project] |
| 142 | + name = 'pydantic_core' |
| 143 | +diff --git a/src/input/return_enums.rs b/src/input/return_enums.rs |
| 144 | +index c91a6e2..d0da05a 100644 |
| 145 | +--- a/src/input/return_enums.rs |
| 146 | ++++ b/src/input/return_enums.rs |
| 147 | +@@ -10,7 +10,7 @@ use pyo3::exceptions::PyTypeError; |
| 148 | + use pyo3::ffi; |
| 149 | + use pyo3::intern; |
| 150 | + use pyo3::prelude::*; |
| 151 | +-#[cfg(not(PyPy))] |
| 152 | ++#[cfg(all(not(PyPy),not(GraalPy)))] |
| 153 | + use pyo3::types::PyFunction; |
| 154 | + use pyo3::types::{PyBytes, PyComplex, PyFloat, PyFrozenSet, PyIterator, PyMapping, PySet, PyString}; |
| 155 | + |
| 156 | +@@ -330,14 +330,14 @@ pub(crate) fn iterate_attributes<'a, 'py>( |
| 157 | + // the PyFunction::is_type_of(attr) catches `staticmethod`, but also any other function, |
| 158 | + // I think that's better than including static methods in the yielded attributes, |
| 159 | + // if someone really wants fields, they can use an explicit field, or a function to modify input |
| 160 | +- #[cfg(not(PyPy))] |
| 161 | ++ #[cfg(all(not(PyPy),not(GraalPy)))] |
| 162 | + if !is_bound && !attr.is_instance_of::<PyFunction>() { |
| 163 | + return Some(Ok((name, attr))); |
| 164 | + } |
| 165 | + // MASSIVE HACK! PyFunction doesn't exist for PyPy, |
| 166 | + // is_instance_of::<PyFunction> crashes with a null pointer, hence this hack, see |
| 167 | + // https://github.com/pydantic/pydantic-core/pull/161#discussion_r917257635 |
| 168 | +- #[cfg(PyPy)] |
| 169 | ++ #[cfg(any(PyPy,GraalPy))] |
| 170 | + if !is_bound && attr.get_type().to_string() != "<class 'function'>" { |
| 171 | + return Some(Ok((name, attr))); |
| 172 | + } |
0 commit comments