From ef904533356eeef38f2084547b0d58bf9271be11 Mon Sep 17 00:00:00 2001 From: Nate Pope Date: Wed, 18 Nov 2026 14:43:32 -0800 Subject: [PATCH 1/5] Add C extension build, test and CI infrastructure --- .clang-format | 20 +++++ .github/workflows/tests.yml | 18 ++++ .github/workflows/wheels.yml | 34 +++----- .gitignore | 7 ++ MANIFEST.in | 6 ++ Makefile | 8 ++ _tsdatemodule.c | 104 +++++++++++++++++++++++ codecov.yml | 25 ++++++ docs/installation.md | 7 ++ lib/err.c | 62 ++++++++++++++ lib/err.h | 89 ++++++++++++++++++++ lib/meson.build | 27 ++++++ lib/tests/tests.c | 159 +++++++++++++++++++++++++++++++++++ lib/tsdate.h | 45 ++++++++++ prek.toml | 13 +++ pyproject.toml | 27 ++++++ setup.py | 30 +++++++ tests/test_python_c.py | 66 +++++++++++++++ uv.lock | 135 ++++++++++++++++++++++++++--- 19 files changed, 848 insertions(+), 34 deletions(-) create mode 100644 .clang-format create mode 100644 MANIFEST.in create mode 100644 Makefile create mode 100644 _tsdatemodule.c create mode 100644 codecov.yml create mode 100644 lib/err.c create mode 100644 lib/err.h create mode 100644 lib/meson.build create mode 100644 lib/tests/tests.c create mode 100644 lib/tsdate.h create mode 100644 setup.py create mode 100644 tests/test_python_c.py diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..918771c5 --- /dev/null +++ b/.clang-format @@ -0,0 +1,20 @@ +Language: Cpp +BasedOnStyle: GNU +SortIncludes: false +AllowShortIfStatementsOnASingleLine: false +BreakBeforeBraces: Linux +TabWidth: 4 +IndentWidth: 4 +ColumnLimit: 89 +SpaceBeforeParens: + ControlStatements +SpacesInCStyleCastParentheses: false +SpaceAfterCStyleCast: true +IndentCaseLabels: true +AlignAfterOpenBracket: DontAlign +BinPackArguments: true +BinPackParameters: true +AlwaysBreakAfterReturnType: AllDefinitions + +StatementMacros: ["PyObject_HEAD", "Py_BEGIN_ALLOW_THREADS", "Py_END_ALLOW_THREADS"] +AlignConsecutiveMacros: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0903024d..9b065e4f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,6 +15,24 @@ jobs: with: cli-test-cmd: tsdate --help + test-c: + name: C tests + permissions: + contents: read + uses: tskit-dev/.github/.github/workflows/c-tests.yml@v22 + with: + library-directory: lib + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + test-python-c: + name: Python-C tests + permissions: + contents: read + uses: tskit-dev/.github/.github/workflows/python-c-tests.yml@v22 + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + test: name: Python permissions: diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 5d685958..ed1cc8d5 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -10,39 +10,25 @@ permissions: contents: read jobs: - build: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - with: - fetch-depth: 0 - persist-credentials: false - - - name: Install uv - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 - with: - version: "0.13.6" - enable-cache: false - - - name: Build - run: uv build - - - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - name: dist - path: dist/ + build-wheels: + uses: tskit-dev/.github/.github/workflows/build-wheels.yml@v22 publish: runs-on: ubuntu-24.04 environment: release - needs: [build] + needs: [build-wheels] permissions: id-token: write steps: - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + - name: Download artifacts + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: - name: dist + pattern: build-* path: dist + merge-multiple: true + + - name: Show artifacts + run: ls -lah dist - name: Publish to TestPyPI if: github.event_name == 'push' && github.ref_name == 'test-publish' diff --git a/.gitignore b/.gitignore index dea84902..07e256b3 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,10 @@ evaluation/results/* !evaluation/results/performance*.csv !evaluation/results/performance*.png evaluation/results/*_quick* + +# C extension +*.so +lib/build* +build-* +*.gcda +*.gcno diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..d49cfdf6 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,6 @@ +include lib/*.c +include lib/*.h +include _tsdatemodule.c +include README.md +include LICENSE +recursive-include tests *.py diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..89e94abf --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +all: ext + +ext: + uv run python setup.py build_ext --inplace + +clean: + rm -f *.so *.o + rm -fR build lib/build diff --git a/_tsdatemodule.c b/_tsdatemodule.c new file mode 100644 index 00000000..13d13df7 --- /dev/null +++ b/_tsdatemodule.c @@ -0,0 +1,104 @@ +/* + * MIT License + * + * Copyright (c) 2026 Tskit Developers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define PY_SSIZE_T_CLEAN +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION + +#include +#include + +#include "lib/tsdate.h" + +#define MODULE_DOC "Low-level tsdate interface." + +static PyObject *TsdLibraryError; + +static void +handle_library_error(int err) +{ + if (err == TSD_ERR_NO_MEMORY) { + PyErr_NoMemory(); + } else { + PyErr_Format(TsdLibraryError, "%s", tsd_strerror(err)); + } +} + +/* Return the library's message for the given error code. */ +static PyObject * +tsdate_strerror(PyObject *Py_UNUSED(self), PyObject *args) +{ + PyObject *ret = NULL; + int err; + + if (!PyArg_ParseTuple(args, "i", &err)) { + goto out; + } + ret = Py_BuildValue("s", tsd_strerror(err)); +out: + return ret; +} + +/* Raise the exception that the given library error code maps to. */ +static PyObject * +tsdate_raise_library_error(PyObject *Py_UNUSED(self), PyObject *args) +{ + PyObject *ret = NULL; + int err; + + if (!PyArg_ParseTuple(args, "i", &err)) { + goto out; + } + handle_library_error(err); +out: + return ret; +} + +static PyMethodDef tsdate_methods[] = { + { "strerror", (PyCFunction) tsdate_strerror, METH_VARARGS, + "Return the message for a library error code." }, + { "raise_library_error", (PyCFunction) tsdate_raise_library_error, METH_VARARGS, + "Raise the Python exception corresponding to a library error code." }, + { NULL } /* Sentinel */ +}; + +static struct PyModuleDef tsdatemodule = { PyModuleDef_HEAD_INIT, "_tsdate", MODULE_DOC, + -1, tsdate_methods, NULL, NULL, NULL, NULL }; + +PyObject * +PyInit__tsdate(void) +{ + PyObject *module = PyModule_Create(&tsdatemodule); + + if (module == NULL) { + return NULL; + } + /* Initialise numpy */ + import_array(); + + TsdLibraryError = PyErr_NewException("_tsdate.LibraryError", NULL, NULL); + Py_INCREF(TsdLibraryError); + PyModule_AddObject(module, "LibraryError", TsdLibraryError); + + return module; +} diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..4560adec --- /dev/null +++ b/codecov.yml @@ -0,0 +1,25 @@ +ignore: + - "lib/tests/" + +codecov: + require_ci_to_pass: false + +comment: + layout: "header, diff, flags, components" # show component info in the PR comment + +component_management: + individual_components: + - component_id: python_code + name: Python API + paths: + - tsdate/*.py + + - component_id: python_c_code + name: Python C interface + paths: + - _tsdatemodule.c + + - component_id: c_code + name: C library + paths: + - lib diff --git a/docs/installation.md b/docs/installation.md index b222e243..816b1a84 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -30,6 +30,10 @@ or $ tsdate +Binary wheels are provided for the common platforms. Building from source (e.g. +from the sdist, or a development checkout) requires a C compiler, as `tsdate` +includes a C extension module (`_tsdate`). + Alternatively, the {ref}`Python API ` allows more fine-grained control of the inference process. @@ -43,6 +47,9 @@ Install development dependencies with `uv sync` and run the tests with: $ uv run pytest +`uv sync` also (re)builds the C extension. After editing C code, run `uv sync` +(or `make`) again to rebuild it. + _Tsdate_ makes extensive use of [numba](https://numba.pydata.org)'s "just in time" (jit) compilation to speed up time-consuming numerical functions. Because of the need to compile these functions, loading the tsdate package can take diff --git a/lib/err.c b/lib/err.c new file mode 100644 index 00000000..7d241c75 --- /dev/null +++ b/lib/err.c @@ -0,0 +1,62 @@ +/* + * MIT License + * + * Copyright (c) 2026 Tskit Developers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +#include "err.h" + +const char * +tsd_strerror(int err) +{ + const char *ret = "Unknown error"; + + switch (err) { + case 0: + ret = "Normal exit condition. This is not an error!"; + break; + case TSD_ERR_GENERIC: + ret = "Generic tsdate error - please file a bug report."; + break; + case TSD_ERR_NO_MEMORY: + ret = "Out of memory"; + break; + case TSD_ERR_BAD_PARAM: + ret = "Bad parameter value provided"; + break; + default: + break; + } + return ret; +} + +void +_tsd_safe_free(void **ptr) +{ + if (ptr != NULL) { + if (*ptr != NULL) { + free(*ptr); + *ptr = NULL; + } + } +} diff --git a/lib/err.h b/lib/err.h new file mode 100644 index 00000000..294c9ebf --- /dev/null +++ b/lib/err.h @@ -0,0 +1,89 @@ +/* + * MIT License + * + * Copyright (c) 2026 Tskit Developers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef TSD_ERR_H +#define TSD_ERR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/* clang-format off */ +#define TSD_ERR_GENERIC -1 +#define TSD_ERR_NO_MEMORY -2 +#define TSD_ERR_BAD_PARAM -3 +/* clang-format on */ + +#ifdef __GNUC__ +#define WARN_UNUSED __attribute__((warn_unused_result)) +#define unlikely(expr) __builtin_expect(!!(expr), 0) +#define likely(expr) __builtin_expect(!!(expr), 1) +#else +#define WARN_UNUSED +#define unlikely(expr) (expr) +#define likely(expr) (expr) +#endif + +const char *tsd_strerror(int err); + +#ifdef TSD_TRACE_ERRORS + +static inline int +_tsd_trace_error(int err, int line, const char *file) +{ + fprintf(stderr, "tsdate-trace-error: %d='%s' at line %d in %s\n", err, + tsd_strerror(err), line, file); + return err; +} + +#define tsd_trace_error(err) (_tsd_trace_error(err, __LINE__, __FILE__)) +#else +#define tsd_trace_error(err) (err) +#endif + +#define TSD_BUG_ASSERT_MESSAGE \ + "Please report this bug at https://github.com/tskit-dev/tsdate/issues," \ + " ideally with a reproducible example." + +/* Cheap internal-invariant check that is always compiled in. */ +#define tsd_bug_assert(condition) \ + do { \ + if (!(condition)) { \ + fprintf(stderr, "Bug detected in %s at line %d. %s\n", __FILE__, __LINE__, \ + TSD_BUG_ASSERT_MESSAGE); \ + abort(); \ + } \ + } while (0) + +void _tsd_safe_free(void **ptr); +#define tsd_safe_free(pointer) _tsd_safe_free((void **) &(pointer)) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/meson.build b/lib/meson.build new file mode 100644 index 00000000..bbcc384f --- /dev/null +++ b/lib/meson.build @@ -0,0 +1,27 @@ +project('tsdate', 'c', default_options: ['c_std=c11']) + +cc = meson.get_compiler('c') +m_dep = cc.find_library('m', required : false) +cunit_dep = dependency('cunit') + +extra_c_args = [ + '-Wall', '-Wextra', '-Werror', '-Wpedantic', '-W', + '-Wmissing-prototypes', '-Wstrict-prototypes', + '-Wconversion', '-Wshadow', '-Wpointer-arith', '-Wcast-align', + '-Wcast-qual', '-Wwrite-strings', '-Wnested-externs', + '-fshort-enums', '-fno-common', '-ffp-contract=off'] + +if get_option('buildtype') == 'debug' + extra_c_args += ['-DTSD_TRACE_ERRORS'] +endif + +tsdate_sources = ['err.c'] + +tsdate_lib = static_library('tsdate', + sources: tsdate_sources, dependencies: [m_dep], + c_args: extra_c_args) + +unit_tests = executable('tests', + sources: ['tests/tests.c'], + link_with: [tsdate_lib], dependencies: [cunit_dep, m_dep]) +test('Unit tests', unit_tests) diff --git a/lib/tests/tests.c b/lib/tests/tests.c new file mode 100644 index 00000000..07c5e970 --- /dev/null +++ b/lib/tests/tests.c @@ -0,0 +1,159 @@ +/* + * MIT License + * + * Copyright (c) 2026 Tskit Developers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * Smoke tests for the low-level tsdate API. These check return codes and + * memory handling only; numerical correctness is tested from Python. + */ + +#include +#include +#include + +#include + +#include "tsdate.h" + +static void +test_strerror(void) +{ + const int codes[] = { 0, TSD_ERR_GENERIC, TSD_ERR_NO_MEMORY, TSD_ERR_BAD_PARAM }; + const int num_codes = (int) (sizeof(codes) / sizeof(codes[0])); + const char *msg_i; + const char *msg_j; + int i, j; + + for (i = 0; i < num_codes; i++) { + msg_i = tsd_strerror(codes[i]); + CU_ASSERT_FATAL(msg_i != NULL); + CU_ASSERT(strlen(msg_i) > 0); + for (j = 0; j < i; j++) { + msg_j = tsd_strerror(codes[j]); + CU_ASSERT(strcmp(msg_i, msg_j) != 0); + } + } +} + +static void +test_strerror_unknown(void) +{ + const char *msg = tsd_strerror(-12345); + + CU_ASSERT_FATAL(msg != NULL); + CU_ASSERT_STRING_EQUAL(msg, "Unknown error"); +} + +static void +test_trace_error(void) +{ + int ret = tsd_trace_error(TSD_ERR_BAD_PARAM); + + CU_ASSERT_EQUAL(ret, TSD_ERR_BAD_PARAM); +} + +static void +test_safe_free(void) +{ + double *x = NULL; + + tsd_safe_free(x); + CU_ASSERT_PTR_NULL(x); + + x = malloc(10 * sizeof(*x)); + CU_ASSERT_PTR_NOT_NULL_FATAL(x); + tsd_safe_free(x); + CU_ASSERT_PTR_NULL(x); + /* Freeing twice is harmless */ + tsd_safe_free(x); + CU_ASSERT_PTR_NULL(x); +} + +static void +test_bug_assert_passes(void) +{ + tsd_bug_assert(1 + 1 == 2); +} + +static void +handle_cunit_error(void) +{ + fprintf( + stderr, "CUnit error occurred: %d: %s\n", CU_get_error(), CU_get_error_msg()); + exit(EXIT_FAILURE); +} + +int +main(int argc, char **argv) +{ + int ret; + CU_pTest test; + CU_pSuite suite; + CU_TestInfo tests[] = { + { "test_strerror", test_strerror }, + { "test_strerror_unknown", test_strerror_unknown }, + { "test_trace_error", test_trace_error }, + { "test_safe_free", test_safe_free }, + { "test_bug_assert_passes", test_bug_assert_passes }, + CU_TEST_INFO_NULL, + }; + CU_SuiteInfo suites[] = { + { .pName = "tsdate", .pInitFunc = NULL, .pCleanupFunc = NULL, .pTests = tests }, + CU_SUITE_INFO_NULL, + }; + + if (CUE_SUCCESS != CU_initialize_registry()) { + handle_cunit_error(); + } + if (CUE_SUCCESS != CU_register_suites(suites)) { + handle_cunit_error(); + } + CU_basic_set_mode(CU_BRM_VERBOSE); + + if (argc == 1) { + CU_basic_run_tests(); + } else if (argc == 2) { + suite = CU_get_suite_by_name("tsdate", CU_get_registry()); + if (suite == NULL) { + printf("Suite not found\n"); + return EXIT_FAILURE; + } + test = CU_get_test_by_name(argv[1], suite); + if (test == NULL) { + printf("Test '%s' not found\n", argv[1]); + return EXIT_FAILURE; + } + CU_basic_run_test(suite, test); + } else { + printf("usage: ./tests \n"); + return EXIT_FAILURE; + } + + ret = EXIT_SUCCESS; + if (CU_get_number_of_tests_failed() != 0) { + printf("Test failed!\n"); + ret = EXIT_FAILURE; + } + CU_cleanup_registry(); + return ret; +} diff --git a/lib/tsdate.h b/lib/tsdate.h new file mode 100644 index 00000000..96575cc6 --- /dev/null +++ b/lib/tsdate.h @@ -0,0 +1,45 @@ +/* + * MIT License + * + * Copyright (c) 2026 Tskit Developers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef TSDATE_H +#define TSDATE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include "err.h" + +/* Node, edge, mutation and block ids; matches the tskit id arrays. */ +typedef int32_t tsd_id_t; +/* Counts and sizes; matches tsk_size_t. */ +typedef uint64_t tsd_size_t; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/prek.toml b/prek.toml index 593f6ae3..fcd42474 100644 --- a/prek.toml +++ b/prek.toml @@ -39,6 +39,19 @@ hooks = [ }, ] +[[repos]] +repo = "local" +hooks = [ + { + id = "clang-format", + name = "clang-format", + language = "system", + entry = "uv run --only-group=lint clang-format -i", + types = ["c"], + verbose = true, + }, +] + [[repos]] repo = "local" hooks = [ diff --git a/pyproject.toml b/pyproject.toml index 6cf39594..1e26d170 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,6 +3,7 @@ requires = [ "setuptools>=42", "setuptools_scm", "wheel", + "numpy>=2", ] build-backend = "setuptools.build_meta" @@ -94,6 +95,7 @@ docs = [ ] lint = [ + "clang-format==21.1.8", "ruff==0.15.1", "prek==0.3.3", "zizmor==1.26.1", @@ -101,6 +103,7 @@ lint = [ packaging = [ "twine", + "cibuildwheel", "validate-pyproject[all]", ] @@ -148,3 +151,27 @@ known-third-party = [ "pytest", ] + +[tool.cibuildwheel] +build = ["cp311-*", "cp312-*", "cp313-*"] +build-frontend = "build" +build-verbosity = 1 +test-command = [ + "python -c \"import _tsdate\"", + "tsdate --help", +] + +[tool.cibuildwheel.linux] +archs = ["x86_64"] +skip = ["*musllinux*"] + +[tool.uv] +# Rebuild the editable install (and so the C extension) when the C sources change. +cache-keys = [ + { file = "pyproject.toml" }, + { file = "setup.py" }, + { file = "_tsdatemodule.c" }, + { file = "lib/*.c" }, + { file = "lib/*.h" }, + { git = { commit = true } }, +] diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..e9b07c08 --- /dev/null +++ b/setup.py @@ -0,0 +1,30 @@ +import os +import platform + +import numpy +from setuptools import Extension, setup + +IS_WINDOWS = platform.system() == "Windows" + +libdir = "lib" +includes = [libdir] + +tsd_source_files = ["err.c"] + +sources = ["_tsdatemodule.c"] + [os.path.join(libdir, f) for f in tsd_source_files] + +# Unlike tsinfer we do not undefine NDEBUG: assert() is for expensive checks and +# is compiled out of the Python module; tsd_bug_assert is always on. +# -ffp-contract=off stops clang fusing multiply-adds, which would change results. +extra_compile_args = [] if IS_WINDOWS else ["-std=c11", "-ffp-contract=off"] + +_tsdate_module = Extension( + "_tsdate", + sources=sources, + extra_compile_args=extra_compile_args, + include_dirs=includes + [numpy.get_include()], +) + +setup( + ext_modules=[_tsdate_module], +) diff --git a/tests/test_python_c.py b/tests/test_python_c.py new file mode 100644 index 00000000..d3d5def1 --- /dev/null +++ b/tests/test_python_c.py @@ -0,0 +1,66 @@ +""" +Tests for the low-level _tsdate C module. +""" + +import _tsdate +import pytest + +ERR_GENERIC = -1 +ERR_NO_MEMORY = -2 +ERR_BAD_PARAM = -3 +ALL_ERRORS = [ERR_GENERIC, ERR_NO_MEMORY, ERR_BAD_PARAM] + + +class TestModule: + def test_name(self): + assert _tsdate.__name__ == "_tsdate" + + def test_library_error_is_exception(self): + assert issubclass(_tsdate.LibraryError, Exception) + assert _tsdate.LibraryError.__name__ == "LibraryError" + + +class TestStrerror: + def test_success_code(self): + assert "not an error" in _tsdate.strerror(0) + + @pytest.mark.parametrize("code", ALL_ERRORS) + def test_known_codes(self, code): + message = _tsdate.strerror(code) + assert isinstance(message, str) + assert len(message) > 0 + + def test_messages_distinct(self): + messages = {_tsdate.strerror(code) for code in [0, *ALL_ERRORS]} + assert len(messages) == len(ALL_ERRORS) + 1 + + def test_unknown_code(self): + assert _tsdate.strerror(-12345) == "Unknown error" + + @pytest.mark.parametrize("bad_arg", ["x", None, 1.5]) + def test_bad_argument(self, bad_arg): + with pytest.raises(TypeError): + _tsdate.strerror(bad_arg) + + def test_no_arguments(self): + with pytest.raises(TypeError): + _tsdate.strerror() + + +class TestRaiseLibraryError: + @pytest.mark.parametrize("code", [ERR_GENERIC, ERR_BAD_PARAM]) + def test_raises_library_error(self, code): + with pytest.raises(_tsdate.LibraryError, match=_tsdate.strerror(code)): + _tsdate.raise_library_error(code) + + def test_no_memory_is_memory_error(self): + with pytest.raises(MemoryError): + _tsdate.raise_library_error(ERR_NO_MEMORY) + + def test_unknown_code(self): + with pytest.raises(_tsdate.LibraryError, match="Unknown error"): + _tsdate.raise_library_error(-12345) + + def test_bad_argument(self): + with pytest.raises(TypeError): + _tsdate.raise_library_error("x") diff --git a/uv.lock b/uv.lock index 060621d4..975321a4 100644 --- a/uv.lock +++ b/uv.lock @@ -9,10 +9,10 @@ resolution-markers = [ "python_full_version >= '3.12' and python_full_version < '3.14' and sys_platform == 'emscripten'", "python_full_version >= '3.12' and python_full_version < '3.14' and sys_platform != 'emscripten' and sys_platform != 'win32'", "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform == 'win32'", - "python_full_version < '3.11.5' and sys_platform == 'win32'", "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform == 'emscripten'", - "python_full_version < '3.11.5' and sys_platform == 'emscripten'", "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform != 'emscripten' and sys_platform != 'win32'", + "python_full_version < '3.11.5' and sys_platform == 'win32'", + "python_full_version < '3.11.5' and sys_platform == 'emscripten'", "python_full_version < '3.11.5' and sys_platform != 'emscripten' and sys_platform != 'win32'", ] @@ -100,6 +100,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/b9/fa/123043af240e49752f1c4bd24da5053b6bd00cad78c2be53c0d1e8b975bc/backports.tarfile-1.2.0-py3-none-any.whl", hash = "sha256:77e284d754527b01fb1e6fa8a1afe577858ebe4e9dad8919e34c862cb399bc34", size = 30181, upload-time = "2024-05-28T17:01:53.112Z" }, ] +[[package]] +name = "bashlex" +version = "0.18" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/76/60/aae0bb54f9af5e0128ba90eb83d8d0d506ee8f0475c4fdda3deeda20b1d2/bashlex-0.18.tar.gz", hash = "sha256:5bb03a01c6d5676338c36fd1028009c8ad07e7d61d8a1ce3f513b7fff52796ee", size = 68742, upload-time = "2023-01-18T15:21:26.402Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f4/be/6985abb1011fda8a523cfe21ed9629e397d6e06fb5bae99750402b25c95b/bashlex-0.18-py2.py3-none-any.whl", hash = "sha256:91d73a23a3e51711919c1c899083890cdecffc91d8c088942725ac13e9dcfffa", size = 69539, upload-time = "2023-01-18T15:21:24.167Z" }, +] + [[package]] name = "beautifulsoup4" version = "4.15.0" @@ -114,6 +123,29 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/88/c6/92fcd42f1ba33e1184263f25bfabf3d27c383410470f169e4b8163bf9c17/beautifulsoup4-4.15.0-py3-none-any.whl", hash = "sha256:d6f88de62e1d4e38ecb1077eb9724cd0eff29d2a08ca16a401e9b9e93f117cf9", size = 109924, upload-time = "2026-06-07T16:44:21.566Z" }, ] +[[package]] +name = "bracex" +version = "3.2.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/42/39/9ae971118d77b86cc3f03ab5a467ddb58de352d8ef29830c81531d22010c/bracex-3.2.3.tar.gz", hash = "sha256:8fbf92b4db3c31de999145e22a47d4ffdbefb983a98583c3272bd7d570f9a343", size = 35266, upload-time = "2026-11-14T17:11:16.858Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c8/42/f5d49972873bd3fff36e736ad1fcb36f9fdadb1ad577dfcfa17777dc84f0/bracex-3.2.3-py3-none-any.whl", hash = "sha256:8d6d677856121820d67b9009e76a5740fb02ab6dcd2d9815a83724d1888c305d", size = 14182, upload-time = "2026-11-14T17:11:15.595Z" }, +] + +[[package]] +name = "build" +version = "1.6.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "os_name == 'nt'" }, + { name = "packaging" }, + { name = "pyproject-hooks" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/bd/67/4898a44ea4f3f8e213b0954ec0aa0a16971d62a6212d6ea3931e97115b99/build-1.6.1.tar.gz", hash = "sha256:51cc11666391ab6f092070437ac747002ff46f3e4113a3622177ee6b488bfc53", size = 113427, upload-time = "2026-09-10T07:56:00.417Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ad/9b/9fb3585dabcd73a1b2a6267f63f62649347c9e6d072c9fde365b105abb2c/build-1.6.1-py3-none-any.whl", hash = "sha256:ecd351a4be9d35a9eaaba244a7687143c9c7d4aea6ac964e7e7ddab20cbcf4e7", size = 31179, upload-time = "2026-09-10T07:55:59.148Z" }, +] + [[package]] name = "certifi" version = "2026.10.23" @@ -368,6 +400,51 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/fc/ad/d07d7862a62ffa6d79d68074d14823243dd235a77c45262acbf6adeb28bf/charset_normalizer-3.5.2-py3-none-any.whl", hash = "sha256:b6b751274acb69d77b3323d6b7dbaa3c7fdfc1eb829b7eb61d262f32e1af9685", size = 68872, upload-time = "2026-09-30T04:39:21.828Z" }, ] +[[package]] +name = "cibuildwheel" +version = "4.3.5" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "bashlex" }, + { name = "bracex" }, + { name = "build" }, + { name = "certifi" }, + { name = "dependency-groups" }, + { name = "filelock" }, + { name = "humanize" }, + { name = "packaging" }, + { name = "platformdirs" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/97/08/284f916363482d28ba98cf4517283f89ec5c3bd8acfa43b1049b9a5ed486/cibuildwheel-4.3.5.tar.gz", hash = "sha256:43c30292b9ec8d08a8eb3873436e64d4d1434c5dcbc855fb0afbfc69732048f1", size = 464371, upload-time = "2026-10-27T19:01:55.682Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c9/ad/ebdaf81b0f29b86906a6c4ad0253796204853111fdd3a1d041d7b1bf92d0/cibuildwheel-4.3.5-py3-none-any.whl", hash = "sha256:2297362cb7a0a12cd681788197811e1f3d700bd31f6decaab051837c90d4e3ba", size = 170368, upload-time = "2026-10-27T19:01:53.729Z" }, +] + +[[package]] +name = "clang-format" +version = "21.1.8" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/29/ed/019e682e9f8a5a5abf4258b293453092ef9524b540ada591ccfdff1246df/clang_format-21.1.8.tar.gz", hash = "sha256:99369fe76526ba6be6d7a8093fee6cd266bbf5ce72597a0d79a4ce9a625b28cf", size = 11509, upload-time = "2025-12-16T20:34:33.065Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/17/1d/4b1d85acb99a2ee3bad0b20cc3e82c58fbfb39bf4dd5856ac1f2c4f36e65/clang_format-21.1.8-py2.py3-none-macosx_10_9_x86_64.whl", hash = "sha256:f447091c346027a09728a0a96128fe058419fe06cf200ccc3dc98bcd4399e351", size = 1465604, upload-time = "2025-12-16T20:34:03.955Z" }, + { url = "https://files.pythonhosted.org/packages/84/38/a61466227a8a6bf22c583f7bd810e75c9a356cfc63c6a712a201103a4ad3/clang_format-21.1.8-py2.py3-none-macosx_11_0_arm64.whl", hash = "sha256:9a78fabba6b382866819b42a7b220d235a3baf6128a40fb7bd590c037f69879b", size = 1459014, upload-time = "2025-12-16T20:34:05.929Z" }, + { url = "https://files.pythonhosted.org/packages/ab/5d/6720c895c5cfc01831fac55ecf849f10d03d6222700909af14f6047c933b/clang_format-21.1.8-py2.py3-none-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c2a044953efab5f7d0261f3a76aabc01358592faac1b73af38d8c83db6e91a69", size = 1725482, upload-time = "2025-12-16T20:34:07.525Z" }, + { url = "https://files.pythonhosted.org/packages/54/0d/074b940884ced1b5c93e2e7fc8a941673519a938e7f31aeade321e3ab094/clang_format-21.1.8-py2.py3-none-manylinux_2_26_i686.manylinux_2_28_i686.whl", hash = "sha256:143d2dffa71058d05ac5ad71321682e23d638bce22c8f2e3d01ed457d841a5f3", size = 1856680, upload-time = "2025-12-16T20:34:09.987Z" }, + { url = "https://files.pythonhosted.org/packages/34/d5/46e22ae8c4385a7836db7403ced63ea8056c971cbb806bf0c6f0d2133acc/clang_format-21.1.8-py2.py3-none-manylinux_2_26_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:6a4b61a743dad5afc5e60be0c5c8f162f6cf27fff9eed56ec0bf65c2bcbd8a8d", size = 2031282, upload-time = "2025-12-16T20:34:11.565Z" }, + { url = "https://files.pythonhosted.org/packages/e0/2a/cad75567c312d945cc26aaee7e1b7135703fed9c7e7ad15c427bf6ad7a84/clang_format-21.1.8-py2.py3-none-manylinux_2_26_s390x.manylinux_2_28_s390x.whl", hash = "sha256:94de66c5eeca1270825348687d384750d91f1d8d12216b2df0aea892859be33a", size = 2047763, upload-time = "2025-12-16T20:34:13.175Z" }, + { url = "https://files.pythonhosted.org/packages/a8/c2/403e7371b1ab0f6175d708ecc93cf18085ea9f903e8fe7d17c43df698f06/clang_format-21.1.8-py2.py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d12b864b596b80810cdd7f97556c485dc09cfe2952503958535f01359e025fbb", size = 1804755, upload-time = "2025-12-16T20:34:14.813Z" }, + { url = "https://files.pythonhosted.org/packages/76/33/9e7db5fc4abefb25022d266957f666bfc263ae3e51abdd2c997d2880ceee/clang_format-21.1.8-py2.py3-none-manylinux_2_31_armv7l.whl", hash = "sha256:b81f1e909f5e7ef862a7818dc22b302a3ff407f3534e3395aa7ba26746cc890e", size = 1643208, upload-time = "2025-12-16T20:34:16.898Z" }, + { url = "https://files.pythonhosted.org/packages/aa/9f/43f4e384cb8943418f94943f682835f375f15b9cc64c526d73a7360f2b2f/clang_format-21.1.8-py2.py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:e10a5dca18a04997ad55c082bc0759edc7e337b24a2373ded109634fde12662a", size = 2701696, upload-time = "2025-12-16T20:34:19.043Z" }, + { url = "https://files.pythonhosted.org/packages/5d/6a/378187d72a465cebd3dbf7cd455e33b4931daa33e815b7865e6e65591a72/clang_format-21.1.8-py2.py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:10f7d7004d70b5e03fd3f764fc19fae89cd38d68b3482162cb09cac47c12c7b0", size = 2481266, upload-time = "2025-12-16T20:34:20.336Z" }, + { url = "https://files.pythonhosted.org/packages/99/eb/2332edb1846d6832932191a590203a53ec69f585e718b51796335a1dcb6e/clang_format-21.1.8-py2.py3-none-musllinux_1_2_i686.whl", hash = "sha256:303d5fd53090422119136b1a458e98db429dedd5db0add50e70f885f8c95d82a", size = 2954000, upload-time = "2025-12-16T20:34:21.739Z" }, + { url = "https://files.pythonhosted.org/packages/7b/b5/eed5c95521b77d3cde024c3a23c7a80c46e78aa5b5a81c5cf935e7267588/clang_format-21.1.8-py2.py3-none-musllinux_1_2_ppc64le.whl", hash = "sha256:6b9e0b45cfaf4a18336a6db4666dd6a6aae840e38b038e6d568a65f43ade007c", size = 3076720, upload-time = "2025-12-16T20:34:23.139Z" }, + { url = "https://files.pythonhosted.org/packages/14/55/7527fbe31423a1bb53653c2a2b20aa34a73ec33b99199bceaec0f5907295/clang_format-21.1.8-py2.py3-none-musllinux_1_2_s390x.whl", hash = "sha256:4dd0fee9eaee9915ba7fa08e60ee9ddfba1f754d10d71164482d9eb387c431f0", size = 3160892, upload-time = "2025-12-16T20:34:24.618Z" }, + { url = "https://files.pythonhosted.org/packages/53/61/1623382bc78ef139c196473a5c76b840a071c9002cb5cd2694ac50327db9/clang_format-21.1.8-py2.py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:9731aecf954651004f184347d0c589d4e91a39ccda21262ee17c60f80a4408b2", size = 2812487, upload-time = "2025-12-16T20:34:26.505Z" }, + { url = "https://files.pythonhosted.org/packages/53/e1/74f2000d44e4904472e5685afb98d19566c515026214733f02bbdc73d6d8/clang_format-21.1.8-py2.py3-none-win32.whl", hash = "sha256:2f5883ca83f718d8c2272e98b3cbda422fec520824b5a1e335c631dc6d812da7", size = 1271310, upload-time = "2025-12-16T20:34:28.179Z" }, + { url = "https://files.pythonhosted.org/packages/69/7a/c49c8af9135c6a6dfb9cd103328ba7b6551643dce71b57e58ea940884015/clang_format-21.1.8-py2.py3-none-win_amd64.whl", hash = "sha256:a7606da55e31ebf5b63dd75800392e6cca7c595a74100c2cebcda2d742130732", size = 1426467, upload-time = "2025-12-16T20:34:29.805Z" }, + { url = "https://files.pythonhosted.org/packages/ad/d3/8790b539afb6cb0d4474705d3750e78a1f0847ab6d3ef1b00dd1ae52f364/clang_format-21.1.8-py2.py3-none-win_arm64.whl", hash = "sha256:1aa10b3f647268361d08bf4f17ce70964b8d9c04d5539e7d8acbebd14dc4a49c", size = 1327254, upload-time = "2025-12-16T20:34:31.579Z" }, +] + [[package]] name = "click" version = "8.5.0" @@ -401,10 +478,10 @@ version = "1.3.3" source = { registry = "https://pypi.org/simple" } resolution-markers = [ "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform == 'win32'", - "python_full_version < '3.11.5' and sys_platform == 'win32'", "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform == 'emscripten'", - "python_full_version < '3.11.5' and sys_platform == 'emscripten'", "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform != 'emscripten' and sys_platform != 'win32'", + "python_full_version < '3.11.5' and sys_platform == 'win32'", + "python_full_version < '3.11.5' and sys_platform == 'emscripten'", "python_full_version < '3.11.5' and sys_platform != 'emscripten' and sys_platform != 'win32'", ] dependencies = [ @@ -830,16 +907,28 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/de/3c/9a80d239cbad95418816187cb39bd946ec78b8552e8704ff692d50327674/demesdraw-0.4.1-py3-none-any.whl", hash = "sha256:023cf309ec5587b99f2edf85396e76eafd5f6492a5deaec85d91515367c4d2e5", size = 23456, upload-time = "2025-10-04T10:17:52.843Z" }, ] +[[package]] +name = "dependency-groups" +version = "1.3.2" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "packaging" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b5/16/65e61d8e837e0d70a99a0d4dd76e2af53357c3a03ed1db8ad9b5786d7f25/dependency_groups-1.3.2.tar.gz", hash = "sha256:c81831f43828dbc3987ee247eb198241a0152b8e7ceab10977cc3808eb388ac7", size = 13309, upload-time = "2026-08-22T02:43:30.137Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a1/e4/da5f2f176050efcfb9222a76a3e81c41f69f775be8e563b76ca4292a134f/dependency_groups-1.3.2-py3-none-any.whl", hash = "sha256:8c337f7b92445823b0d0ea507f611390c58dcd2112be00aebcd738a2ca7a1c64", size = 9802, upload-time = "2026-08-22T02:43:28.853Z" }, +] + [[package]] name = "deprecated" version = "1.3.1" source = { registry = "https://pypi.org/simple" } resolution-markers = [ "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform == 'win32'", - "python_full_version < '3.11.5' and sys_platform == 'win32'", "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform == 'emscripten'", - "python_full_version < '3.11.5' and sys_platform == 'emscripten'", "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform != 'emscripten' and sys_platform != 'win32'", + "python_full_version < '3.11.5' and sys_platform == 'win32'", + "python_full_version < '3.11.5' and sys_platform == 'emscripten'", "python_full_version < '3.11.5' and sys_platform != 'emscripten' and sys_platform != 'win32'", ] dependencies = [ @@ -915,6 +1004,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/49/82/2755c7c982086f00d4dab85bc120ec35045a9fc2191893a6ce79afe94443/fastjsonschema-2.22.2-py3-none-any.whl", hash = "sha256:0fb3915616adac85ccfdd737d26be1089845d2019819505b42d39888458f74d4", size = 27413, upload-time = "2026-08-15T19:47:04.406Z" }, ] +[[package]] +name = "filelock" +version = "4.2.12" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/52/aa/8ccff8da9a27e089727fcffd3c5b61708383217e47eb1e1b8af37b1dd166/filelock-4.2.12.tar.gz", hash = "sha256:7e7da24d3ac39268b0f156e56870001de44886318f092f9d851e692f7114d6dd", size = 680837, upload-time = "2026-11-18T01:20:03.951Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/8a/c9/eb6b6528c7edb958d4c24ac47a8b94113d9de36e4cfc6eecd599b1a4f349/filelock-4.2.12-py3-none-any.whl", hash = "sha256:21decfec02f116ed4c954433cdb31f28c3b346b784543177b6d7059da2702ee9", size = 222442, upload-time = "2026-11-18T01:20:02.439Z" }, +] + [[package]] name = "fonttools" version = "4.68.0" @@ -2042,10 +2140,10 @@ version = "2.4.6" source = { registry = "https://pypi.org/simple" } resolution-markers = [ "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform == 'win32'", - "python_full_version < '3.11.5' and sys_platform == 'win32'", "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform == 'emscripten'", - "python_full_version < '3.11.5' and sys_platform == 'emscripten'", "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform != 'emscripten' and sys_platform != 'win32'", + "python_full_version < '3.11.5' and sys_platform == 'win32'", + "python_full_version < '3.11.5' and sys_platform == 'emscripten'", "python_full_version < '3.11.5' and sys_platform != 'emscripten' and sys_platform != 'win32'", ] sdist = { url = "https://files.pythonhosted.org/packages/d0/ad/fed0499ce6a338d2a03ebae59cd15093910c8875328855781952abf6c2fe/numpy-2.4.6.tar.gz", hash = "sha256:f3a3570c4a2a16746ac2c31a7c7c7b0c186b95ce902e33db6f28094ed7387dda", size = 20735807, upload-time = "2026-05-18T23:37:14.07Z" } @@ -2566,6 +2664,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/38/bb/d215ee7c73b61497b28a5503f9f53523f294fcc936762b7caf90e0c1c2b5/pyparsing-3.3.3-py3-none-any.whl", hash = "sha256:ece8c00a69cf01b45d0b1dedabb469c90d8caf996d4fda40f147627a122849a4", size = 126420, upload-time = "2026-09-20T20:59:04.025Z" }, ] +[[package]] +name = "pyproject-hooks" +version = "1.3.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/6d/5d/f2ddeef4a855a102aaae5e97826a0260007522ab504421b75addfdb1517c/pyproject_hooks-1.3.3.tar.gz", hash = "sha256:defda19b854fa0d3bd4f76ea4ddcba8abd7dcfcdd585a6690ade050744fc5f43", size = 21013, upload-time = "2026-09-16T08:58:03.999Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/85/11/044d1ae1b4ec0d7af88ee5bc91e081be1022533032b906a7bdabdbb60977/pyproject_hooks-1.3.3-py3-none-any.whl", hash = "sha256:5fc53fdac9f7bd63fbcdc868fb5f90b4784d78a53a3d3388cd738b807441a20b", size = 10724, upload-time = "2026-09-16T08:58:02.96Z" }, +] + [[package]] name = "pyslim" version = "1.1.1" @@ -3026,10 +3133,10 @@ version = "1.17.1" source = { registry = "https://pypi.org/simple" } resolution-markers = [ "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform == 'win32'", - "python_full_version < '3.11.5' and sys_platform == 'win32'", "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform == 'emscripten'", - "python_full_version < '3.11.5' and sys_platform == 'emscripten'", "python_full_version >= '3.11.5' and python_full_version < '3.12' and sys_platform != 'emscripten' and sys_platform != 'win32'", + "python_full_version < '3.11.5' and sys_platform == 'win32'", + "python_full_version < '3.11.5' and sys_platform == 'emscripten'", "python_full_version < '3.11.5' and sys_platform != 'emscripten' and sys_platform != 'win32'", ] dependencies = [ @@ -3718,6 +3825,8 @@ dependencies = [ [package.dev-dependencies] dev = [ + { name = "cibuildwheel" }, + { name = "clang-format" }, { name = "demesdraw" }, { name = "ipywidgets" }, { name = "jupyter-book" }, @@ -3755,11 +3864,13 @@ docs = [ { name = "tsinfer" }, ] lint = [ + { name = "clang-format" }, { name = "prek" }, { name = "ruff" }, { name = "zizmor" }, ] packaging = [ + { name = "cibuildwheel" }, { name = "twine" }, { name = "validate-pyproject", extra = ["all"] }, ] @@ -3786,6 +3897,8 @@ requires-dist = [ [package.metadata.requires-dev] dev = [ + { name = "cibuildwheel" }, + { name = "clang-format", specifier = "==21.1.8" }, { name = "demesdraw" }, { name = "ipywidgets" }, { name = "jupyter-book", specifier = "<2" }, @@ -3823,11 +3936,13 @@ docs = [ { name = "tsinfer" }, ] lint = [ + { name = "clang-format", specifier = "==21.1.8" }, { name = "prek", specifier = "==0.3.3" }, { name = "ruff", specifier = "==0.15.1" }, { name = "zizmor", specifier = "==1.26.1" }, ] packaging = [ + { name = "cibuildwheel" }, { name = "twine" }, { name = "validate-pyproject", extras = ["all"] }, ] From 846c3be5ef4050ad3472c64d4b47758e9100efc1 Mon Sep 17 00:00:00 2001 From: Nate Pope Date: Wed, 18 Nov 2026 14:59:55 -0800 Subject: [PATCH 2/5] Fix CI errors --- pyproject.toml | 3 ++- uv.lock | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1e26d170..60089ddd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,6 +69,7 @@ tsdate = "tsdate.__main__:main" [dependency-groups] test = [ + "setuptools", "pytest", "pytest-xdist", "pytest-cov", @@ -156,6 +157,7 @@ known-third-party = [ build = ["cp311-*", "cp312-*", "cp313-*"] build-frontend = "build" build-verbosity = 1 +skip = ["*musllinux*"] test-command = [ "python -c \"import _tsdate\"", "tsdate --help", @@ -163,7 +165,6 @@ test-command = [ [tool.cibuildwheel.linux] archs = ["x86_64"] -skip = ["*musllinux*"] [tool.uv] # Rebuild the editable install (and so the C extension) when the C sources change. diff --git a/uv.lock b/uv.lock index 975321a4..2f12d3ec 100644 --- a/uv.lock +++ b/uv.lock @@ -3839,6 +3839,7 @@ dev = [ { name = "pytest-cov" }, { name = "pytest-xdist" }, { name = "ruff" }, + { name = "setuptools" }, { name = "sphinx-argparse" }, { name = "sphinx-book-theme" }, { name = "sphinx-issues" }, @@ -3881,6 +3882,7 @@ test = [ { name = "pytest" }, { name = "pytest-cov" }, { name = "pytest-xdist" }, + { name = "setuptools" }, { name = "tsinfer" }, ] @@ -3911,6 +3913,7 @@ dev = [ { name = "pytest-cov" }, { name = "pytest-xdist" }, { name = "ruff", specifier = "==0.15.1" }, + { name = "setuptools" }, { name = "sphinx-argparse", specifier = "<0.6" }, { name = "sphinx-book-theme" }, { name = "sphinx-issues" }, @@ -3953,6 +3956,7 @@ test = [ { name = "pytest" }, { name = "pytest-cov" }, { name = "pytest-xdist" }, + { name = "setuptools" }, { name = "tsinfer" }, ] From aef820be13df278b25ac38cee1129ad5ca277aeb Mon Sep 17 00:00:00 2001 From: Nate Pope Date: Thu, 19 Nov 2026 05:57:33 -0800 Subject: [PATCH 3/5] Fix release wheel build and extend wheel coverage (skip win32) --- pyproject.toml | 14 ++++++++++++-- uv.lock | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 60089ddd..8caafeae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,6 +108,10 @@ packaging = [ "validate-pyproject[all]", ] +wheels = [ + "cibuildwheel", +] + dev = [ {include-group = "docs"}, {include-group = "lint"}, @@ -154,10 +158,16 @@ known-third-party = [ [tool.cibuildwheel] -build = ["cp311-*", "cp312-*", "cp313-*"] +build = ["cp311-*", "cp312-*", "cp313-*", "cp314-*", "cp315-*"] build-frontend = "build" build-verbosity = 1 -skip = ["*musllinux*"] +# scipy and numba publish no win32 wheels, and numba none for musllinux, so +# installing these wheels would mean building the dependencies from source. +skip = ["*musllinux*", "*-win32"] +# numba publishes no macOS x86_64 wheels after 0.62.1 (none at all for +# Python >= 3.14), so the install test fails there. Build these wheels, but +# only test them once numba is no longer a dependency. +test-skip = ["*-macosx_x86_64"] test-command = [ "python -c \"import _tsdate\"", "tsdate --help", diff --git a/uv.lock b/uv.lock index 2f12d3ec..b46f01c8 100644 --- a/uv.lock +++ b/uv.lock @@ -3885,6 +3885,9 @@ test = [ { name = "setuptools" }, { name = "tsinfer" }, ] +wheels = [ + { name = "cibuildwheel" }, +] [package.metadata] requires-dist = [ @@ -3959,6 +3962,7 @@ test = [ { name = "setuptools" }, { name = "tsinfer" }, ] +wheels = [{ name = "cibuildwheel" }] [[package]] name = "tsinfer" From aebc7882a21f38e9ddc7bc565aad6bdf41a4aa0b Mon Sep 17 00:00:00 2001 From: Nate Pope Date: Thu, 19 Nov 2026 07:43:01 -0800 Subject: [PATCH 4/5] build apple silicon wheels on macos-15 (macos-14 runner is retired) --- .github/workflows/wheels.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index ed1cc8d5..6fbf4400 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -12,6 +12,10 @@ permissions: jobs: build-wheels: uses: tskit-dev/.github/.github/workflows/build-wheels.yml@v22 + with: + # The shared default still lists macos-14, which GitHub no longer runs; + # macos-15 is its Apple Silicon replacement. + os-list: '["ubuntu-24.04", "windows-2025", "macos-15-intel", "macos-15"]' publish: runs-on: ubuntu-24.04 From 196fa28f83481c1b5118190e5cd0ff64d42fd1ae Mon Sep 17 00:00:00 2001 From: Nate Pope Date: Thu, 19 Nov 2026 15:08:33 -0800 Subject: [PATCH 5/5] Use tskit-dev shared workflows v23; add Python 3.14/3.15 classifiers --- .github/workflows/docs.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/tests.yml | 8 ++++---- .github/workflows/wheels.yml | 6 +----- pyproject.toml | 2 ++ 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 4aa61db0..ffb16252 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -12,4 +12,4 @@ jobs: Docs: permissions: contents: read - uses: tskit-dev/.github/.github/workflows/docs.yml@v22 + uses: tskit-dev/.github/.github/workflows/docs.yml@v23 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b83f707d..5186d20e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,4 +7,4 @@ jobs: Lint: permissions: contents: read - uses: tskit-dev/.github/.github/workflows/lint.yml@v22 + uses: tskit-dev/.github/.github/workflows/lint.yml@v23 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9b065e4f..d0af1aa2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,7 +11,7 @@ jobs: name: Python packaging permissions: contents: read - uses: tskit-dev/.github/.github/workflows/python-packaging.yml@v22 + uses: tskit-dev/.github/.github/workflows/python-packaging.yml@v23 with: cli-test-cmd: tsdate --help @@ -19,7 +19,7 @@ jobs: name: C tests permissions: contents: read - uses: tskit-dev/.github/.github/workflows/c-tests.yml@v22 + uses: tskit-dev/.github/.github/workflows/c-tests.yml@v23 with: library-directory: lib secrets: @@ -29,7 +29,7 @@ jobs: name: Python-C tests permissions: contents: read - uses: tskit-dev/.github/.github/workflows/python-c-tests.yml@v22 + uses: tskit-dev/.github/.github/workflows/python-c-tests.yml@v23 secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} @@ -37,7 +37,7 @@ jobs: name: Python permissions: contents: read - uses: tskit-dev/.github/.github/workflows/python-tests.yml@v22 + uses: tskit-dev/.github/.github/workflows/python-tests.yml@v23 with: os: ${{ matrix.os }} python-version: ${{ matrix.python }} diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 6fbf4400..31bce87d 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -11,11 +11,7 @@ permissions: jobs: build-wheels: - uses: tskit-dev/.github/.github/workflows/build-wheels.yml@v22 - with: - # The shared default still lists macos-14, which GitHub no longer runs; - # macos-15 is its Apple Silicon replacement. - os-list: '["ubuntu-24.04", "windows-2025", "macos-15-intel", "macos-15"]' + uses: tskit-dev/.github/.github/workflows/build-wheels.yml@v23 publish: runs-on: ubuntu-24.04 diff --git a/pyproject.toml b/pyproject.toml index 8caafeae..6a302b1a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,8 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", + "Programming Language :: Python :: 3.15", "Programming Language :: Python :: 3 :: Only", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Bio-Informatics",