Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
15 changes: 9 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- '3.11'
- '3.12'
- '3.13'
- '3.13t'
arch:
- 'arm64'
- 'x86'
Expand Down Expand Up @@ -58,35 +59,35 @@ jobs:
# Activate Python development mode so we get warnings.
PYTHONDEVMODE: '1'
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.py }}
architecture: ${{ matrix.arch }}

- name: Install Rust
if: matrix.arch == 'x64'
if: matrix.arch == 'x64' && !startsWith(matrix.py, '3.13')
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable

- uses: actions/checkout@v4

- name: Install Dependencies
shell: bash
run: |
python -m pip install --require-hashes -r ci/requirements.txt

# TODO enable once PyO3 supports 3.13.
- name: Build (Rust)
if: matrix.arch == 'x64' && matrix.py != '3.13'
if: matrix.arch == 'x64' && !startsWith(matrix.py, '3.13')
Comment on lines 81 to +83
Copy link
Owner

Choose a reason for hiding this comment

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

I'm guessing this is supported now. But scope bloat to resolve it in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I opened a followup issue to track this #251

env:
PIP_CONSTRAINT: 'ci/constraints.txt'
run: |
python -m pip install --config-settings='--build-option=--rust-backend' -e .

- name: Build (No Rust)
if: matrix.arch != 'x64' || matrix.py == '3.13'
if: matrix.arch != 'x64' || startsWith(matrix.py, '3.13')
run: |
python -m pip install -e .

Expand All @@ -95,13 +96,15 @@ jobs:
pytest --numprocesses=auto --hypothesis-profile=${HYPOTHESIS_PROFILE} -v tests/

- name: Test CFFI Backend
# CFFI doesn't yet support the free-threaded build of CPython
if: matrix.py != '3.13t'
env:
PYTHON_ZSTANDARD_IMPORT_POLICY: 'cffi'
run: |
pytest --numprocesses=auto --hypothesis-profile=${HYPOTHESIS_PROFILE} -v tests/

- name: Test Rust Backend
if: matrix.arch == 'x64'
if: matrix.arch == 'x64' && !startsWith(matrix.py, '3.13')
# Rust backend is currently experimental. So ignore failures in it.
continue-on-error: true
env:
Expand Down
6 changes: 5 additions & 1 deletion c-ext/backend_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ void zstd_module_init(PyObject *m) {
Py_DECREF(feature);
#endif

#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif

if (PyObject_SetAttrString(m, "backend_features", features) == -1) {
return;
}
Expand Down Expand Up @@ -313,7 +317,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
7 changes: 6 additions & 1 deletion docs/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ One way to do this is to depend on the ``zstandard[cffi]`` dependency.
e.g. ``pip install 'zstandard[cffi]'`` or add ``zstandard[cffi]`` to your
pip requirements file.

CFFI does not yet support the free-threaded build of CPython so the CFFI
backend is disabled at build time for free-threaded Python regardless of
whether or not the ``cffi`` is specified.

Legacy Format Support
=====================

Expand Down Expand Up @@ -84,7 +88,8 @@ All Install Arguments
Do not compile the CFFI-based backend.

``--rust-backend``
Compile the Rust backend (not yet feature complete).
Compile the Rust backend (not yet feature complete and not supported
on the free-threaded build or Python 3.13).

If you invoke ``setup.py``, simply pass the aforementioned arguments. e.g.
``python3.9 setup.py --no-cffi-backend``. If using ``pip``, use the
Expand Down
37 changes: 21 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import platform
import sys
import sysconfig

from setuptools import setup

Expand All @@ -36,7 +37,6 @@

ext_suffix = os.environ.get("SETUPTOOLS_EXT_SUFFIX")
if ext_suffix:
import sysconfig
# setuptools._distutils.command.build_ext doesn't use
# SETUPTOOLS_EXT_SUFFIX like setuptools.command.build_ext does.
# Work around the issue so that cross-compilation can work
Expand All @@ -55,22 +55,27 @@
if py39compat:
py39compat.add_ext_suffix = lambda vars: None

try:
import cffi

# PyPy (and possibly other distros) have CFFI distributed as part of
# them.
cffi_version = LooseVersion(cffi.__version__)
if cffi_version < LooseVersion(MINIMUM_CFFI_VERSION):
print(
"CFFI %s or newer required (%s found); "
"not building CFFI backend" % (MINIMUM_CFFI_VERSION, cffi_version),
file=sys.stderr,
)
cffi = None

except ImportError:
if bool(sysconfig.get_config_var("Py_GIL_DISABLED")):
# cffi does not yet support the free-threaded build so we
# disable the cffi backend
cffi = None
else:
try:
import cffi

# PyPy (and possibly other distros) have CFFI distributed as part of
# them.
cffi_version = LooseVersion(cffi.__version__)
if cffi_version < LooseVersion(MINIMUM_CFFI_VERSION):
print(
"CFFI %s or newer required (%s found); "
"not building CFFI backend" % (MINIMUM_CFFI_VERSION, cffi_version),
file=sys.stderr,
)
cffi = None

except ImportError:
cffi = None

sys.path.insert(0, ".")

Expand Down