From patchwork Wed Oct 25 09:36:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Vinnicombe X-Patchwork-Id: 19183 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 850A5BDCBD for ; Wed, 25 Oct 2023 09:37:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BC1CE6298F; Wed, 25 Oct 2023 11:37:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1698226663; bh=Wg0hwiLnNC4ocCGf3NTeTThJSfhTGMP+0Mig14kS8dQ=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=3osmvNg8/E/sndk1z2+vOCprt51Pacet0OFa/w9/jY3D7+BJoAE4HcosSi1DwXZXm y+fiqXmMMui0gPqzoe7RBf+aQI6vBBeAjP/Bu5uAWYEsn1124jI7RLSKAV3hBzhJ7M 44v+X3rLA0W0sWfXkVwC0Yz6m63/5tVXaTdoMpnYGHLa8k6m29MGN6BFYmMwT+LV9S 6TeU2cXH4s4QvnHS1KWGAJaypoNlDj/W14XWKifW/LVe8nMw2uJAJCLUVuy1bCKiMg D1PXMY9jbC9IdkWIU1fwAAxdDRektEuQXcT3c+ixZ4YKtdPhKrZi0FWLHvnmNXyE4f 6dcD+H3v1PuYQ== Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C999161DCB for ; Wed, 25 Oct 2023 11:37:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ZRmBO0Gj"; dkim-atps=neutral Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40838915cecso44645565e9.2 for ; Wed, 25 Oct 2023 02:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1698226661; x=1698831461; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4vZ+dJG4sKt2La/skPuj1Yi3Hi7yIIhti5wJH+CS90Q=; b=ZRmBO0GjHkcFHi48qpSxma6hXavQiUaSWWrio+syxDO0CFWR6VXneV0lYWCDStYC6w tdzZRujT4swrJBY00nXy0gSCMFOSq24kEJGhPRueGHVN4zFq6X0/kkeglB7wh6Ld+EDT pNlgc2gT2j8CmCiAJdRjXVFBzW+jb0YpPiNew1c0QXGFKmI2zMXjIpkEFTEIVSFe6YuT IQxxO9ZyN31RfGxCjihU3JTYcckRVFPmx0WxRNPsa/sjrLeNUaVHjStrgGpicwvvzMbL vkm7BzgOX1tNrY+IKMBNoqJlypM/rEL1k+jfhxGAIMcvmzcW5kLLcNwGs/BjJDX+vVS2 2zVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698226661; x=1698831461; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4vZ+dJG4sKt2La/skPuj1Yi3Hi7yIIhti5wJH+CS90Q=; b=XUue2TnnHHMwI89zvwVpMEupl7SvQyRDvc2KgQqVIJDWngMRyQy8SGeAhnPTQ5qAzt ca7x2TTTONRDG27Nw2GzCbRXdrgvPmyJwxCwYgImXsheqgE7Z0jBo7kpfy9xKa+58gBo XVwmwDzTqSJfaJIDTCyNKvqvRkTEk6iDFFrf3pDb/mDmEWsNCUkncUk5wfCbUZQxHewg wBgbSQkm4mD4MaDc522qUyLLStGHmaWnRv7US92aE8hkZ2gopRir2XvMuFaUGTK1YeTs sXYZe3+xBinVC/DWk5NnN0mr2hBPGjOoj2myE2B/mbhcLFS2pjTMJtE6mAlimPZLw2Bw OwCQ== X-Gm-Message-State: AOJu0Yyead2ml3cnEBUXaDHcf695urcVTr2XQZv/Hw1wvXnIgyjmRflD IdtEg0LYJiTTO3J6bzCA3IWdRGJvAKcPMmvafTM= X-Google-Smtp-Source: AGHT+IH0X4hsOPC+daGO7w5R6YVZdmH7wf1YcaUEZPEoxp9+z38VLcHGVAcGhe4MRgUx6lZpWGnsqQ== X-Received: by 2002:a5d:67c5:0:b0:32d:8183:d130 with SMTP id n5-20020a5d67c5000000b0032d8183d130mr9600719wrw.38.1698226660751; Wed, 25 Oct 2023 02:37:40 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id r17-20020a5d4e51000000b0032d09f7a713sm11712295wrt.18.2023.10.25.02.37.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 02:37:40 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 25 Oct 2023 10:36:49 +0100 Message-Id: <20231025093649.25222-1-william.vinnicombe@raspberrypi.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] py: libcamera: Improve python binding installation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: William Vinnicombe via libcamera-devel From: William Vinnicombe Reply-To: William Vinnicombe Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The existing meson.build file installs the bindings to an architecture specific libdir (eg /usr/local/lib/aarch64-linux-gnu/), which is not picked up by default python which only looks in the non architecture specific libdir (eg /usr/local/lib/python3.11/). It also will always build using the system python, rather than building using the same python as meson is using. This prevents a user being able to build the bindings for a different version of python, without changing their system python to that version. Modify the build process to use the meson Python module to build the python bindings targets, so it installs them to the correct directories for python, and builds them for the version of python that meson is running with. Signed-off-by: William Vinnicombe --- src/py/libcamera/meson.build | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index f58c7198..e9e3f915 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -1,6 +1,8 @@ # SPDX-License-Identifier: CC0-1.0 -py3_dep = dependency('python3', required : get_option('pycamera')) + +py = import('python').find_installation('python3', required : get_option('pycamera')) +py3_dep = py.dependency(required : get_option('pycamera')) if not py3_dep.found() pycamera_enabled = false @@ -78,15 +80,12 @@ pycamera_args = [ '-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT', ] -destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera' - -pycamera = shared_module('_libcamera', - pycamera_sources, - install : true, - install_dir : destdir, - name_prefix : '', - dependencies : pycamera_deps, - cpp_args : pycamera_args) +pycamera = py.extension_module('_libcamera', + pycamera_sources, + install : true, + subdir : 'libcamera', + dependencies : pycamera_deps, + cpp_args : pycamera_args) # Create symlinks from the build dir to the source dir so that we can use the # Python module directly from the build dir. @@ -99,7 +98,9 @@ run_command('ln', '-fsrT', meson.current_source_dir() / 'utils', meson.current_build_dir() / 'utils', check : true) -install_data(['__init__.py'], install_dir : destdir) +py.install_sources(['__init__.py'], + subdir : 'libcamera', + pure : false) # \todo Generate stubs when building. See https://peps.python.org/pep-0484/#stub-files # Note: Depends on pybind11-stubgen. To generate pylibcamera stubs: