From b9f5d29950a41d2a3089e8e21838822b751f937f Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Tue, 18 Apr 2023 11:58:57 +0200 Subject: [PATCH] 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 --- bindings/python/setup.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bindings/python/setup.py b/bindings/python/setup.py index a53d55f..66b7908 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 -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", -- 2.30.2