Skip to content

Commit e62194f

Browse files
authored
Merge pull request #196 from static-frame/195/threaded
Free-threaded Python support
2 parents e90f515 + fa6874a commit e62194f

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ jobs:
4141
fi
4242
4343
wheels:
44-
name: Build / ${{ matrix.os }} / Python 3.${{ matrix.python.minor }}
44+
name: Build / ${{ matrix.os }} / Python 3.${{ matrix.python.minor }} / FT${{ matrix.python.ft }}
4545
needs: matrix_config
4646
strategy:
4747
fail-fast: false
4848
matrix:
4949
os: ${{ fromJson(needs.matrix_config.outputs.matrix_os) }}
5050
python:
51-
- {minor: 10, req_build: 'requirements-build-3_11.txt', req_test: 'requirements-dev-3_11.txt'}
52-
- {minor: 11, req_build: 'requirements-build-3_11.txt', req_test: 'requirements-dev-3_11.txt'}
53-
- {minor: 12, req_build: 'requirements-build-3_12.txt', req_test: 'requirements-dev-3_12.txt'}
54-
- {minor: 13, req_build: 'requirements-build-3_13.txt', req_test: 'requirements-dev-3_13.txt'}
51+
- {minor: 10, req_build: 'requirements-build-3_11.txt', req_test: 'requirements-dev-3_11.txt', ft: '0'}
52+
- {minor: 11, req_build: 'requirements-build-3_11.txt', req_test: 'requirements-dev-3_11.txt', ft: '0'}
53+
- {minor: 12, req_build: 'requirements-build-3_12.txt', req_test: 'requirements-dev-3_12.txt', ft: '0'}
54+
- {minor: 13, req_build: 'requirements-build-3_13.txt', req_test: 'requirements-dev-3_13.txt', ft: '0'}
55+
- {minor: 13t, req_build: 'requirements-build-3_13.txt', req_test: 'requirements-dev-3_13.txt', ft: '1'}
5556

5657
runs-on: ${{ matrix.os }}
5758
outputs:
@@ -75,6 +76,7 @@ jobs:
7576
CIBW_BEFORE_BUILD: pip install -r {project}/${{ matrix.python.req_build }}
7677
CIBW_BEFORE_TEST: pip install -r {project}/${{ matrix.python.req_test }}
7778
CIBW_TEST_COMMAND: pytest {project}/test
79+
CIBW_ENABLE: ${{ matrix.python.ft == '1' && 'cpython-freethreading' || '' }}
7880

7981
- run: pip install pipx
8082
if: matrix.os == 'macos-13-xlarge'
@@ -87,10 +89,11 @@ jobs:
8789
CIBW_BEFORE_BUILD: pip install -r {project}/${{ matrix.python.req_build }}
8890
CIBW_BEFORE_TEST: pip install -r {project}/${{ matrix.python.req_test }}
8991
CIBW_TEST_COMMAND: pytest {project}/test
92+
CIBW_ENABLE: ${{ matrix.python.ft == '1' && 'cpython-freethreading' || '' }}
9093

9194
- uses: actions/upload-artifact@v4
9295
with:
93-
name: dist-wheels-${{ matrix.os }}-py3${{ matrix.python.minor }} # Unique artifact name
96+
name: dist-wheels-${{ matrix.os }}-py3${{ matrix.python.minor }}-t${{ matrix.python.ft }} # Unique artifact name
9497
path: dist/*
9598

9699
upload:
@@ -105,11 +108,6 @@ jobs:
105108
path: dist
106109
merge-multiple: true
107110

108-
# - name: Flatten dist directory
109-
# run: |
110-
# find dist -mindepth 2 -type f \( -name '*.whl' -o -name '*.tar.gz' \) \
111-
# -exec mv {} dist/ \;
112-
113111
- uses: pypa/gh-action-pypi-publish@release/v1
114112
with:
115113
password: ${{ secrets.PYPI_TOKEN }}

requirements-build-3_13.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
numpy==2.2.5
1+
numpy==2.3.1
22
setuptools==80.*

requirements-dev-3_13.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
numpy==2.2.5
1+
numpy==2.3.1
22
pytest==8.3.3
33
invoke==2.2.0
44
hypothesis==6.131.16

src/_arraykit.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static struct PyModuleDef arraykit_module = {
7272
.m_methods = arraykit_methods,
7373
};
7474

75-
PyObject *
75+
PyObject*
7676
PyInit__arraykit(void)
7777
{
7878
import_array();
@@ -134,6 +134,9 @@ PyInit__arraykit(void)
134134
Py_XDECREF(m);
135135
return NULL;
136136
}
137+
#ifdef Py_GIL_DISABLED
138+
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
139+
#endif
137140
return m;
138141
}
139142

src/auto_map.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,13 @@ fami_iternext(FAMIObject *self)
426426
else {
427427
PyObject* t = PyTuple_New(2);
428428
if (!t) { return NULL; }
429+
#if PY_VERSION_HEX >= 0x030D0000 // Python 3.13+
430+
PyObject* k = PyList_GetItemRef(self->fam->keys, index);
431+
#else
429432
PyObject* k = PyList_GET_ITEM(self->fam->keys, index);
430-
Py_INCREF(k);
433+
Py_XINCREF(k);
434+
#endif
435+
if (!k) { return NULL; }
431436
PyTuple_SET_ITEM(t, 0, k);
432437
PyTuple_SET_ITEM(t, 1, PyLong_FromSsize_t(index));
433438
return t;
@@ -438,8 +443,13 @@ fami_iternext(FAMIObject *self)
438443
return PyArray_ToScalar(PyArray_GETPTR1(self->keys_array, index), self->keys_array);
439444
}
440445
else {
446+
#if PY_VERSION_HEX >= 0x030D0000 // Python 3.13+
447+
PyObject* yield = PyList_GetItemRef(self->fam->keys, index);
448+
#else
441449
PyObject* yield = PyList_GET_ITEM(self->fam->keys, index);
442-
Py_INCREF(yield);
450+
Py_XINCREF(yield);
451+
#endif
452+
if (!yield) { return NULL; }
443453
return yield;
444454
}
445455
}
@@ -1302,11 +1312,11 @@ lookup(FAMObject *self, PyObject *key) {
13021312
return self->table[table_pos].keys_pos;
13031313
}
13041314

1305-
// Insert a key_pos, hash pair into the table. Assumes table already has appropriate size. When inserting a new itme, `hash` is -1, forcing a fresh hash to be computed here. Return 0 on success, -1 on error.
1315+
// Insert a key_pos, hash pair into the table. Assumes table already has appropriate size. When inserting a new item, `hash` is -1, forcing a fresh hash to be computed here. Return 0 on success, -1 on error.
13061316
static int
13071317
insert_obj(
13081318
FAMObject *self,
1309-
PyObject *key,
1319+
PyObject *key, // NOTE: a borrowed reference
13101320
Py_ssize_t keys_pos,
13111321
Py_hash_t hash)
13121322
{

0 commit comments

Comments
 (0)