linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Howard <phil@gadgetoid.com>
To: Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Kent Gibson <warthog618@gmail.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>
Cc: linux-gpio@vger.kernel.org, Phil Howard <phil@gadgetoid.com>
Subject: [libgpiod][PATCH 1/3] bindings: python: optionally include module in sdist
Date: Wed, 11 Oct 2023 13:12:44 +0100	[thread overview]
Message-ID: <20231011121246.9467-2-phil@gadgetoid.com> (raw)
In-Reply-To: <20231011121246.9467-1-phil@gadgetoid.com>

Build gpiod into Python module.

Optional environment var USE_SYSTEM_GPIO=1 to
generate a module that depends upon system gpiod.

Signed-off-by: Phil Howard <phil@gadgetoid.com>
---
 bindings/python/MANIFEST.in |  4 +++
 bindings/python/include     |  1 +
 bindings/python/lib         |  1 +
 bindings/python/setup.py    | 57 ++++++++++++++++++++++++++++---------
 4 files changed, 50 insertions(+), 13 deletions(-)
 create mode 120000 bindings/python/include
 create mode 120000 bindings/python/lib

diff --git a/bindings/python/MANIFEST.in b/bindings/python/MANIFEST.in
index c7124d4..eff8977 100644
--- a/bindings/python/MANIFEST.in
+++ b/bindings/python/MANIFEST.in
@@ -11,3 +11,7 @@ recursive-include gpiod/ext *.h
 
 recursive-include tests/gpiosim *.c
 recursive-include tests/procname *.c
+
+recursive-include lib *.c
+recursive-include lib *.h
+recursive-include include *.h
diff --git a/bindings/python/include b/bindings/python/include
new file mode 120000
index 0000000..fcffffb
--- /dev/null
+++ b/bindings/python/include
@@ -0,0 +1 @@
+../../include
\ No newline at end of file
diff --git a/bindings/python/lib b/bindings/python/lib
new file mode 120000
index 0000000..58677dd
--- /dev/null
+++ b/bindings/python/lib
@@ -0,0 +1 @@
+../../lib
\ No newline at end of file
diff --git a/bindings/python/setup.py b/bindings/python/setup.py
index 66b7908..2e25981 100644
--- a/bindings/python/setup.py
+++ b/bindings/python/setup.py
@@ -19,19 +19,53 @@ class build_ext(orig_build_ext):
         rmtree(path.join(self.build_lib, "tests"), ignore_errors=True)
 
 
+with open("gpiod/version.py", "r") as fd:
+    exec(fd.read())
+
+
+sources = [
+    # gpiod Python bindings
+    "gpiod/ext/chip.c",
+    "gpiod/ext/common.c",
+    "gpiod/ext/line-config.c",
+    "gpiod/ext/line-settings.c",
+    "gpiod/ext/module.c",
+    "gpiod/ext/request.c",
+]
+
+if "USE_SYSTEM_GPIOD" in environ and environ["USE_SYSTEM_GPIOD"] == "1":
+    libraries = ["gpiod"]
+    include_dirs = ["gpiod"]
+else:
+    sources += [
+        # gpiod library
+        "lib/chip.c",
+        "lib/chip-info.c",
+        "lib/edge-event.c",
+        "lib/info-event.c",
+        "lib/internal.c",
+        "lib/line-config.c",
+        "lib/line-info.c",
+        "lib/line-request.c",
+        "lib/line-settings.c",
+        "lib/misc.c",
+        "lib/request-config.c",
+    ]
+    libraries = []
+    include_dirs = ["include", "lib", "gpiod/ext"]
+
+
 gpiod_ext = Extension(
     "gpiod._ext",
-    sources=[
-        "gpiod/ext/chip.c",
-        "gpiod/ext/common.c",
-        "gpiod/ext/line-config.c",
-        "gpiod/ext/line-settings.c",
-        "gpiod/ext/module.c",
-        "gpiod/ext/request.c",
-    ],
+    libraries=libraries,
+    sources=sources,
     define_macros=[("_GNU_SOURCE", "1")],
-    libraries=["gpiod"],
-    extra_compile_args=["-Wall", "-Wextra"],
+    include_dirs=include_dirs,
+    extra_compile_args=[
+        "-Wall",
+        "-Wextra",
+        '-DGPIOD_VERSION_STR="{}"'.format(__version__),
+    ],
 )
 
 gpiosim_ext = Extension(
@@ -54,9 +88,6 @@ if "GPIOD_WITH_TESTS" in environ and environ["GPIOD_WITH_TESTS"] == "1":
     extensions.append(gpiosim_ext)
     extensions.append(procname_ext)
 
-with open("gpiod/version.py", "r") as fd:
-    exec(fd.read())
-
 setup(
     name="libgpiod",
     packages=find_packages(exclude=["tests", "tests.*"]),
-- 
2.34.1


  reply	other threads:[~2023-10-11 12:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-11 12:12 [libgpiod][PATCH 0/3] bindings: python: optionally include module (...) Phil Howard
2023-10-11 12:12 ` Phil Howard [this message]
2023-10-11 17:11   ` [libgpiod][PATCH 1/3] bindings: python: optionally include module in sdist Andy Shevchenko
2023-10-12  9:03     ` Phil Howard
2023-10-12 19:18       ` Bartosz Golaszewski
2023-10-12 19:37   ` Bartosz Golaszewski
2023-10-11 12:12 ` [libgpiod][PATCH 2/3] bindings: python: add pyproject.toml, pep 518 Phil Howard
2023-10-12 19:10   ` Bartosz Golaszewski
2023-10-11 12:12 ` [libgpiod][PATCH 3/3] bindings: python: require python 3.9.0 Phil Howard
2023-10-12 19:07   ` Bartosz Golaszewski

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=20231011121246.9467-2-phil@gadgetoid.com \
    --to=phil@gadgetoid.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).