From ea9b259b65cc533c8fb050fbc39c7ad6a5de53ac Mon Sep 17 00:00:00 2001 From: Mark Grassi <17365607+markgras@users.noreply.github.com> Date: Thu, 7 Dec 2023 23:09:40 -0500 Subject: [PATCH 1/4] Declare setuptools build dependency per PEP 517 --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..fed528d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" From ae2bee3d727a60258becc50e0a778204957986a1 Mon Sep 17 00:00:00 2001 From: Mark Grassi <17365607+markgras@users.noreply.github.com> Date: Thu, 7 Dec 2023 23:10:39 -0500 Subject: [PATCH 2/4] Drop support for Python < 3.6 --- cbitstruct/_cbitstruct.c | 2 - cbitstruct/clinic/_cbitstruct.c.35.h | 620 -------------------- cbitstruct/tests/original/test_bitstruct.py | 1 - cbitstruct/tests/test_bitstruct.py | 1 - setup.py | 13 +- 5 files changed, 6 insertions(+), 631 deletions(-) delete mode 100644 cbitstruct/clinic/_cbitstruct.c.35.h diff --git a/cbitstruct/_cbitstruct.c b/cbitstruct/_cbitstruct.c index 58b24cf..47fa627 100644 --- a/cbitstruct/_cbitstruct.c +++ b/cbitstruct/_cbitstruct.c @@ -833,8 +833,6 @@ typedef struct { #include "clinic/_cbitstruct.c.37.h" #elif PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 6 #include "clinic/_cbitstruct.c.36.h" -#elif PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 5 -#include "clinic/_cbitstruct.c.35.h" #else #error "Unsupported python version" #endif diff --git a/cbitstruct/clinic/_cbitstruct.c.35.h b/cbitstruct/clinic/_cbitstruct.c.35.h deleted file mode 100644 index 0a42ef0..0000000 --- a/cbitstruct/clinic/_cbitstruct.c.35.h +++ /dev/null @@ -1,620 +0,0 @@ -/*[clinic input] -preserve -[clinic start generated code]*/ - -PyDoc_STRVAR(CompiledFormat___init____doc__, -"CompiledFormat(fmt)\n" -"--\n" -"\n" -"Create a compiled bitstruct object.\n" -"\n" -"Return a new CompiledFormat object which writes and reads binary data\n" -"according to the format string."); - -static int -CompiledFormat___init___impl(PyCompiledFormatObject *self, const char *fmt); - -static int -CompiledFormat___init__(PyObject *self, PyObject *args, PyObject *kwargs) -{ - int return_value = -1; - static char *_keywords[] = {"fmt", NULL}; - const char *fmt; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:CompiledFormat", _keywords, - &fmt)) - goto exit; - return_value = CompiledFormat___init___impl((PyCompiledFormatObject *)self, fmt); - -exit: - return return_value; -} - -PyDoc_STRVAR(CompiledFormat_calcsize__doc__, -"calcsize($self, /)\n" -"--\n" -"\n" -"Return size in bits of the bitDescribed by the format string."); - -#define COMPILEDFORMAT_CALCSIZE_METHODDEF \ - {"calcsize", (PyCFunction)CompiledFormat_calcsize, METH_NOARGS, CompiledFormat_calcsize__doc__}, - -static Py_ssize_t -CompiledFormat_calcsize_impl(PyCompiledFormatObject *self); - -static PyObject * -CompiledFormat_calcsize(PyCompiledFormatObject *self, PyObject *Py_UNUSED(ignored)) -{ - PyObject *return_value = NULL; - Py_ssize_t _return_value; - - _return_value = CompiledFormat_calcsize_impl(self); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromSsize_t(_return_value); - -exit: - return return_value; -} - -PyDoc_STRVAR(CompiledFormat_unpack__doc__, -"unpack($self, /, data)\n" -"--\n" -"\n" -"Return a tuple containing unpacked values."); - -#define COMPILEDFORMAT_UNPACK_METHODDEF \ - {"unpack", (PyCFunction)CompiledFormat_unpack, METH_VARARGS|METH_KEYWORDS, CompiledFormat_unpack__doc__}, - -static PyObject * -CompiledFormat_unpack_impl(PyCompiledFormatObject *self, Py_buffer *data); - -static PyObject * -CompiledFormat_unpack(PyCompiledFormatObject *self, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"data", NULL}; - Py_buffer data = {NULL, NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:unpack", _keywords, - &data)) - goto exit; - return_value = CompiledFormat_unpack_impl(self, &data); - -exit: - /* Cleanup for data */ - if (data.obj) - PyBuffer_Release(&data); - - return return_value; -} - -PyDoc_STRVAR(CompiledFormat_unpack_from__doc__, -"unpack_from($self, /, data, offset=0)\n" -"--\n" -"\n" -"Return a tuple containing unpacked values starting at \'offset\' bits."); - -#define COMPILEDFORMAT_UNPACK_FROM_METHODDEF \ - {"unpack_from", (PyCFunction)CompiledFormat_unpack_from, METH_VARARGS|METH_KEYWORDS, CompiledFormat_unpack_from__doc__}, - -static PyObject * -CompiledFormat_unpack_from_impl(PyCompiledFormatObject *self, - Py_buffer *data, Py_ssize_t offset); - -static PyObject * -CompiledFormat_unpack_from(PyCompiledFormatObject *self, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"data", "offset", NULL}; - Py_buffer data = {NULL, NULL}; - Py_ssize_t offset = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|n:unpack_from", _keywords, - &data, &offset)) - goto exit; - return_value = CompiledFormat_unpack_from_impl(self, &data, offset); - -exit: - /* Cleanup for data */ - if (data.obj) - PyBuffer_Release(&data); - - return return_value; -} - -PyDoc_STRVAR(CompiledFormatDict___init____doc__, -"CompiledFormatDict(fmt, names)\n" -"--\n" -"\n" -"Create a compiled bitstruct object.\n" -"\n" -"Return a new CompiledFormatDict object which writes and reads binary data\n" -"according to the format string. The names list \'name\' will be used\n" -"as keys in data dictionaries."); - -static int -CompiledFormatDict___init___impl(PyCompiledFormatDictObject *self, - const char *fmt, PyObject *names); - -static int -CompiledFormatDict___init__(PyObject *self, PyObject *args, PyObject *kwargs) -{ - int return_value = -1; - static char *_keywords[] = {"fmt", "names", NULL}; - const char *fmt; - PyObject *names; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO:CompiledFormatDict", _keywords, - &fmt, &names)) - goto exit; - return_value = CompiledFormatDict___init___impl((PyCompiledFormatDictObject *)self, fmt, names); - -exit: - return return_value; -} - -PyDoc_STRVAR(CompiledFormatDict_pack__doc__, -"pack($self, /, data)\n" -"--\n" -"\n" -"Pack values from a dict into a bytes object\n" -"\n" -"Return a tuple containing unpacked values.\n" -"\'data\' is a dictionary containing values whic keys are the \'names\'\n" -"used when constructing this object."); - -#define COMPILEDFORMATDICT_PACK_METHODDEF \ - {"pack", (PyCFunction)CompiledFormatDict_pack, METH_VARARGS|METH_KEYWORDS, CompiledFormatDict_pack__doc__}, - -static PyObject * -CompiledFormatDict_pack_impl(PyCompiledFormatDictObject *self, - PyObject *data); - -static PyObject * -CompiledFormatDict_pack(PyCompiledFormatDictObject *self, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"data", NULL}; - PyObject *data; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:pack", _keywords, - &data)) - goto exit; - return_value = CompiledFormatDict_pack_impl(self, data); - -exit: - return return_value; -} - -PyDoc_STRVAR(CompiledFormatDict_pack_into__doc__, -"pack_into($self, /, buf, offset, data, *, fill_padding=True)\n" -"--\n" -"\n" -"Pack data into a bytes object, starting at bit offset given by the offset argument.\n" -"\n" -"With fill_padding=False, passing bits in \'buf\' will not be modified."); - -#define COMPILEDFORMATDICT_PACK_INTO_METHODDEF \ - {"pack_into", (PyCFunction)CompiledFormatDict_pack_into, METH_VARARGS|METH_KEYWORDS, CompiledFormatDict_pack_into__doc__}, - -static PyObject * -CompiledFormatDict_pack_into_impl(PyCompiledFormatDictObject *self, - Py_buffer *buf, Py_ssize_t offset, - PyObject *data, int fill_padding); - -static PyObject * -CompiledFormatDict_pack_into(PyCompiledFormatDictObject *self, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"buf", "offset", "data", "fill_padding", NULL}; - Py_buffer buf = {NULL, NULL}; - Py_ssize_t offset; - PyObject *data; - int fill_padding = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*nO|$p:pack_into", _keywords, - &buf, &offset, &data, &fill_padding)) - goto exit; - return_value = CompiledFormatDict_pack_into_impl(self, &buf, offset, data, fill_padding); - -exit: - /* Cleanup for buf */ - if (buf.obj) - PyBuffer_Release(&buf); - - return return_value; -} - -PyDoc_STRVAR(CompiledFormatDict_unpack__doc__, -"unpack($self, /, data)\n" -"--\n" -"\n" -"Unpack data into a dict which keys are the \'names\' used when constructing this object.\n" -"\n" -"Return a dict containing unpacked values."); - -#define COMPILEDFORMATDICT_UNPACK_METHODDEF \ - {"unpack", (PyCFunction)CompiledFormatDict_unpack, METH_VARARGS|METH_KEYWORDS, CompiledFormatDict_unpack__doc__}, - -static PyObject * -CompiledFormatDict_unpack_impl(PyCompiledFormatDictObject *self, - Py_buffer *data); - -static PyObject * -CompiledFormatDict_unpack(PyCompiledFormatDictObject *self, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"data", NULL}; - Py_buffer data = {NULL, NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*:unpack", _keywords, - &data)) - goto exit; - return_value = CompiledFormatDict_unpack_impl(self, &data); - -exit: - /* Cleanup for data */ - if (data.obj) - PyBuffer_Release(&data); - - return return_value; -} - -PyDoc_STRVAR(CompiledFormatDict_unpack_from__doc__, -"unpack_from($self, /, data, offset=0)\n" -"--\n" -"\n" -"Unpack data into a dict starting at \'offset\' bits.\n" -"\n" -"Return a dict containing unpacked values."); - -#define COMPILEDFORMATDICT_UNPACK_FROM_METHODDEF \ - {"unpack_from", (PyCFunction)CompiledFormatDict_unpack_from, METH_VARARGS|METH_KEYWORDS, CompiledFormatDict_unpack_from__doc__}, - -static PyObject * -CompiledFormatDict_unpack_from_impl(PyCompiledFormatDictObject *self, - Py_buffer *data, Py_ssize_t offset); - -static PyObject * -CompiledFormatDict_unpack_from(PyCompiledFormatDictObject *self, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"data", "offset", NULL}; - Py_buffer data = {NULL, NULL}; - Py_ssize_t offset = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|n:unpack_from", _keywords, - &data, &offset)) - goto exit; - return_value = CompiledFormatDict_unpack_from_impl(self, &data, offset); - -exit: - /* Cleanup for data */ - if (data.obj) - PyBuffer_Release(&data); - - return return_value; -} - -PyDoc_STRVAR(pack_dict__doc__, -"pack_dict($module, /, fmt, names, data)\n" -"--\n" -"\n" -"Pack the dict data into a bytes object according to format.\n" -"\n" -"The order of value is determines by the list \'names\'."); - -#define PACK_DICT_METHODDEF \ - {"pack_dict", (PyCFunction)pack_dict, METH_VARARGS|METH_KEYWORDS, pack_dict__doc__}, - -static PyObject * -pack_dict_impl(PyObject *module, const char *fmt, PyObject *names, - PyObject *data); - -static PyObject * -pack_dict(PyObject *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fmt", "names", "data", NULL}; - const char *fmt; - PyObject *names; - PyObject *data; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sOO:pack_dict", _keywords, - &fmt, &names, &data)) - goto exit; - return_value = pack_dict_impl(module, fmt, names, data); - -exit: - return return_value; -} - -PyDoc_STRVAR(pack_into_dict__doc__, -"pack_into_dict($module, /, fmt, names, buf, offset, data, *,\n" -" fill_padding=True)\n" -"--\n" -"\n" -"Pack data into a bytes object, starting at bit offset given by the offset argument.\n" -"\n" -"With fill_padding=False, passing bits in \'buf\' will not be modified."); - -#define PACK_INTO_DICT_METHODDEF \ - {"pack_into_dict", (PyCFunction)pack_into_dict, METH_VARARGS|METH_KEYWORDS, pack_into_dict__doc__}, - -static PyObject * -pack_into_dict_impl(PyObject *module, const char *fmt, PyObject *names, - Py_buffer *buf, Py_ssize_t offset, PyObject *data, - int fill_padding); - -static PyObject * -pack_into_dict(PyObject *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fmt", "names", "buf", "offset", "data", "fill_padding", NULL}; - const char *fmt; - PyObject *names; - Py_buffer buf = {NULL, NULL}; - Py_ssize_t offset; - PyObject *data; - int fill_padding = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sOy*nO|$p:pack_into_dict", _keywords, - &fmt, &names, &buf, &offset, &data, &fill_padding)) - goto exit; - return_value = pack_into_dict_impl(module, fmt, names, &buf, offset, data, fill_padding); - -exit: - /* Cleanup for buf */ - if (buf.obj) - PyBuffer_Release(&buf); - - return return_value; -} - -PyDoc_STRVAR(unpack__doc__, -"unpack($module, /, fmt, data)\n" -"--\n" -"\n" -"Unpack data according to the format \'fmt\'. Returns a tuple."); - -#define UNPACK_METHODDEF \ - {"unpack", (PyCFunction)unpack, METH_VARARGS|METH_KEYWORDS, unpack__doc__}, - -static PyObject * -unpack_impl(PyObject *module, const char *fmt, Py_buffer *data); - -static PyObject * -unpack(PyObject *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fmt", "data", NULL}; - const char *fmt; - Py_buffer data = {NULL, NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sy*:unpack", _keywords, - &fmt, &data)) - goto exit; - return_value = unpack_impl(module, fmt, &data); - -exit: - /* Cleanup for data */ - if (data.obj) - PyBuffer_Release(&data); - - return return_value; -} - -PyDoc_STRVAR(unpack_from__doc__, -"unpack_from($module, /, fmt, data, offset=0)\n" -"--\n" -"\n" -"Unpack data according to the format \'fmt\', starting at bit offset \'offset.\n" -"\n" -"Returns a tuple."); - -#define UNPACK_FROM_METHODDEF \ - {"unpack_from", (PyCFunction)unpack_from, METH_VARARGS|METH_KEYWORDS, unpack_from__doc__}, - -static PyObject * -unpack_from_impl(PyObject *module, const char *fmt, Py_buffer *data, - Py_ssize_t offset); - -static PyObject * -unpack_from(PyObject *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fmt", "data", "offset", NULL}; - const char *fmt; - Py_buffer data = {NULL, NULL}; - Py_ssize_t offset = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sy*|n:unpack_from", _keywords, - &fmt, &data, &offset)) - goto exit; - return_value = unpack_from_impl(module, fmt, &data, offset); - -exit: - /* Cleanup for data */ - if (data.obj) - PyBuffer_Release(&data); - - return return_value; -} - -PyDoc_STRVAR(unpack_dict__doc__, -"unpack_dict($module, /, fmt, names, data)\n" -"--\n" -"\n" -"Unpack data according to \'fmt\'.\n" -"\n" -"Returns a dict which keys are \'names\'."); - -#define UNPACK_DICT_METHODDEF \ - {"unpack_dict", (PyCFunction)unpack_dict, METH_VARARGS|METH_KEYWORDS, unpack_dict__doc__}, - -static PyObject * -unpack_dict_impl(PyObject *module, const char *fmt, PyObject *names, - Py_buffer *data); - -static PyObject * -unpack_dict(PyObject *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fmt", "names", "data", NULL}; - const char *fmt; - PyObject *names; - Py_buffer data = {NULL, NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sOy*:unpack_dict", _keywords, - &fmt, &names, &data)) - goto exit; - return_value = unpack_dict_impl(module, fmt, names, &data); - -exit: - /* Cleanup for data */ - if (data.obj) - PyBuffer_Release(&data); - - return return_value; -} - -PyDoc_STRVAR(unpack_from_dict__doc__, -"unpack_from_dict($module, /, fmt, names, data, offset=0)\n" -"--\n" -"\n" -"Unpack data according to \'fmt\' starting at bit offset \'offset\'.\n" -"\n" -"Returns a dict which keys are \'names\'."); - -#define UNPACK_FROM_DICT_METHODDEF \ - {"unpack_from_dict", (PyCFunction)unpack_from_dict, METH_VARARGS|METH_KEYWORDS, unpack_from_dict__doc__}, - -static PyObject * -unpack_from_dict_impl(PyObject *module, const char *fmt, PyObject *names, - Py_buffer *data, Py_ssize_t offset); - -static PyObject * -unpack_from_dict(PyObject *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fmt", "names", "data", "offset", NULL}; - const char *fmt; - PyObject *names; - Py_buffer data = {NULL, NULL}; - Py_ssize_t offset = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sOy*|n:unpack_from_dict", _keywords, - &fmt, &names, &data, &offset)) - goto exit; - return_value = unpack_from_dict_impl(module, fmt, names, &data, offset); - -exit: - /* Cleanup for data */ - if (data.obj) - PyBuffer_Release(&data); - - return return_value; -} - -PyDoc_STRVAR(compile__doc__, -"compile($module, /, fmt, names=None)\n" -"--\n" -"\n" -"Returns a compiled object for the format \'fmt\'."); - -#define COMPILE_METHODDEF \ - {"compile", (PyCFunction)compile, METH_VARARGS|METH_KEYWORDS, compile__doc__}, - -static PyObject * -compile_impl(PyObject *module, const char *fmt, PyObject *names); - -static PyObject * -compile(PyObject *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fmt", "names", NULL}; - const char *fmt; - PyObject *names = Py_None; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|O:compile", _keywords, - &fmt, &names)) - goto exit; - return_value = compile_impl(module, fmt, names); - -exit: - return return_value; -} - -PyDoc_STRVAR(calcsize__doc__, -"calcsize($module, /, fmt)\n" -"--\n" -"\n" -"Return size in bits of the bit described by the format string."); - -#define CALCSIZE_METHODDEF \ - {"calcsize", (PyCFunction)calcsize, METH_VARARGS|METH_KEYWORDS, calcsize__doc__}, - -static Py_ssize_t -calcsize_impl(PyObject *module, const char *fmt); - -static PyObject * -calcsize(PyObject *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fmt", NULL}; - const char *fmt; - Py_ssize_t _return_value; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:calcsize", _keywords, - &fmt)) - goto exit; - _return_value = calcsize_impl(module, fmt); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromSsize_t(_return_value); - -exit: - return return_value; -} - -PyDoc_STRVAR(byteswap__doc__, -"byteswap($module, /, fmt, data, offset=0)\n" -"--\n" -"\n" -"Swap bytes in `data` according to `fmt`, starting at byte `offset` and return the result.\n" -"\n" -"`fmt` must be an iterable, iterating over\n" -"number of bytes to swap. For example, the format string ``\'24\'``\n" -"applied to the bytes ``b\'\\x00\\x11\\x22\\x33\\x44\\x55\'`` will\n" -"produce the result ``b\'\\x11\\x00\\x55\\x44\\x33\\x22\'``."); - -#define BYTESWAP_METHODDEF \ - {"byteswap", (PyCFunction)byteswap, METH_VARARGS|METH_KEYWORDS, byteswap__doc__}, - -static PyObject * -byteswap_impl(PyObject *module, PyObject *fmt, Py_buffer *data, - Py_ssize_t offset); - -static PyObject * -byteswap(PyObject *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fmt", "data", "offset", NULL}; - PyObject *fmt; - Py_buffer data = {NULL, NULL}; - Py_ssize_t offset = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oy*|n:byteswap", _keywords, - &fmt, &data, &offset)) - goto exit; - return_value = byteswap_impl(module, fmt, &data, offset); - -exit: - /* Cleanup for data */ - if (data.obj) - PyBuffer_Release(&data); - - return return_value; -} -/*[clinic end generated code: output=c102aaba2bc6b295 input=a9049054013a1b77]*/ diff --git a/cbitstruct/tests/original/test_bitstruct.py b/cbitstruct/tests/original/test_bitstruct.py index f79aac0..2c5a155 100644 --- a/cbitstruct/tests/original/test_bitstruct.py +++ b/cbitstruct/tests/original/test_bitstruct.py @@ -1,4 +1,3 @@ -from __future__ import print_function import unittest import timeit import sys diff --git a/cbitstruct/tests/test_bitstruct.py b/cbitstruct/tests/test_bitstruct.py index 8dc6358..46c4c4f 100644 --- a/cbitstruct/tests/test_bitstruct.py +++ b/cbitstruct/tests/test_bitstruct.py @@ -1,4 +1,3 @@ -from __future__ import print_function import unittest import timeit import sys diff --git a/setup.py b/setup.py index da104af..438b481 100644 --- a/setup.py +++ b/setup.py @@ -12,16 +12,14 @@ undef_macros = [] -if sys.platform == "win32": - extra_compile_args += [] -else: - extra_compile_args += ["-std=c11", "-Wall", "-Werror", "-O3"] +if sys.platform != "win32": + extra_compile_args.extend(("-std=c11", "-Wall", "-Werror", "-O3")) if os.environ.get("COVERAGE"): - extra_compile_args += ["-g", "-O0", "-fprofile-arcs", "-ftest-coverage"] - extra_link_args += ["-fprofile-arcs"] - undef_macros += ["NDEBUG"] + extra_compile_args.extend(("-g", "-O0", "-fprofile-arcs", "-ftest-coverage")) + extra_link_args.append("-fprofile-arcs") + undef_macros.append("NDEBUG") with open("README.md", "r") as fh: @@ -38,6 +36,7 @@ description="Faster C implementation of bitstruct", long_description=long_description, long_description_content_type="text/markdown", + python_requires=">=3.6", classifiers=[ "Programming Language :: Python :: 3", "Programming Language :: C", From 547159ca234aea79f962a9201c26ebe2bc629100 Mon Sep 17 00:00:00 2001 From: Mark Grassi <17365607+markgras@users.noreply.github.com> Date: Thu, 7 Dec 2023 23:11:57 -0500 Subject: [PATCH 3/4] Update CI to use cibuildwheel --- .ci/build-linux-sdist.sh | 13 ------- .ci/coverage.sh | 8 ++-- .ci/performance.sh | 6 --- .github/workflows/build_and_publish.yml | 50 +++++++++++++++++++++++++ .github/workflows/manylinux.yml | 39 ------------------- dev-requirements.txt | 4 -- pyproject.toml | 12 ++++++ setup.py | 1 + 8 files changed, 67 insertions(+), 66 deletions(-) delete mode 100644 .ci/build-linux-sdist.sh delete mode 100644 .ci/performance.sh create mode 100644 .github/workflows/build_and_publish.yml delete mode 100644 .github/workflows/manylinux.yml delete mode 100644 dev-requirements.txt diff --git a/.ci/build-linux-sdist.sh b/.ci/build-linux-sdist.sh deleted file mode 100644 index 28ddf68..0000000 --- a/.ci/build-linux-sdist.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -e -x - -python -m pip install -U -r dev-requirements.txt -python setup.py sdist - -# test wheel, move out of here otherwise pip thinks -# cbitstruct is already installed -mkdir -p testdir -cd testdir -python -m pip install cbitstruct --no-index -f ../dist/ -python -m nose2 cbitstruct -cd .. diff --git a/.ci/coverage.sh b/.ci/coverage.sh index 1b69641..5e39a37 100644 --- a/.ci/coverage.sh +++ b/.ci/coverage.sh @@ -3,11 +3,11 @@ set -e -x export COVERAGE=1 -python -m pip install -U -r dev-requirements.txt +python -m pip install .[test] python -m pip install -U cpp-coveralls -python setup.py install -# move to a different directory to avoid picking-up the local files +# Move to a different directory to avoid picking-up the local files. +# Alternatively, in Python 3.11+ use the interpreter's -P option to ignore local files. mkdir ci-coverage && cd ci-coverage -python -m nose2 cbitstruct +python -m unittest discover cbitstruct coveralls --exclude clinic --gcov-options '\-lp' diff --git a/.ci/performance.sh b/.ci/performance.sh deleted file mode 100644 index 5916611..0000000 --- a/.ci/performance.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -e -x - -python -m pip install -U -r dev-requirements.txt -python setup.py install -python cbitstruct/tests/test_perf.py diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml new file mode 100644 index 0000000..3922260 --- /dev/null +++ b/.github/workflows/build_and_publish.yml @@ -0,0 +1,50 @@ +name: Python package build and publish + +on: push + +jobs: + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Build sdist + run: pipx run build --sdist + + - uses: actions/upload-artifact@v3 + with: + path: dist/*.tar.gz + + build_wheels: + name: Build and test manylinux wheels + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Build wheels + uses: pypa/cibuildwheel@v2.16.2 + + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + + publish_pypi: + name: Publish sdist and wheels to PyPI + needs: [build_sdist, build_wheels] + runs-on: ubuntu-latest + environment: pypi + permissions: + id-token: write + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + steps: + - uses: actions/download-artifact@v3 + with: + name: artifact + path: dist + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: ${{ secrets.PYPI_USERNAME }} + password: ${{ secrets.PYPI_PASSWORD }} diff --git a/.github/workflows/manylinux.yml b/.github/workflows/manylinux.yml deleted file mode 100644 index 87389c0..0000000 --- a/.github/workflows/manylinux.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Python package build and publish - -on: push - -jobs: - ci: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v1 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install twine - - - name: Performance - run: bash .ci/performance.sh - - - name: Build sources - run: bash .ci/build-linux-sdist.sh - - - name: Build manylinux Python wheels - uses: RalfG/python-wheels-manylinux-build@v0.6.0-manylinux2014_x86_64 - with: - python-versions: "cp37-cp37m cp38-cp38 cp310-cp310 cp311-cp311" - build-requirements: "cython" - - - name: Publish wheels to PyPI - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - twine upload dist/*-manylinux*.whl dist/*.tar.gz diff --git a/dev-requirements.txt b/dev-requirements.txt deleted file mode 100644 index 285e8df..0000000 --- a/dev-requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -nose2 -bitstruct -wheel -setuptools diff --git a/pyproject.toml b/pyproject.toml index fed528d..12d24f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,15 @@ [build-system] requires = ["setuptools"] build-backend = "setuptools.build_meta" + +[tool.cibuildwheel] +build = [ + "cp36-manylinux_x86_64", + "cp37-manylinux_x86_64", + "cp38-manylinux_x86_64", + "cp39-manylinux_x86_64", + "cp310-manylinux_x86_64", + "cp311-manylinux_x86_64", +] +test-extras = "test" +test-command = "python -m unittest discover cbitstruct" diff --git a/setup.py b/setup.py index 438b481..aeebb02 100644 --- a/setup.py +++ b/setup.py @@ -54,6 +54,7 @@ "bit pack", "C", ], + extras_require={"test": ["bitstruct"]}, ext_modules=[ Extension( "cbitstruct._cbitstruct", From e58ba551377d46734aa0a916fd1fb1435ad0d23c Mon Sep 17 00:00:00 2001 From: Mark Grassi <17365607+markgras@users.noreply.github.com> Date: Thu, 7 Dec 2023 23:12:16 -0500 Subject: [PATCH 4/4] Add Python 3.12 support --- cbitstruct/clinic/_cbitstruct.c.37.h | 34 ++++++++++++++-------------- pyproject.toml | 1 + 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/cbitstruct/clinic/_cbitstruct.c.37.h b/cbitstruct/clinic/_cbitstruct.c.37.h index d52f94d..4a94113 100644 --- a/cbitstruct/clinic/_cbitstruct.c.37.h +++ b/cbitstruct/clinic/_cbitstruct.c.37.h @@ -19,7 +19,7 @@ CompiledFormat___init__(PyObject *self, PyObject *args, PyObject *kwargs) { int return_value = -1; static const char * const _keywords[] = {"fmt", NULL}; - static _PyArg_Parser _parser = {"s:CompiledFormat", _keywords, 0}; + static _PyArg_Parser _parser = {.format="s:CompiledFormat", .keywords=_keywords, .fname=0}; const char *fmt; if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, @@ -77,7 +77,7 @@ CompiledFormat_unpack(PyCompiledFormatObject *self, PyObject *const *args, Py_ss { PyObject *return_value = NULL; static const char * const _keywords[] = {"data", NULL}; - static _PyArg_Parser _parser = {"y*:unpack", _keywords, 0}; + static _PyArg_Parser _parser = {.format="y*:unpack", .keywords=_keywords, .fname=0}; Py_buffer data = {NULL, NULL}; if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, @@ -113,7 +113,7 @@ CompiledFormat_unpack_from(PyCompiledFormatObject *self, PyObject *const *args, { PyObject *return_value = NULL; static const char * const _keywords[] = {"data", "offset", NULL}; - static _PyArg_Parser _parser = {"y*|n:unpack_from", _keywords, 0}; + static _PyArg_Parser _parser = {.format="y*|n:unpack_from", .keywords=_keywords, .fname=0}; Py_buffer data = {NULL, NULL}; Py_ssize_t offset = 0; @@ -151,7 +151,7 @@ CompiledFormatDict___init__(PyObject *self, PyObject *args, PyObject *kwargs) { int return_value = -1; static const char * const _keywords[] = {"fmt", "names", NULL}; - static _PyArg_Parser _parser = {"sO:CompiledFormatDict", _keywords, 0}; + static _PyArg_Parser _parser = {.format="sO:CompiledFormatDict", .keywords=_keywords, .fname=0}; const char *fmt; PyObject *names; @@ -187,7 +187,7 @@ CompiledFormatDict_pack(PyCompiledFormatDictObject *self, PyObject *const *args, { PyObject *return_value = NULL; static const char * const _keywords[] = {"data", NULL}; - static _PyArg_Parser _parser = {"O:pack", _keywords, 0}; + static _PyArg_Parser _parser = {.format="O:pack", .keywords=_keywords, .fname=0}; PyObject *data; if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, @@ -221,7 +221,7 @@ CompiledFormatDict_pack_into(PyCompiledFormatDictObject *self, PyObject *const * { PyObject *return_value = NULL; static const char * const _keywords[] = {"buf", "offset", "data", "fill_padding", NULL}; - static _PyArg_Parser _parser = {"y*nO|$p:pack_into", _keywords, 0}; + static _PyArg_Parser _parser = {.format="y*nO|$p:pack_into", .keywords=_keywords, .fname=0}; Py_buffer buf = {NULL, NULL}; Py_ssize_t offset; PyObject *data; @@ -262,7 +262,7 @@ CompiledFormatDict_unpack(PyCompiledFormatDictObject *self, PyObject *const *arg { PyObject *return_value = NULL; static const char * const _keywords[] = {"data", NULL}; - static _PyArg_Parser _parser = {"y*:unpack", _keywords, 0}; + static _PyArg_Parser _parser = {.format="y*:unpack", .keywords=_keywords, .fname=0}; Py_buffer data = {NULL, NULL}; if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, @@ -300,7 +300,7 @@ CompiledFormatDict_unpack_from(PyCompiledFormatDictObject *self, PyObject *const { PyObject *return_value = NULL; static const char * const _keywords[] = {"data", "offset", NULL}; - static _PyArg_Parser _parser = {"y*|n:unpack_from", _keywords, 0}; + static _PyArg_Parser _parser = {.format="y*|n:unpack_from", .keywords=_keywords, .fname=0}; Py_buffer data = {NULL, NULL}; Py_ssize_t offset = 0; @@ -339,7 +339,7 @@ pack_dict(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k { PyObject *return_value = NULL; static const char * const _keywords[] = {"fmt", "names", "data", NULL}; - static _PyArg_Parser _parser = {"sOO:pack_dict", _keywords, 0}; + static _PyArg_Parser _parser = {.format="sOO:pack_dict", .keywords=_keywords, .fname=0}; const char *fmt; PyObject *names; PyObject *data; @@ -376,7 +376,7 @@ pack_into_dict(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje { PyObject *return_value = NULL; static const char * const _keywords[] = {"fmt", "names", "buf", "offset", "data", "fill_padding", NULL}; - static _PyArg_Parser _parser = {"sOy*nO|$p:pack_into_dict", _keywords, 0}; + static _PyArg_Parser _parser = {.format="sOy*nO|$p:pack_into_dict", .keywords=_keywords, .fname=0}; const char *fmt; PyObject *names; Py_buffer buf = {NULL, NULL}; @@ -416,7 +416,7 @@ unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwna { PyObject *return_value = NULL; static const char * const _keywords[] = {"fmt", "data", NULL}; - static _PyArg_Parser _parser = {"sy*:unpack", _keywords, 0}; + static _PyArg_Parser _parser = {.format="sy*:unpack", .keywords=_keywords, .fname=0}; const char *fmt; Py_buffer data = {NULL, NULL}; @@ -455,7 +455,7 @@ unpack_from(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject { PyObject *return_value = NULL; static const char * const _keywords[] = {"fmt", "data", "offset", NULL}; - static _PyArg_Parser _parser = {"sy*|n:unpack_from", _keywords, 0}; + static _PyArg_Parser _parser = {.format="sy*|n:unpack_from", .keywords=_keywords, .fname=0}; const char *fmt; Py_buffer data = {NULL, NULL}; Py_ssize_t offset = 0; @@ -495,7 +495,7 @@ unpack_dict(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject { PyObject *return_value = NULL; static const char * const _keywords[] = {"fmt", "names", "data", NULL}; - static _PyArg_Parser _parser = {"sOy*:unpack_dict", _keywords, 0}; + static _PyArg_Parser _parser = {.format="sOy*:unpack_dict", .keywords=_keywords, .fname=0}; const char *fmt; PyObject *names; Py_buffer data = {NULL, NULL}; @@ -535,7 +535,7 @@ unpack_from_dict(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb { PyObject *return_value = NULL; static const char * const _keywords[] = {"fmt", "names", "data", "offset", NULL}; - static _PyArg_Parser _parser = {"sOy*|n:unpack_from_dict", _keywords, 0}; + static _PyArg_Parser _parser = {.format="sOy*|n:unpack_from_dict", .keywords=_keywords, .fname=0}; const char *fmt; PyObject *names; Py_buffer data = {NULL, NULL}; @@ -573,7 +573,7 @@ compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwn { PyObject *return_value = NULL; static const char * const _keywords[] = {"fmt", "names", NULL}; - static _PyArg_Parser _parser = {"s|O:compile", _keywords, 0}; + static _PyArg_Parser _parser = {.format="s|O:compile", .keywords=_keywords, .fname=0}; const char *fmt; PyObject *names = Py_None; @@ -604,7 +604,7 @@ calcsize(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw { PyObject *return_value = NULL; static const char * const _keywords[] = {"fmt", NULL}; - static _PyArg_Parser _parser = {"s:calcsize", _keywords, 0}; + static _PyArg_Parser _parser = {.format="s:calcsize", .keywords=_keywords, .fname=0}; const char *fmt; Py_ssize_t _return_value; @@ -645,7 +645,7 @@ byteswap(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw { PyObject *return_value = NULL; static const char * const _keywords[] = {"fmt", "data", "offset", NULL}; - static _PyArg_Parser _parser = {"Oy*|n:byteswap", _keywords, 0}; + static _PyArg_Parser _parser = {.format="Oy*|n:byteswap", .keywords=_keywords, .fname=0}; PyObject *fmt; Py_buffer data = {NULL, NULL}; Py_ssize_t offset = 0; diff --git a/pyproject.toml b/pyproject.toml index 12d24f2..8cf85b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ build = [ "cp39-manylinux_x86_64", "cp310-manylinux_x86_64", "cp311-manylinux_x86_64", + "cp312-manylinux_x86_64", ] test-extras = "test" test-command = "python -m unittest discover cbitstruct"