From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Kent Gibson <warthog618@gmail.com>,
Linus Walleij <linus.walleij@linaro.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Viresh Kumar <viresh.kumar@linaro.org>,
Erik Schilling <erik.schilling@linaro.org>
Cc: linux-gpio@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [libgpiod][PATCH v2 4/5] bindings: python: provide the chip_name property in line_request
Date: Thu, 20 Jul 2023 16:47:46 +0200 [thread overview]
Message-ID: <20230720144747.73276-5-brgl@bgdev.pl> (raw)
In-Reply-To: <20230720144747.73276-1-brgl@bgdev.pl>
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Provide a wrapper around gpiod_line_request_get_chip_name() for Python
bindings and update the tests.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
bindings/python/gpiod/chip.py | 1 +
bindings/python/gpiod/ext/request.c | 11 +++++++++++
bindings/python/gpiod/line_request.py | 12 ++++++++++--
bindings/python/tests/tests_line_request.py | 13 ++++++++-----
4 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py
index da93370..b3d8e61 100644
--- a/bindings/python/gpiod/chip.py
+++ b/bindings/python/gpiod/chip.py
@@ -315,6 +315,7 @@ class Chip:
req_internal = self._chip.request_lines(line_cfg, consumer, event_buffer_size)
request = LineRequest(req_internal)
+ request._chip_name = req_internal.chip_name
request._offsets = req_internal.offsets
request._name_map = name_map
request._offset_map = offset_map
diff --git a/bindings/python/gpiod/ext/request.c b/bindings/python/gpiod/ext/request.c
index a32ff8f..5db69fe 100644
--- a/bindings/python/gpiod/ext/request.c
+++ b/bindings/python/gpiod/ext/request.c
@@ -37,6 +37,13 @@ static void request_finalize(request_object *self)
gpiod_edge_event_buffer_free(self->buffer);
}
+static PyObject *
+request_chip_name(request_object *self, void *Py_UNUSED(ignored))
+{
+ return PyUnicode_FromString(
+ gpiod_line_request_get_chip_name(self->request));
+}
+
static PyObject *
request_num_lines(request_object *self, void *Py_UNUSED(ignored))
{
@@ -92,6 +99,10 @@ static PyObject *request_fd(request_object *self, void *Py_UNUSED(ignored))
}
static PyGetSetDef request_getset[] = {
+ {
+ .name = "chip_name",
+ .get = (getter)request_chip_name,
+ },
{
.name = "num_lines",
.get = (getter)request_num_lines,
diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py
index 096bf18..cde298f 100644
--- a/bindings/python/gpiod/line_request.py
+++ b/bindings/python/gpiod/line_request.py
@@ -212,10 +212,18 @@ class LineRequest:
if not self._req:
return "<LineRequest RELEASED>"
- return "<LineRequest num_lines={} offsets={} fd={}>".format(
- self.num_lines, self.offsets, self.fd
+ return '<LineRequest chip="{}" num_lines={} offsets={} fd={}>'.format(
+ self.chip_name, self.num_lines, self.offsets, self.fd
)
+ @property
+ def chip_name(self) -> str:
+ """
+ Name of the chip this request was made on.
+ """
+ self._check_released()
+ return self._chip_name
+
@property
def num_lines(self) -> int:
"""
diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py
index aa84b9a..f99b93d 100644
--- a/bindings/python/tests/tests_line_request.py
+++ b/bindings/python/tests/tests_line_request.py
@@ -529,11 +529,14 @@ class LineRequestStringRepresentation(TestCase):
del self.sim
def test_str(self):
- with gpiod.request_lines(self.sim.dev_path, config={(2, 6, 4, 1): None}) as req:
- self.assertEqual(
- str(req),
- "<LineRequest num_lines=4 offsets=[2, 6, 4, 1] fd={}>".format(req.fd),
- )
+ with gpiod.Chip(self.sim.dev_path) as chip:
+ with chip.request_lines(config={(2, 6, 4, 1): None}) as req:
+ self.assertEqual(
+ str(req),
+ '<LineRequest chip="{}" num_lines=4 offsets=[2, 6, 4, 1] fd={}>'.format(
+ self.sim.name, req.fd
+ ),
+ )
def test_str_released(self):
req = gpiod.request_lines(self.sim.dev_path, config={(2, 6, 4, 1): None})
--
2.39.2
next prev parent reply other threads:[~2023-07-20 14:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-20 14:47 [libgpiod][PATCH v2 0/5] core: provide information about the parent chip in line requests Bartosz Golaszewski
2023-07-20 14:47 ` [libgpiod][PATCH v2 1/5] core: provide gpiod_line_request_get_chip_name() Bartosz Golaszewski
2023-07-20 14:47 ` [libgpiod][PATCH v2 2/5] tests: add a test-case for gpiod_line_request_get_chip_name() Bartosz Golaszewski
2023-07-20 14:47 ` [libgpiod][PATCH v2 3/5] bindings: cxx: provide line_request::chip_name() Bartosz Golaszewski
2023-07-20 14:47 ` Bartosz Golaszewski [this message]
2023-07-20 14:47 ` [libgpiod][PATCH v2 5/5] bindings: rust: provide LineRequest::chip_name() Bartosz Golaszewski
2023-07-20 14:53 ` Erik Schilling
2023-07-21 3:15 ` Kent Gibson
2023-07-21 18:35 ` Bartosz Golaszewski
2023-07-22 2:07 ` Kent Gibson
2023-07-22 12:30 ` Bartosz Golaszewski
2023-07-21 3:27 ` Kent Gibson
2023-07-21 6:55 ` Viresh Kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230720144747.73276-5-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=erik.schilling@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=warthog618@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.