Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
- '3.11'
- '3.12'
- '3.13'
- '3.14.0-rc.2'
- '3.14'
- '3.14t'
arch:
- 'arm64'
- 'x86'
Expand Down Expand Up @@ -77,9 +78,10 @@ jobs:
with:
python-version: ${{ matrix.py }}
architecture: ${{ matrix.arch }}
allow-prereleases: true

- name: Install Rust
if: matrix.arch != 'x86' && matrix.py != '3.14.0-rc.2'
if: matrix.arch != 'x86' && (matrix.py != '3.14' || matrix.py != '3.14t')
uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b # v1
with:
toolchain: stable
Expand All @@ -96,14 +98,14 @@ jobs:
python -m pip install --require-hashes -r ci/requirements.txt

- name: Build (Rust)
if: matrix.arch != 'x86' && matrix.py != '3.14.0-rc.2'
if: matrix.arch != 'x86' && (matrix.py != '3.14' || matrix.py != '3.14t')
env:
PIP_CONSTRAINT: 'ci/constraints.txt'
run: |
python -m pip -v install --config-settings='--build-option=--rust-backend' -e .

- name: Build (No Rust)
if: matrix.arch == 'x86' || matrix.py == '3.14.0-rc.2'
if: matrix.arch == 'x86' || matrix.py == '3.14' || matrix.py == '3.14t'
env:
PIP_CONSTRAINT: 'ci/constraints.txt'
run: |
Expand All @@ -120,7 +122,7 @@ jobs:
pytest --numprocesses=auto --hypothesis-profile=${HYPOTHESIS_PROFILE} -v tests/

- name: Test Rust Backend
if: matrix.arch != 'x86' && matrix.py != '3.14.0-rc.2'
if: matrix.arch != 'x86' && (matrix.py != '3.14' || matrix.py != '3.14t' )
# Rust backend is currently experimental. So ignore failures in it.
continue-on-error: true
env:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/typing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ jobs:
- '3.11'
- '3.12'
- '3.13'
- '3.13t'
- '3.14'
- '3.14t'
runs-on: 'ubuntu-24.04'
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
- 'cp312'
- 'cp313'
- 'cp314'
- 'cp314t'
arch:
- 'arm64'
- 'x86_64'
Expand All @@ -74,7 +75,9 @@ jobs:
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_BUILD: ${{ matrix.py }}-*
CIBW_BUILD_VERBOSITY: '1'
CIBW_ENABLE: cpython-prerelease cpython-freethreading
ZSTD_WARNINGS_AS_ERRORS: '1'

steps:
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
Expand Down Expand Up @@ -109,7 +112,8 @@ jobs:
- '3.11'
- '3.12'
- '3.13'
- '3.14.0-rc.2'
- '3.14'
- '3.14t'
arch:
- 'x86'
- 'x64'
Expand All @@ -130,6 +134,7 @@ jobs:
with:
python-version: ${{ matrix.py }}
architecture: ${{ matrix.arch }}
allow-prereleases: true

- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
Expand Down
23 changes: 11 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ version = "2.0.10+zstd.1.5.6"
features = ["experimental", "legacy", "zstdmt"]

[dependencies.pyo3]
version = "0.24.2"
version = "0.25.1"
features = ["extension-module"]
2 changes: 1 addition & 1 deletion c-ext/backend_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ size_t roundpow2(size_t i) {
int safe_pybytes_resize(PyObject **obj, Py_ssize_t size) {
PyObject *tmp;

if ((*obj)->ob_refcnt == 1) {
if (Py_REFCNT(*obj) == 1) {
return _PyBytes_Resize(obj, size);
}

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies = []

[project.optional-dependencies]
cffi = [
'cffi>=1.17 ; python_version >= "3.13" and platform_python_implementation != "PyPy"',
'cffi>=2.0.0b1 ; python_version >= "3.13" and platform_python_implementation != "PyPy"',
]

[project.urls]
Expand All @@ -34,7 +34,7 @@ Documentation = "https://python-zstandard.readthedocs.io/en/latest/"

[build-system]
requires = [
"cffi>=1.17.0 ; platform_python_implementation != 'PyPy'",
"cffi>=2.0.0b1 ; platform_python_implementation != 'PyPy'",
"packaging",
"setuptools",
]
Expand Down
6 changes: 3 additions & 3 deletions rust-ext/src/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use {
exceptions::{PyIndexError, PyTypeError, PyValueError},
ffi::Py_buffer,
prelude::*,
types::{PyBytes, PyTuple},
types::{PyBytes, PyTuple}, IntoPyObjectExt,
},
};

Expand Down Expand Up @@ -242,7 +242,7 @@ impl ZstdBufferWithSegments {
}

Ok(Self {
source: data.into_py(py),
source: data.into_py_any(py).unwrap(),
buffer: data_buffer,
segments,
})
Expand Down Expand Up @@ -344,7 +344,7 @@ impl ZstdBufferWithSegmentsCollection {

offset += segment.segments.len();

buffers.push(item.to_object(py));
buffers.push(item.into_py_any(py).unwrap());
first_elements.push(offset);
}

Expand Down
6 changes: 3 additions & 3 deletions rust-ext/src/compression_chunker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
stream::{make_in_buffer_source, InBufferSource},
zstd_safe::CCtx,
},
pyo3::{prelude::*, types::PyBytes},
pyo3::{prelude::*, types::PyBytes, IntoPyObjectExt},
std::sync::Arc,
};

Expand Down Expand Up @@ -225,7 +225,7 @@ impl ZstdCompressionChunkerIterator {
let chunk = PyBytes::new(py, &slf.dest_buffer);
slf.dest_buffer.clear();

return Ok(Some(chunk.into_py(py)));
return Ok(Some(chunk.into_py_any(py).unwrap()));
}

// Else continue to compress available input data.
Expand Down Expand Up @@ -278,6 +278,6 @@ impl ZstdCompressionChunkerIterator {
let chunk = PyBytes::new(py, &slf.dest_buffer);
slf.dest_buffer.clear();

Ok(Some(chunk.into_py(py)))
Ok(Some(chunk.into_py_any(py).unwrap()))
}
}
4 changes: 2 additions & 2 deletions rust-ext/src/compression_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
buffer::PyBuffer,
exceptions::{PyNotImplementedError, PyOSError, PyValueError},
prelude::*,
types::PyBytes,
types::PyBytes, IntoPyObjectExt,
},
std::sync::Arc,
};
Expand Down Expand Up @@ -48,7 +48,7 @@ impl ZstdCompressionWriter {

Ok(Self {
cctx,
writer: writer.into_py(py),
writer: writer.into_py_any(py).unwrap(),
write_return_read,
closefd,
entered: false,
Expand Down
6 changes: 3 additions & 3 deletions rust-ext/src/compressor_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
stream::{make_in_buffer_source, InBufferSource},
zstd_safe::CCtx,
},
pyo3::{prelude::*, types::PyBytes},
pyo3::{prelude::*, types::PyBytes, IntoPyObjectExt},
std::sync::Arc,
};

Expand Down Expand Up @@ -60,7 +60,7 @@ impl ZstdCompressorIterator {
// TODO avoid buffer copy
let chunk = PyBytes::new(py, &dest_buffer);

return Ok(Some(chunk.into_py(py)));
return Ok(Some(chunk.into_py_any(py).unwrap()));
}

// Else read another chunk in hopes of producing output data.
Expand Down Expand Up @@ -94,7 +94,7 @@ impl ZstdCompressorIterator {
// TODO avoid buffer copy.
let chunk = PyBytes::new(py, &dest_buffer);

return Ok(Some(chunk.into_py(py)));
return Ok(Some(chunk.into_py_any(py).unwrap()));
}

Ok(None)
Expand Down
4 changes: 2 additions & 2 deletions rust-ext/src/decompression_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
buffer::PyBuffer,
exceptions::{PyOSError, PyValueError},
prelude::*,
types::PyBytes,
types::PyBytes, IntoPyObjectExt,
},
std::sync::Arc,
};
Expand Down Expand Up @@ -40,7 +40,7 @@ impl ZstdDecompressionWriter {
) -> PyResult<Self> {
Ok(Self {
dctx,
writer: writer.into_py(py),
writer: writer.into_py_any(py).unwrap(),
write_size,
write_return_read,
closefd,
Expand Down
6 changes: 3 additions & 3 deletions rust-ext/src/decompressor_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
stream::{make_in_buffer_source, InBufferSource},
zstd_safe::DCtx,
},
pyo3::{exceptions::PyValueError, prelude::*, types::PyBytes},
pyo3::{exceptions::PyValueError, prelude::*, types::PyBytes, IntoPyObjectExt},
std::{cmp::min, sync::Arc},
};

Expand Down Expand Up @@ -60,7 +60,7 @@ impl ZstdDecompressorIterator {
if !dest_buffer.is_empty() {
// TODO avoid buffer copy.
let chunk = PyBytes::new(py, &dest_buffer);
return Ok(Some(chunk.into_py(py)));
return Ok(Some(chunk.into_py_any(py).unwrap()));
}

// Repeat loop to collect more input data.
Expand All @@ -71,7 +71,7 @@ impl ZstdDecompressorIterator {
if !dest_buffer.is_empty() {
// TODO avoid buffer copy.
let chunk = PyBytes::new(py, &dest_buffer);
Ok(Some(chunk.into_py(py)))
Ok(Some(chunk.into_py_any(py).unwrap()))
} else {
Ok(None)
}
Expand Down
6 changes: 3 additions & 3 deletions rust-ext/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// of the BSD license. See the LICENSE file for details.

use {
pyo3::{buffer::PyBuffer, exceptions::PyValueError, prelude::*},
pyo3::{buffer::PyBuffer, exceptions::PyValueError, prelude::*, IntoPyObjectExt},
zstd_sys::ZSTD_inBuffer,
};

Expand Down Expand Up @@ -139,7 +139,7 @@ pub(crate) fn make_in_buffer_source(
) -> PyResult<Box<dyn InBufferSource + Send>> {
if source.hasattr("read")? {
Ok(Box::new(ReadSource {
source: source.into_py(py),
source: source.into_py_any(py).unwrap(),
buffer: None,
read_size,
finished: false,
Expand All @@ -153,7 +153,7 @@ pub(crate) fn make_in_buffer_source(
})?;

Ok(Box::new(BufferSource {
source: source.into_py(py),
source: source.into_py_any(py).unwrap(),
buffer,
offset: 0,
}))
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
# garbage collection pitfalls.
# Require 1.17 everywhere so we don't have to think about supporting older
# versions.
MINIMUM_CFFI_VERSION = "1.17"
# Require 2.0 for improved free-threading support
MINIMUM_CFFI_VERSION = "2.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider only requiring this on Python 3.14 or newer. Here's how I did that in cryptography: https://github.com/pyca/cryptography/pull/12555/files#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711R8


ext_suffix = os.environ.get("SETUPTOOLS_EXT_SUFFIX")
if ext_suffix:
Expand Down