@@ -37,32 +37,39 @@ index 625e474..e3ad221 100644
3737 dbg_macro = "warn"
3838diff --git a/build_backend.py b/build_backend.py
3939new file mode 100644
40- index 0000000..4576d33
40+ index 0000000..471610f
4141--- /dev/null
4242+++ b/build_backend.py
43- @@ -0,0 +1,23 @@
43+ @@ -0,0 +1,30 @@
4444+ import maturin
4545+ import os
4646+ import shutil
4747+ import subprocess
48+ + import tarfile
49+ +
50+ + from pathlib import Path
51+ + from urllib.request import urlopen
4852+
4953+ build_sdist = maturin.build_sdist
5054+
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+ +
5167+ 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.5',
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.0',
64- + ])
65- + subprocess.check_call(['patch', '-p1', '-d', 'patched_crates/jiter', '-i', '../../patches/jiter.patch'])
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.5', patched_crates)
72+ + get_crate_and_patch('pydantic', 'jiter', '0.7.0', patched_crates)
6673+ return maturin.build_wheel(wheel_directory, config_settings, metadata_directory)
6774diff --git a/patches/jiter.patch b/patches/jiter.patch
6875new file mode 100644
0 commit comments