From: Bartosz Golaszewski Date: Wed, 20 Nov 2024 13:18:19 +0000 (+0100) Subject: bindings: python: tests: rename procname to system X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=aa5a1e92b1487f8ebaa71e78537226a36dd70632;p=qemu-gpiodev%2Flibgpiod.git bindings: python: tests: rename procname to system We'll be extending the functionality of that C extension with other OS-level helpers so change its name to 'system'. Reviewed-by: Vincent Fazio Link: https://lore.kernel.org/r/20241120-drop-distutils-v1-2-7498e8b3babe@linaro.org Signed-off-by: Bartosz Golaszewski --- diff --git a/bindings/python/MANIFEST.in b/bindings/python/MANIFEST.in index f3a1ee8..dc7daee 100644 --- a/bindings/python/MANIFEST.in +++ b/bindings/python/MANIFEST.in @@ -13,7 +13,7 @@ recursive-include gpiod/ext *.c recursive-include gpiod/ext *.h recursive-include tests/gpiosim *.c -recursive-include tests/procname *.c +recursive-include tests/system *.c recursive-include lib *.c recursive-include lib *.h diff --git a/bindings/python/build_tests.py b/bindings/python/build_tests.py index 1760257..84cedfc 100644 --- a/bindings/python/build_tests.py +++ b/bindings/python/build_tests.py @@ -11,7 +11,7 @@ polluted with artefacts in build/ Builds: tests/gpiosim/_ext..so - tests/procname/_ext..so + tests/system/_ext..so """ @@ -61,9 +61,9 @@ gpiosim_ext = Extension( ], ) -procname_ext = Extension( - "tests.procname._ext", - sources=["tests/procname/ext.c"], +system_ext = Extension( + "tests.system._ext", + sources=["tests/system/ext.c"], define_macros=[("_GNU_SOURCE", "1")], extra_compile_args=["-Wall", "-Wextra"], ) @@ -71,7 +71,7 @@ procname_ext = Extension( dist = Distribution( { "name": "gpiod", - "ext_modules": [gpiosim_ext, procname_ext, gpiod_ext], + "ext_modules": [gpiosim_ext, system_ext, gpiod_ext], "version": __version__, "platforms": ["linux"], } diff --git a/bindings/python/tests/Makefile.am b/bindings/python/tests/Makefile.am index 3118d5f..d6e3ea3 100644 --- a/bindings/python/tests/Makefile.am +++ b/bindings/python/tests/Makefile.am @@ -1,7 +1,7 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -SUBDIRS = gpiosim procname +SUBDIRS = gpiosim system EXTRA_DIST = \ helpers.py \ diff --git a/bindings/python/tests/__main__.py b/bindings/python/tests/__main__.py index 8b4260d..318e0df 100644 --- a/bindings/python/tests/__main__.py +++ b/bindings/python/tests/__main__.py @@ -4,7 +4,7 @@ import unittest -from . import procname +from .system import set_process_name from .tests_chip import * from .tests_chip_info import * from .tests_edge_event import * @@ -15,6 +15,6 @@ from .tests_line_request import * from .tests_line_settings import * from .tests_module import * -procname.set_process_name("python-gpiod") +set_process_name("python-gpiod") unittest.main() diff --git a/bindings/python/tests/procname/Makefile.am b/bindings/python/tests/procname/Makefile.am deleted file mode 100644 index dbc8e64..0000000 --- a/bindings/python/tests/procname/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski - -EXTRA_DIST = \ - _ext.pyi \ - ext.c \ - __init__.py diff --git a/bindings/python/tests/procname/__init__.py b/bindings/python/tests/procname/__init__.py deleted file mode 100644 index 436ff40..0000000 --- a/bindings/python/tests/procname/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski - -from ._ext import set_process_name - -__all__ = ["set_process_name"] diff --git a/bindings/python/tests/procname/_ext.pyi b/bindings/python/tests/procname/_ext.pyi deleted file mode 100644 index df8bb15..0000000 --- a/bindings/python/tests/procname/_ext.pyi +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -# SPDX-FileCopyrightText: 2024 Vincent Fazio - -def set_process_name(name: str) -> None: ... diff --git a/bindings/python/tests/procname/ext.c b/bindings/python/tests/procname/ext.c deleted file mode 100644 index bf7d2fe..0000000 --- a/bindings/python/tests/procname/ext.c +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: LGPL-2.1-or-later -// SPDX-FileCopyrightText: 2022 Bartosz Golaszewski - -#include -#include - -static PyObject * -module_set_process_name(PyObject *Py_UNUSED(self), PyObject *args) -{ - const char *name; - int ret; - - ret = PyArg_ParseTuple(args, "s", &name); - if (!ret) - return NULL; - - ret = prctl(PR_SET_NAME, name); - if (ret) - return PyErr_SetFromErrno(PyExc_OSError); - - Py_RETURN_NONE; -} - -static PyMethodDef module_methods[] = { - { - .ml_name = "set_process_name", - .ml_meth = (PyCFunction)module_set_process_name, - .ml_flags = METH_VARARGS, - }, - { } -}; - -static PyModuleDef module_def = { - PyModuleDef_HEAD_INIT, - .m_name = "procname._ext", - .m_methods = module_methods, -}; - -PyMODINIT_FUNC PyInit__ext(void) -{ - return PyModule_Create(&module_def); -} diff --git a/bindings/python/tests/system/Makefile.am b/bindings/python/tests/system/Makefile.am new file mode 100644 index 0000000..dbc8e64 --- /dev/null +++ b/bindings/python/tests/system/Makefile.am @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski + +EXTRA_DIST = \ + _ext.pyi \ + ext.c \ + __init__.py diff --git a/bindings/python/tests/system/__init__.py b/bindings/python/tests/system/__init__.py new file mode 100644 index 0000000..436ff40 --- /dev/null +++ b/bindings/python/tests/system/__init__.py @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski + +from ._ext import set_process_name + +__all__ = ["set_process_name"] diff --git a/bindings/python/tests/system/_ext.pyi b/bindings/python/tests/system/_ext.pyi new file mode 100644 index 0000000..df8bb15 --- /dev/null +++ b/bindings/python/tests/system/_ext.pyi @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# SPDX-FileCopyrightText: 2024 Vincent Fazio + +def set_process_name(name: str) -> None: ... diff --git a/bindings/python/tests/system/ext.c b/bindings/python/tests/system/ext.c new file mode 100644 index 0000000..e7c1cc4 --- /dev/null +++ b/bindings/python/tests/system/ext.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +// SPDX-FileCopyrightText: 2022 Bartosz Golaszewski + +#include +#include + +static PyObject * +module_set_process_name(PyObject *Py_UNUSED(self), PyObject *args) +{ + const char *name; + int ret; + + ret = PyArg_ParseTuple(args, "s", &name); + if (!ret) + return NULL; + + ret = prctl(PR_SET_NAME, name); + if (ret) + return PyErr_SetFromErrno(PyExc_OSError); + + Py_RETURN_NONE; +} + +static PyMethodDef module_methods[] = { + { + .ml_name = "set_process_name", + .ml_meth = (PyCFunction)module_set_process_name, + .ml_flags = METH_VARARGS, + }, + { } +}; + +static PyModuleDef module_def = { + PyModuleDef_HEAD_INIT, + .m_name = "system._ext", + .m_methods = module_methods, +}; + +PyMODINIT_FUNC PyInit__ext(void) +{ + return PyModule_Create(&module_def); +} diff --git a/configure.ac b/configure.ac index 97fc83f..78a6670 100644 --- a/configure.ac +++ b/configure.ac @@ -371,7 +371,7 @@ AC_CONFIG_FILES([Makefile bindings/python/examples/Makefile bindings/python/tests/Makefile bindings/python/tests/gpiosim/Makefile - bindings/python/tests/procname/Makefile + bindings/python/tests/system/Makefile bindings/rust/libgpiod-sys/src/Makefile bindings/rust/libgpiod-sys/Makefile bindings/rust/libgpiod/src/Makefile