From 1cfdf5c198f1c74c2f894067baf4670f5bca8e70 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Wed, 9 Feb 2022 19:53:06 +0100 Subject: Fix arrayobject.h path on Debian based distros On Debian Linux and its derivatives such as Ubuntu and LinuxMint, Python packages installed through the package manager are kept in a different non-standard directory called 'dist-packages' instead of the normal 'site-packages' [1]. To detect the Linux distribution the 'platform' library (part of the Python stdlib) provides a function 'platform.freedesktop_os_release()' that parses a standard file '/etc/os-release' available in most Linux distributions [2]. However this function is rather new (Python >= 3.10) and unavailable in most python installations, so the core of its functionaly was reimplemented here. [1]: https://wiki.debian.org/Python#Deviations_from_upstream [2]: https://docs.python.org/3/library/platform.html#linux-platforms Signed-off-by: Jonas Schmid --- c_extension.c | 13 +++++++++++-- setup_c_extension.py | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/c_extension.c b/c_extension.c index 00da503..6cfadba 100644 --- a/c_extension.c +++ b/c_extension.c @@ -42,8 +42,17 @@ POSSIBILITY OF SUCH DAMAGE. #include "helpers.h" -#include - +/* On Debian Linux and its derivatives (such as ubuntu), Python libraries + * installed through the package manager are kept in a non-standard directory + * 'dist-packages' instead of 'site-packages'. Why? Who knows. + * + * https://wiki.debian.org/Python#Deviations_from_upstream + */ +#ifdef DEBIAN_LINUX + #include +#else + #include +#endif #define DEFAULT_FRAME_RATE 10 ///< default frame rate diff --git a/setup_c_extension.py b/setup_c_extension.py index 695c88c..9bed938 100644 --- a/setup_c_extension.py +++ b/setup_c_extension.py @@ -1,8 +1,24 @@ from distutils.core import setup, Extension + +extra_compile_args = [] + +# Detect if distribution is Ubuntu or Debian based +with open('/etc/os-release') as f: + lines = filter(None, f.read().split('\n')) + + info = {} + for (key, val) in map(lambda x: x.split('='), lines): + info[key] = val + + # The ID_LIKE key is usually a space separated list of OSes upon which the distribution is based. + if any(os in ('ubuntu', 'debian') for os in info['ID_LIKE'].split()): + extra_compile_args.append('-DDEBIAN_LINUX') + + setup(name = 'o3000', version = '1.0', ext_modules = [Extension( 'o3000', sources = ['c_extension.c', 'helpers.c'], libraries = ['o3000','o3000_imgpipe','tiff'], - #extra_compile_args = ['-Wextra'] + extra_compile_args = extra_compile_args # + ['-Wextra'] )]) -- cgit v1.2.1