aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-04-18 11:58:57 +0200
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-04-18 15:08:57 +0200
commitb9f5d29950a41d2a3089e8e21838822b751f937f (patch)
tree3e231191679943bdf9aeb399e1a9858819abaf0f
parent4e75476ccb093739ce8bf52d9a8fdf9947ef1cff (diff)
downloadlibgpiod-b9f5d29950a41d2a3089e8e21838822b751f937f.tar.gz
bindings: python: don't install test-specific C extension binaries
We want to ship the source code for C extensions used by the test suite but not install the built shared objects or put them into the bdist. Extend the build_ext command to delete the tests from the build directory right after the extensions have been built and - possibly - installed into the source tree (if --inplace is set). Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
-rw-r--r--bindings/python/setup.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/bindings/python/setup.py b/bindings/python/setup.py
index a53d55fa..66b79080 100644
--- a/bindings/python/setup.py
+++ b/bindings/python/setup.py
@@ -1,8 +1,23 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <brgl@bgdev.pl>
-from os import environ
+from os import environ, path
from setuptools import setup, Extension, find_packages
+from setuptools.command.build_ext import build_ext as orig_build_ext
+from shutil import rmtree
+
+
+class build_ext(orig_build_ext):
+ """
+ setuptools install all C extentions even if they're excluded in setup().
+ As a workaround - remove the tests directory right after all extensions
+ were built (and possibly copied to the source directory if inplace is set).
+ """
+
+ def run(self):
+ super().run()
+ rmtree(path.join(self.build_lib, "tests"), ignore_errors=True)
+
gpiod_ext = Extension(
"gpiod._ext",
@@ -46,6 +61,7 @@ setup(
name="libgpiod",
packages=find_packages(exclude=["tests", "tests.*"]),
ext_modules=extensions,
+ cmdclass={"build_ext": build_ext},
version=__version__,
author="Bartosz Golaszewski",
author_email="brgl@bgdev.pl",