Skip to content

Commit

Permalink
Merge pull request #29 from synodriver/freethreading
Browse files Browse the repository at this point in the history
init support for freethreading
  • Loading branch information
kodonnell authored Nov 21, 2024
2 parents eedb9cc + 55a855c commit 9bbdc27
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ write_to_template = "__version__ = \"{version}\""
[tool.cibuildwheel]
test-requires = "pytest pillow"
test-command = "pytest {project}/tests"
build = "cp39-* cp310-* cp311-* cp312-*"
build = "cp39-* cp310-* cp311-* cp312-* cp313-*"
# skip musl and ignore the non-standard linux builds
skip = "*-musllinux_* *s390x* *ppc64le* *i686*"
build-frontend = "build"
Expand Down
18 changes: 17 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys

import numpy as np
import setuptools_scm # noqa: F401 - to avoid version = 0.0.0 errors if built without setuptools_scm installed
Expand All @@ -8,6 +9,8 @@

try:
from Cython.Build import cythonize
from Cython.Compiler.Version import version as cython_version
from packaging.version import Version
except ImportError:
cythonize = None
if USE_CYTHON:
Expand All @@ -27,12 +30,23 @@ def no_cythonize(extensions, **_ignore):
extension.sources[:] = sources
return extensions

define_macros=[("QOI_MALLOC", "PyMem_RawMalloc"), ("QOI_FREE", "PyMem_RawFree"), ("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")]
if (
sys.version_info > (3, 13, 0)
and hasattr(sys, "_is_gil_enabled")
and not sys._is_gil_enabled()
):
print("build nogil")
define_macros.append(
("Py_GIL_DISABLED", "1"),
) # ("CYTHON_METH_FASTCALL", "1"), ("CYTHON_VECTORCALL", 1)]


extensions = [
Extension(
"qoi.qoi",
sources=["src/qoi/qoi.pyx", "src/qoi/implementation.c"],
define_macros=[("QOI_MALLOC", "PyMem_RawMalloc"), ("QOI_FREE", "PyMem_RawFree"), ("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
define_macros=define_macros,
)
]

Expand All @@ -45,6 +59,8 @@ def no_cythonize(extensions, **_ignore):
"wraparound": False,
"cdivision": True,
}
if Version(cython_version) >= Version("3.1.0a0"):
compiler_directives["freethreading_compatible"] = True
extensions = cythonize(extensions, compiler_directives=compiler_directives)
else:
extensions = no_cythonize(extensions)
Expand Down
2 changes: 2 additions & 0 deletions src/qoi/qoi.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cimport numpy as np
from cpython.mem cimport PyMem_RawFree
import enum
from pathlib import Path
cimport cython

np.import_array()

Expand All @@ -13,6 +14,7 @@ class QOIColorSpace(enum.Enum):
SRGB = qoi.QOI_SRGB
LINEAR = qoi.QOI_LINEAR

@cython.internal
cdef class PixelWrapper:
cdef void* pixels

Expand Down

0 comments on commit 9bbdc27

Please sign in to comment.