[{"id":28163,"web_url":"https://patchwork.libcamera.org/comment/28163/","msgid":"<CAA9M1nWewOsycyWdFyMNG-YZPzgZ_JVqGKp8hE8oAgO2K=hh5g@mail.gmail.com>","date":"2023-11-23T14:03:02","subject":"Re: [libcamera-devel] [PATCH v2] py: libcamera: Improve python\n\tbinding installation","submitter":{"id":131,"url":"https://patchwork.libcamera.org/api/people/131/","name":"William Vinnicombe","email":"william.vinnicombe@raspberrypi.com"},"content":"Could I request some reviews on this V2 of my python patch? It should now\nwork with cross-compilation, as it still uses the old method for building\nthe bindings when cross-compiling.\n\nThanks,\nWilliam\n\nOn Thu, 26 Oct 2023 at 13:52, William Vinnicombe <\nwilliam.vinnicombe@raspberrypi.com> wrote:\n\n> The existing meson.build file installs the bindings to an architecture\n> specific libdir (eg /usr/local/lib/aarch64-linux-gnu/), which is not\n> picked up by default python which only looks in the non architecture\n> specific libdir (eg /usr/local/lib/python3.11/). It also will always\n> build using the system python, rather than building using the same\n> python as meson is using. This prevents a user being able to build the\n> bindings for a different version of python, without changing their\n> system python to that version.\n>\n> Modify the build process to use the meson Python module to build the\n> python bindings targets, so it installs them to the correct directories\n> for python, and builds them for the version of python that meson is\n> running with. For cross-compiling, still use the previous method to\n> build the bindings, as the host machine version of python should be\n> used instead.\n>\n> Signed-off-by: William Vinnicombe <william.vinnicombe@raspberrypi.com>\n> ---\n>  src/py/libcamera/meson.build | 60 +++++++++++++++++++++++++++---------\n>  1 file changed, 45 insertions(+), 15 deletions(-)\n>\n> diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build\n> index f58c7198..128793aa 100644\n> --- a/src/py/libcamera/meson.build\n> +++ b/src/py/libcamera/meson.build\n> @@ -1,10 +1,25 @@\n>  # SPDX-License-Identifier: CC0-1.0\n>\n> -py3_dep = dependency('python3', required : get_option('pycamera'))\n> -\n> -if not py3_dep.found()\n> -    pycamera_enabled = false\n> -    subdir_done()\n> +if meson.is_cross_build()\n> +    py3_dep = dependency('python3', required : get_option('pycamera'))\n> +\n> +    if not py3_dep.found()\n> +        pycamera_enabled = false\n> +        subdir_done()\n> +    endif\n> +else\n> +    py = import('python').find_installation('python3', required :\n> get_option('pycamera'))\n> +\n> +    if not py.found()\n> +        pycamera_enabled = false\n> +        subdir_done()\n> +    else\n> +        py3_dep = py.dependency(required : get_option('pycamera'))\n> +        if not py3_dep.found()\n> +            pycamera_enabled = false\n> +            subdir_done()\n> +        endif\n> +    endif\n>  endif\n>\n>  pybind11_dep = dependency('pybind11', required : get_option('pycamera'))\n> @@ -78,15 +93,24 @@ pycamera_args = [\n>      '-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT',\n>  ]\n>\n> -destdir = get_option('libdir') / ('python' + py3_dep.version()) /\n> 'site-packages' / 'libcamera'\n> -\n> -pycamera = shared_module('_libcamera',\n> -                         pycamera_sources,\n> -                         install : true,\n> -                         install_dir : destdir,\n> -                         name_prefix : '',\n> -                         dependencies : pycamera_deps,\n> -                         cpp_args : pycamera_args)\n> +if meson.is_cross_build()\n> +    destdir = get_option('libdir') / ('python' + py3_dep.version()) /\n> 'site-packages' / 'libcamera'\n> +\n> +    pycamera = shared_module('_libcamera',\n> +                             pycamera_sources,\n> +                             install : true,\n> +                             install_dir : destdir,\n> +                             name_prefix : '',\n> +                             dependencies : pycamera_deps,\n> +                             cpp_args : pycamera_args)\n> +else\n> +    pycamera = py.extension_module('_libcamera',\n> +                                   pycamera_sources,\n> +                                   install : true,\n> +                                   subdir : 'libcamera',\n> +                                   dependencies : pycamera_deps,\n> +                                   cpp_args : pycamera_args)\n> +endif\n>\n>  # Create symlinks from the build dir to the source dir so that we can use\n> the\n>  # Python module directly from the build dir.\n> @@ -99,7 +123,13 @@ run_command('ln', '-fsrT', meson.current_source_dir()\n> / 'utils',\n>              meson.current_build_dir() / 'utils',\n>              check : true)\n>\n> -install_data(['__init__.py'], install_dir : destdir)\n> +if meson.is_cross_build()\n> +    install_data(['__init__.py'], install_dir : destdir)\n> +else\n> +    py.install_sources(['__init__.py'],\n> +                       subdir : 'libcamera',\n> +                       pure : false)\n> +endif\n>\n>  # \\todo Generate stubs when building. See\n> https://peps.python.org/pep-0484/#stub-files\n>  # Note: Depends on pybind11-stubgen. To generate pylibcamera stubs:\n> --\n> 2.39.2\n>\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C6FCCC3220\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Nov 2023 14:03:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 801BC629BD;\n\tThu, 23 Nov 2023 15:03:16 +0100 (CET)","from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com\n\t[IPv6:2607:f8b0:4864:20::102b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8DC5F629AF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Nov 2023 15:03:15 +0100 (CET)","by mail-pj1-x102b.google.com with SMTP id\n\t98e67ed59e1d1-285685530f3so417951a91.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Nov 2023 06:03:15 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1700748196;\n\tbh=orgLoCk2ETBOK8bJZWYefzG8QkvaDOJToIrYW9+7di8=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=E3hTWoj0czDa0j4JZOVMNhq6A9/KgGaaKr2mFgpGsLgcjuzVGLHJ903r2SQZ3wkce\n\ty26Qb02Zpy8fR/RO0YLR0OGa85uZDRKQJbNXd3eJJ9DRcEkIBcENtSgUGapAZ2GtQs\n\tXFK6nORjo922cqlYD/TOJJEJSkidd5DtkCcv0AdXpI1/p6eV09lsKxslqCBagy+Ogz\n\t6BrbTjihgt2dpa0p3KqTgZ4w5AyCoBWaD60NoYIDtjatcv0FJVMsMmYZyl8vLOtvvW\n\tVTzjJMZWhe1i1vrujtivXbvwUcgai7AhlpsHtC4V1Qvf4ob98b4ZSLL6x6zcXrI8E7\n\tH6gBSJt7+pxJQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1700748194; x=1701352994;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=c7r39w10zZ+dCJaGTVLVpyrvGOu5UKt9ExMDUpgW9dk=;\n\tb=SFPIe3cu8gSljAxTgHlAvPHyQBg2sI8SE8a+wFbh8LAZ08WWvQeuJywYiXFErufXxO\n\t3igEWH6FqcLN7zRj6DjTKFFOjQpPm+o/1yCl29HMF+OG+xeJqzwozL+Hh1/Y6jRpQszm\n\tUenhB+yq6Vw0uOi1KuUVqpI98OXHqjWJarsGc8WE1yhXsBQGeiDj1eklkcS+nfoM/MnM\n\tFAmGDLchPRLCIh6Uq+hSxIVie++3E+t0rD+SAa6N+CaG3YoNWAU1aDgqwn9Ul5zxMGWo\n\tbBeJm0cw7cCeT/AVzDekkA2PAiWaj3PCgB9Cw6wYSrZrd/PGZi9dZJt+9caL7PIpLs/7\n\tyXcg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"SFPIe3cu\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1700748194; x=1701352994;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=c7r39w10zZ+dCJaGTVLVpyrvGOu5UKt9ExMDUpgW9dk=;\n\tb=vXf8OyVA7rFmiiYeviKLRsJ0/2IRgAr+9EXKUqUggSOZxZo+h9GtFTKRgg7S67bSq0\n\ttc6z0lGwc9N64d6VZSbOTWaErEl5YXCNAGizaAunvw314f7Yvb47dhEIkn9GQezq+DuC\n\t1sT3tyXk0jZzwDzgeMbpK2LWxvp07tuM5eNe7M8i/TTfTBsB8tX9Z5K6yRaEZ1iYPb6J\n\ty0unIBNCJivRN+/V7R69gHUcvQZbcTPMmfFJ30sLRh7Egju1FItxDEFspi26vFrHhUmc\n\tp/HkOV3D48ZrJmLFfCKOEh8vm9/Bi+wZFBOtzLKj8urTPMkNqdkmPWdbVkvAzcBbZJLr\n\tW/IQ==","X-Gm-Message-State":"AOJu0YzSIOwaJi5ENwjAI9N2AFSF3YOD2KFZNeIXi+ErEBRl53XeLUhD\n\tFgS/iMOSI/6kmg4fmuO9NWNjf3X+ZchqhM1fXjLBCjnehZFRHJ28","X-Google-Smtp-Source":"AGHT+IEwSyEJjFZ4VnNv17Y9KXePS80hgh8HKtlbn2euAGWRjHJz6AJBEnYhQYqvltk/RUn74TzPlijCed71j8a6ouo=","X-Received":"by 2002:a17:90a:6349:b0:280:65ed:df9 with SMTP id\n\tv9-20020a17090a634900b0028065ed0df9mr5918095pjs.31.1700748193632;\n\tThu, 23 Nov 2023 06:03:13 -0800 (PST)","MIME-Version":"1.0","References":"<20231026125038.27985-1-william.vinnicombe@raspberrypi.com>","In-Reply-To":"<20231026125038.27985-1-william.vinnicombe@raspberrypi.com>","Date":"Thu, 23 Nov 2023 14:03:02 +0000","Message-ID":"<CAA9M1nWewOsycyWdFyMNG-YZPzgZ_JVqGKp8hE8oAgO2K=hh5g@mail.gmail.com>","To":"libcamera-devel@lists.libcamera.org","Content-Type":"multipart/alternative; boundary=\"000000000000ef2aa3060ad24b45\"","Subject":"Re: [libcamera-devel] [PATCH v2] py: libcamera: Improve python\n\tbinding installation","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"William Vinnicombe via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"William Vinnicombe <william.vinnicombe@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":28165,"web_url":"https://patchwork.libcamera.org/comment/28165/","msgid":"<ab0211a8-17a2-4060-b30e-32cd835a9df4@ideasonboard.com>","date":"2023-11-23T15:26:05","subject":"Re: [libcamera-devel] [PATCH v2] py: libcamera: Improve python\n\tbinding installation","submitter":{"id":109,"url":"https://patchwork.libcamera.org/api/people/109/","name":"Tomi Valkeinen","email":"tomi.valkeinen@ideasonboard.com"},"content":"Hi,\n\nOn 26/10/2023 15:50, William Vinnicombe via libcamera-devel wrote:\n> The existing meson.build file installs the bindings to an architecture\n> specific libdir (eg /usr/local/lib/aarch64-linux-gnu/), which is not\n\nFor me, in buildroot, it would be \"/usr/lib/python3.11/site-packages\", \nso no arch part. On my PC, though, I get \n\"/usr/lib/x86_64-linux-gnu/python3.10/site-packages/libcamera\", which is \nnot in the python search path. However, even if I did drop the arch \npart, it wouldn't be right for my PC as the python system search paths \ndon't contain \"site-packages\", but \"dist-packages\": \n\"/usr/lib/python3.10/dist-packages\". Although there _is_ \"site-packages\" \nin the path, but for the user specific pip path: \n\"/home/tomba/.local/lib/python3.10/site-packages\"...\n\n> picked up by default python which only looks in the non architecture\n> specific libdir (eg /usr/local/lib/python3.11/). It also will always\n> build using the system python, rather than building using the same\n> python as meson is using. This prevents a user being able to build the\n\nWell... I don't know which one of those is better or worse =). And it's \nnot system python (if that means the build system), it's the target python.\n\nI don't think it's a good idea to always use the same python as meson is \nusing, and for cross-compiling that's totally wrong, of course. It \nshould be perfectly fine for meson to always use the normal system \npython, while targeting some specific python version.\n\nIn your version, shouldn't the import('python').find_installation() call \nbe configurable, so that the user would tell meson where to look for the \npython installation? The docs say find_installation() can take e.g. a \npath to the python.\n\n> bindings for a different version of python, without changing their\n> system python to that version.\n\nHow do you change the python version with your patch?\n\n> Modify the build process to use the meson Python module to build the\n> python bindings targets, so it installs them to the correct directories\n> for python, and builds them for the version of python that meson is\n> running with. For cross-compiling, still use the previous method to\n> build the bindings, as the host machine version of python should be\n> used instead.\n\nTo clarify, if using your version (i.e. the \"official\" meson version) \nfor finding python, the build goes totally bonkers as meson starts \nmixing up the build system's and target's libraries. I think it was less \nbonkers earlier, but now it looks to be totally broken (probably related \nto a meson bug Laurent found recently).\n\nIn any case, this patch keeps the cross-compilation working for me, and \na native build on my PC works too. So it's ugly, but, afaics, works.\n\nYou could add some comments to the meson.build file, to explain why all \nthis is being done.\n\n  Tomi\n\n> Signed-off-by: William Vinnicombe <william.vinnicombe@raspberrypi.com>\n> ---\n>   src/py/libcamera/meson.build | 60 +++++++++++++++++++++++++++---------\n>   1 file changed, 45 insertions(+), 15 deletions(-)\n> \n> diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build\n> index f58c7198..128793aa 100644\n> --- a/src/py/libcamera/meson.build\n> +++ b/src/py/libcamera/meson.build\n> @@ -1,10 +1,25 @@\n>   # SPDX-License-Identifier: CC0-1.0\n>   \n> -py3_dep = dependency('python3', required : get_option('pycamera'))\n> -\n> -if not py3_dep.found()\n> -    pycamera_enabled = false\n> -    subdir_done()\n> +if meson.is_cross_build()\n> +    py3_dep = dependency('python3', required : get_option('pycamera'))\n> +\n> +    if not py3_dep.found()\n> +        pycamera_enabled = false\n> +        subdir_done()\n> +    endif\n> +else\n> +    py = import('python').find_installation('python3', required : get_option('pycamera'))\n> +\n> +    if not py.found()\n> +        pycamera_enabled = false\n> +        subdir_done()\n> +    else\n> +        py3_dep = py.dependency(required : get_option('pycamera'))\n> +        if not py3_dep.found()\n> +            pycamera_enabled = false\n> +            subdir_done()\n> +        endif\n> +    endif\n>   endif\n>   \n>   pybind11_dep = dependency('pybind11', required : get_option('pycamera'))\n> @@ -78,15 +93,24 @@ pycamera_args = [\n>       '-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT',\n>   ]\n>   \n> -destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera'\n> -\n> -pycamera = shared_module('_libcamera',\n> -                         pycamera_sources,\n> -                         install : true,\n> -                         install_dir : destdir,\n> -                         name_prefix : '',\n> -                         dependencies : pycamera_deps,\n> -                         cpp_args : pycamera_args)\n> +if meson.is_cross_build()\n> +    destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera'\n> +\n> +    pycamera = shared_module('_libcamera',\n> +                             pycamera_sources,\n> +                             install : true,\n> +                             install_dir : destdir,\n> +                             name_prefix : '',\n> +                             dependencies : pycamera_deps,\n> +                             cpp_args : pycamera_args)\n> +else\n> +    pycamera = py.extension_module('_libcamera',\n> +                                   pycamera_sources,\n> +                                   install : true,\n> +                                   subdir : 'libcamera',\n> +                                   dependencies : pycamera_deps,\n> +                                   cpp_args : pycamera_args)\n> +endif\n>   \n>   # Create symlinks from the build dir to the source dir so that we can use the\n>   # Python module directly from the build dir.\n> @@ -99,7 +123,13 @@ run_command('ln', '-fsrT', meson.current_source_dir() / 'utils',\n>               meson.current_build_dir() / 'utils',\n>               check : true)\n>   \n> -install_data(['__init__.py'], install_dir : destdir)\n> +if meson.is_cross_build()\n> +    install_data(['__init__.py'], install_dir : destdir)\n> +else\n> +    py.install_sources(['__init__.py'],\n> +                       subdir : 'libcamera',\n> +                       pure : false)\n> +endif\n>   \n>   # \\todo Generate stubs when building. See https://peps.python.org/pep-0484/#stub-files\n>   # Note: Depends on pybind11-stubgen. To generate pylibcamera stubs:","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 6FB17C3220\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Nov 2023 15:26:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9E9CC629BC;\n\tThu, 23 Nov 2023 16:26:10 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F19DE61DAC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Nov 2023 16:26:08 +0100 (CET)","from [192.168.88.20] (91-158-149-209.elisa-laajakaista.fi\n\t[91.158.149.209])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E22B9DB7;\n\tThu, 23 Nov 2023 16:25:36 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1700753170;\n\tbh=wzsB8hjTQ/ik92hK42hHIHhOuKDBhxjj2QlNkFfQ9mA=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=cZKeYYzJHn0+O9E+DF/v1YyTPZV1TQOqzzFVNQDb3g2Ga04SlB1S8g9bZ6crqcyDI\n\tEMMDcTmdf/V/5fbnWjM2ABfUxmwBV6KblrFuV+UTt6gyOfR/BYuDygEl4bKY4PtBjZ\n\tXOknXpk172kUFHxEa9uZNfja2PXh36/c41aRlZVfwz3WqNLe+E0vNQQPMsp4UMAafs\n\tZK7VDJkXiNYPDrbtwa2NcbQE64FxVlDlFq5G9oMjJAYfdMmV7IICeEHkyPUlBHJRvL\n\tORgAH4XDc5Y4mhIdWo5RfiP+KxcSAYdk+7uNBHKS4jo6Det63eZ+o8I4cSxPsQMx5S\n\tbcPr+bXPOnpKA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1700753137;\n\tbh=wzsB8hjTQ/ik92hK42hHIHhOuKDBhxjj2QlNkFfQ9mA=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=DW8na+IKlfI5Wd/xkg8Isn6T3WH+TiftO5ChudjpcetTtLQCC4UYpgTnJBx5Wr9D2\n\taGC7ul5zHrctCtYJe7XxVs10gemTVqNZ/8v1OPaM3sOsshFmsYPE1t1/H2/tkqAuRe\n\tSJSIRyulsuFZrK1O3W+FuBdRh4RMXKOxzFnGGHjQ="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"DW8na+IK\"; dkim-atps=neutral","Message-ID":"<ab0211a8-17a2-4060-b30e-32cd835a9df4@ideasonboard.com>","Date":"Thu, 23 Nov 2023 17:26:05 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Content-Language":"en-US","To":"William Vinnicombe <william.vinnicombe@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20231026125038.27985-1-william.vinnicombe@raspberrypi.com>","Autocrypt":"addr=tomi.valkeinen@ideasonboard.com; keydata=\n\txsFNBE6ms0cBEACyizowecZqXfMZtnBniOieTuFdErHAUyxVgtmr0f5ZfIi9Z4l+uUN4Zdw2\n\twCEZjx3o0Z34diXBaMRJ3rAk9yB90UJ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sBS0DaZb\n\t4IkLmZwEXpZcIOQjQ71fqlpiXkXSIaQ6YMEs8WjBbpP81h7QxWIfWtp+VnwNGc6nq5IQDESH\n\tmvQcsFS7d3eGVI6eyjCFdcAO8eMAEQEAAcLBXwQYAQIACQUCTqazRwIbDAAKCRD6PaqMvJYe\n\t9fA7EACS6exUedsBKmt4pT7nqXBcRsqm6YzT6DeCM8PWMTeaVGHiR4TnNFiT3otD5UpYQI7S\n\tsuYxoTdHrrrBzdlKe5rUWpzoZkVK6p0s9OIvGzLT0lrb0HC9iNDWT3JgpYDnk4Z2mFi6tTbq\n\txKMtpVFRA6FjviGDRsfkfoURZI51nf2RSAk/A8BEDDZ7lgJHskYoklSpwyrXhkp9FHGMaYII\n\tm9EKuUTX9JPDG2FTthCBrdsgWYPdJQvM+zscq09vFMQ9Fykbx5N8z/oFEUy3ACyPqW2oyfvU\n\tCH5WDpWBG0s5BALp1gBJPytIAd/pY/5ZdNoi0Cx3+Z7jaBFEyYJdWy1hGddpkgnMjyOfLI7B\n\tCFrdecTZbR5upjNSDvQ7RG85SnpYJTIin+SAUazAeA2nS6gTZzumgtdw8XmVXZwdBfF+ICof\n\t92UkbYcYNbzWO/GHgsNT1WnM4sa9lwCSWH8Fw1o/3bX1VVPEsnESOfxkNdu+gAF5S6+I6n3a\n\tueeIlwJl5CpT5l8RpoZXEOVtXYn8zzOJ7oGZYINRV9Pf8qKGLf3Dft7zKBP832I3PQjeok7F\n\tyjt+9S+KgSFSHP3Pa4E7lsSdWhSlHYNdG/czhoUkSCN09C0rEK93wxACx3vtxPLjXu6RptBw\n\t3dRq7n+mQChEB1am0BueV1JZaBboIL0AGlSJkm23kw==","In-Reply-To":"<20231026125038.27985-1-william.vinnicombe@raspberrypi.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v2] py: libcamera: Improve python\n\tbinding installation","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Tomi Valkeinen via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":35493,"web_url":"https://patchwork.libcamera.org/comment/35493/","msgid":"<20250819011037.GG5862@pendragon.ideasonboard.com>","date":"2025-08-19T01:10:37","subject":"Re: [libcamera-devel] [PATCH v2] py: libcamera: Improve python\n\tbinding installation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hello,\n\nReviving this old thread after a weekend of rabbit hole exploration.\n\nOn Thu, Nov 23, 2023 at 05:26:05PM +0200, 📷-dev wrote:\n> On 26/10/2023 15:50, William Vinnicombe via libcamera-devel wrote:\n> > The existing meson.build file installs the bindings to an architecture\n> > specific libdir (eg /usr/local/lib/aarch64-linux-gnu/), which is not\n> \n> For me, in buildroot, it would be \"/usr/lib/python3.11/site-packages\", \n> so no arch part. On my PC, though, I get \n> \"/usr/lib/x86_64-linux-gnu/python3.10/site-packages/libcamera\", which is \n> not in the python search path. However, even if I did drop the arch \n> part, it wouldn't be right for my PC as the python system search paths \n> don't contain \"site-packages\", but \"dist-packages\": \n> \"/usr/lib/python3.10/dist-packages\". Although there _is_ \"site-packages\" \n> in the path, but for the user specific pip path: \n> \"/home/tomba/.local/lib/python3.10/site-packages\"...\n\n\"dist-packages\" is Debian-specific. See [1] and [2].\n\n[1] https://wiki.debian.org/Python#Deviations_from_upstream\n[2] https://stackoverflow.com/questions/9387928/whats-the-difference-between-dist-packages-and-site-packages\n\nThe idea is to support coexistence of a Python interpreter installed\nfrom Debian packages, and the same version of the interpreter installed\nfrom source. The former would be installed in /usr and the latter in\n/usr/local, but they will both look in /usr/local/lib/python3.x/ to find\nsite packages installed from source. The Debian interpreter looks in the\ncustom dist-packages directory, and the one compiled from sources in the\nstandard site-packages directory. That way, packages compiled for one of\nthe interpreters won't conflict with packages compiled for the other. It\nseems a bit of a corner case.\n\nAnother data point: on my Gentoo machine, libcamera currently installs\nPython packages in /usr/lib64/python3.13/site-packages, while Python\nlooks for them in /usr/lib/python3.13/site-packages.\n\n> > picked up by default python which only looks in the non architecture\n> > specific libdir (eg /usr/local/lib/python3.11/). It also will always\n> > build using the system python, rather than building using the same\n> > python as meson is using. This prevents a user being able to build the\n> \n> Well... I don't know which one of those is better or worse =). And it's \n> not system python (if that means the build system), it's the target python.\n> \n> I don't think it's a good idea to always use the same python as meson is \n> using, and for cross-compiling that's totally wrong, of course. It \n> should be perfectly fine for meson to always use the normal system \n> python, while targeting some specific python version.\n> \n> In your version, shouldn't the import('python').find_installation() call \n> be configurable, so that the user would tell meson where to look for the \n> python installation? The docs say find_installation() can take e.g. a \n> path to the python.\n> \n> > bindings for a different version of python, without changing their\n> > system python to that version.\n> \n> How do you change the python version with your patch?\n\nThis can be done by specifying the Python interpreter in a meson native\nfile (the equivalent of a cross file for native builds).\n\n> > Modify the build process to use the meson Python module to build the\n> > python bindings targets, so it installs them to the correct directories\n> > for python, and builds them for the version of python that meson is\n> > running with. For cross-compiling, still use the previous method to\n> > build the bindings, as the host machine version of python should be\n> > used instead.\n> \n> To clarify, if using your version (i.e. the \"official\" meson version) \n> for finding python, the build goes totally bonkers as meson starts \n> mixing up the build system's and target's libraries. I think it was less \n> bonkers earlier, but now it looks to be totally broken (probably related \n> to a meson bug Laurent found recently).\n\nIt wasn't entirely clear to me if the meson python module is meant to\nsupport cross-compilation. I have asked on the #mesonbuild IRC channel,\nand the information I have received from meson developers is that the\npython module, and the python_installation object returned by\nfind_installation(), are meant to support compilation of Python\nextension modules, including both native and cross-compilation.\n\nThe meson python module, on the other hand, is *not* meant to access the\nPython interpreter of the build machine, even if the find_installation()\nmethod can return an object that refers to that interpreter. The reason\nis that the build machine Python interpreter, as run for instance from\nthe libcamera code generation scripts (\"#!/usr/bin/env python3\") does\nnot necessarily match the Python interpreter for which the libcamera\nPython bindings extension module is compiled, even in the case of native\ncompilation. Using find_installation() to check, for instance, the\nversion of a Python module used by Sphinx to build the documentation, is\nwrong. I have submitted two patches to remove incorrect usage of the\nmeson python module in libcamera.\n\nIn the text below I'll use \"build machine\" and \"host machine\" in the\nmeson sense, which translate to \"host machine\" and \"target machine\" for\nbuildroot.\n\nThe python_installation dependency() and extension_module() methods are\ninteresting. In a cross-compilation environment, dependency() tries to\nfind the Python libraries for the host machine, but searches for the\nexact same Python version as the Python interpreter returned by\nfind_installation(). By default, find_installation() on my machine finds\nthe build machine's native interpreter (v3.13), which doesn't match the\nPython version from my buildroot cross-compilation environment (v3.12).\nMeson fails to find the dependency().\n\nI think the expected way to handle this is for find_installation() to\nreturn the *build* machine interpreter from the *cross-compilation*\nenvironment, which will likely be the same version as the *host* machine\ninterpreter in the same cross-compilation environment. The meson\ndocumentation is very unclear about this though.\n\nGoing down this rabbit hole deeper, I've set\n\n[binaries]\npython = br_host_dir / 'bin/python3'\n\nin my cross file. Meson picked the build machine Python installation\nfrom buildroot (in the buildroot \"host\" directory). This caused issues\nwhen building the libcamera documentation, as the sphinxcontrib.doxylink\nmodule wasn't installed in my buildroot environment, which the patches I\nmentioened above fixed.\n\nWith that, py.dependency() found the Python dependency for the host, and\npy.extension_module() built the module correctly. py.install_sources()\nalso behaved nearly as expected.\n\nNearly :-(\n\nThere are two issue I've run into. One of them is specific to\ncross-compilation, the other one isn't. The first issue is related to\npy.extension_module(). The method selects the appropriate file extension\nfor the module, based on the Python interpreter configuration.\nUnfortunately, querying that configuration requires running Python code.\nWith the cross file pointing to a Python interpreter that has been\ncompiled for the build machine architecture, the result of the query\nwill be the suffix expected on the build machine, not on the host\nmachine. Cross-compiling from x86_64 to aarch64 on Gentoo, meson\nproduces an aarch64 binary named\n_libcamera.cpython-313-x86_64-linux-gnu.so.\n\nThis issue affects cross-compilation only. One workaround is to\nreference in the cross file a Python interpreter binary compiled for the\nhost machine and wrapper in qemu. Given how this would impact all the\nlibcamera users who cross-compile the project, I don't think it's a good\nidea.\n\nThe second issue is related to install paths. Those are\ninstallation-dependent and distribution-dependent, and here too querying\nthem involves running Python code (if anyone is curious, the information\ncomes from the Python sysconfig module, while population sys.path at\nruntime is done in the site module). Even for native compilation,\ndistribution-specific \"interesting\" behaviours (that some may call bugs)\nmakes this complex. Meson tries to wrap all the dirty code that queries\nfor those paths in a python_info.py helper script, to keep the rest of\nmeson clean. It seems to work when installing libcamera to a /usr\nprefix, but breaks for instance on Debian when installing to /usr/local.\n\nI've tested usage of py.extension_module() and py.install_sources() with\nnative compilation and the prefix set to /usr in the following\nenvironments:\n\n- Debian 11 (meson 1.2.0 from pip)\n\nInstalling src/py/libcamera/_libcamera.cpython-39-x86_64-linux-gnu.so to /usr/lib/python3/dist-packages/libcamera\nInstalling src/py/libcamera/__init__.py to /usr/lib/python3/dist-packages/libcamera\n\n- Debian 12 (meson 1.0.1)\n\nInstalling src/py/libcamera/_libcamera.cpython-311-x86_64-linux-gnu.so to /usr/lib/python3/dist-packages/libcamera\nInstalling src/py/libcamera/__init__.py to /usr/lib/python3/dist-packages/libcamera\n\n- Debian 13 (meson 1.7.0)\n\nInstalling src/py/libcamera/_libcamera.cpython-313-x86_64-linux-gnu.so to /usr/lib/python3/dist-packages/libcamera\nInstalling src/py/libcamera/__init__.py to /usr/lib/python3/dist-packages/libcamera\n\n- Gentoo (meson 1.7.2)\n\nInstalling src/py/libcamera/_libcamera.cpython-313-x86_64-linux-gnu.so to /usr/lib/python3.13/site-packages/libcamera\nInstalling src/py/libcamera/__init__.py to /usr/lib/python3.13/site-packages/libcamera\n\n\nThe libcamera module can be imported successfully by the Python\ninterpreter. This is a clear improvement over the currently situation.\n\nSetting the prefix to /usr/local gives \"interesting\" results on Debian.\nThe files are installed in /usr/local/lib/python3/dist-packages/ instead\nof /usr/lib/python3/dist-packages/, but while the Debian Python\ninterpreter is configured to look for system site packages in\n/usr/lib/python3/dist-packages/, it searches the local site packages in\n/usr/local/lib/python3.x/dist-packages/ (with x being the minor\nversion). I don't know why this is the case, but it prevents Python from\nfinding the libcamera module. This is not worse than the current\nbehaviour though, which is also broken.\n\nI believe that using the meson python module (py.extension_module() and\npy.install_sources()) for native compilation, as proposed in this patch,\nis a good solution. It should fix the installation path issue when the\nprefix is set to /usr, and won't cause a regression when the prefix is\nset to /usr/local. Furthermore, the module introduces two meson\nconfiguration options (python.platlibdir and python.purelibdir) that\nallow overriding the installation path, so this will give us a\nworkaround for installation in /usr/local, improving on the current\nsituation.\n\nFor cross-compilation, I think we should also switch to using the python\nmodule to get the dependency, as well as the installation path. This\nwill require pointing the cross file to the build machine Python\ninterpreter from the cross-compilation environment in some cases (manual\ncompilation of libcamera against a Buildroot or Yocto environment, when\nthe system Python version differs from the one used by Buildroot or\nYocto), but will provide the ability to fix incorrect installation paths\nthrough a meson configuration option.\n\nPEP 739 [3], and the work in progress [4] in meson to implement support\nfor it, will improve the situation and should fix the suffix issue in\nthe cross compilation case. Installation paths will require more work,\nespecially on Debian that uses very unconventional conventions, for both\nnative and cross compilation. It should be possible to work around that\nissue in meson itself without PEP 739 or any additional PEP.\n\n[3] https://peps.python.org/pep-0739/\n[4] https://github.com/mesonbuild/meson/pull/14657\n\n> In any case, this patch keeps the cross-compilation working for me, and \n> a native build on my PC works too. So it's ugly, but, afaics, works.\n> \n> You could add some comments to the meson.build file, to explain why all \n> this is being done.\n> \n> > Signed-off-by: William Vinnicombe <william.vinnicombe@raspberrypi.com>\n> > ---\n> >   src/py/libcamera/meson.build | 60 +++++++++++++++++++++++++++---------\n> >   1 file changed, 45 insertions(+), 15 deletions(-)\n> > \n> > diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build\n> > index f58c7198..128793aa 100644\n> > --- a/src/py/libcamera/meson.build\n> > +++ b/src/py/libcamera/meson.build\n> > @@ -1,10 +1,25 @@\n> >   # SPDX-License-Identifier: CC0-1.0\n> >   \n> > -py3_dep = dependency('python3', required : get_option('pycamera'))\n> > -\n> > -if not py3_dep.found()\n> > -    pycamera_enabled = false\n> > -    subdir_done()\n> > +if meson.is_cross_build()\n> > +    py3_dep = dependency('python3', required : get_option('pycamera'))\n> > +\n> > +    if not py3_dep.found()\n> > +        pycamera_enabled = false\n> > +        subdir_done()\n> > +    endif\n> > +else\n> > +    py = import('python').find_installation('python3', required : get_option('pycamera'))\n> > +\n> > +    if not py.found()\n> > +        pycamera_enabled = false\n> > +        subdir_done()\n> > +    else\n> > +        py3_dep = py.dependency(required : get_option('pycamera'))\n> > +        if not py3_dep.found()\n> > +            pycamera_enabled = false\n> > +            subdir_done()\n> > +        endif\n> > +    endif\n> >   endif\n\nThis can be simplified to\n\nif meson.is_cross_build()\n    py3_dep = dependency('python3', required : get_option('pycamera'))\nelse\n    py3 = import('python').find_installation('python3', required : get_option('pycamera'))\n    if not py3.found()\n        pycamera_enabled = false\n        subdir_done()\n    endif\n\n    py3_dep = py.dependency(required : get_option('pycamera'))\nendif\n\nif not py3_dep.found()\n    pycamera_enabled = false\n    subdir_done()\nendif\n\n> >   \n> >   pybind11_dep = dependency('pybind11', required : get_option('pycamera'))\n> > @@ -78,15 +93,24 @@ pycamera_args = [\n> >       '-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT',\n> >   ]\n> >   \n> > -destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera'\n> > -\n> > -pycamera = shared_module('_libcamera',\n> > -                         pycamera_sources,\n> > -                         install : true,\n> > -                         install_dir : destdir,\n> > -                         name_prefix : '',\n> > -                         dependencies : pycamera_deps,\n> > -                         cpp_args : pycamera_args)\n> > +if meson.is_cross_build()\n> > +    destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera'\n> > +\n> > +    pycamera = shared_module('_libcamera',\n> > +                             pycamera_sources,\n> > +                             install : true,\n> > +                             install_dir : destdir,\n> > +                             name_prefix : '',\n> > +                             dependencies : pycamera_deps,\n> > +                             cpp_args : pycamera_args)\n> > +else\n> > +    pycamera = py.extension_module('_libcamera',\n> > +                                   pycamera_sources,\n> > +                                   install : true,\n> > +                                   subdir : 'libcamera',\n> > +                                   dependencies : pycamera_deps,\n> > +                                   cpp_args : pycamera_args)\n> > +endif\n> >   \n> >   # Create symlinks from the build dir to the source dir so that we can use the\n> >   # Python module directly from the build dir.\n> > @@ -99,7 +123,13 @@ run_command('ln', '-fsrT', meson.current_source_dir() / 'utils',\n> >               meson.current_build_dir() / 'utils',\n> >               check : true)\n> >   \n> > -install_data(['__init__.py'], install_dir : destdir)\n> > +if meson.is_cross_build()\n> > +    install_data(['__init__.py'], install_dir : destdir)\n> > +else\n> > +    py.install_sources(['__init__.py'],\n> > +                       subdir : 'libcamera',\n> > +                       pure : false)\n> > +endif\n\nYou can merge this with the code above that also test for\nis_cross_build().\n\nI'll submit a v3 of this patch.\n\n> >   \n> >   # \\todo Generate stubs when building. See https://peps.python.org/pep-0484/#stub-files\n> >   # Note: Depends on pybind11-stubgen. To generate pylibcamera stubs:","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 0DAC5BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Aug 2025 01:11:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E8B91613C5;\n\tTue, 19 Aug 2025 03:11:01 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 11F75613C5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Aug 2025 03:11:00 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 5203BC6D;\n\tTue, 19 Aug 2025 03:10:02 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"XVCDKOBd\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755565802;\n\tbh=tdBQ4iJS4AFzU+GAsBx6bEoogxZZZ+MOOdXNyIVMyVo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=XVCDKOBdYXRmjEExECmHme8gEAE7Z2pCxT4z/Lx79UcSzEZfckkah9b9GtuBShASV\n\tRO9J85vmyeX9Y5rsHEVmWlPMGRTNnf02Jgn0f2K5fKwvLnYV9urbZQy1KbO+MZlcxT\n\t32B8kbsCFjyvz9rJuFV/7GvcF8tZLo2Ez8bkhroQ=","Date":"Tue, 19 Aug 2025 04:10:37 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Cc":"William Vinnicombe <william.vinnicombe@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [libcamera-devel] [PATCH v2] py: libcamera: Improve python\n\tbinding installation","Message-ID":"<20250819011037.GG5862@pendragon.ideasonboard.com>","References":"<20231026125038.27985-1-william.vinnicombe@raspberrypi.com>\n\t<ab0211a8-17a2-4060-b30e-32cd835a9df4@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<ab0211a8-17a2-4060-b30e-32cd835a9df4@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":35524,"web_url":"https://patchwork.libcamera.org/comment/35524/","msgid":"<2c5b3f6f-8d6c-4cfd-83ad-0fd45268e3f9@ideasonboard.com>","date":"2025-08-20T09:41:43","subject":"Re: [libcamera-devel] [PATCH v2] py: libcamera: Improve python\n\tbinding installation","submitter":{"id":109,"url":"https://patchwork.libcamera.org/api/people/109/","name":"Tomi Valkeinen","email":"tomi.valkeinen@ideasonboard.com"},"content":"Hi,\n\nOn 19/08/2025 04:10, Laurent Pinchart wrote:\n> Hello,\n> \n> Reviving this old thread after a weekend of rabbit hole exploration.\n> \n> On Thu, Nov 23, 2023 at 05:26:05PM +0200, 📷-dev wrote:\n>> On 26/10/2023 15:50, William Vinnicombe via libcamera-devel wrote:\n>>> The existing meson.build file installs the bindings to an architecture\n>>> specific libdir (eg /usr/local/lib/aarch64-linux-gnu/), which is not\n>>\n>> For me, in buildroot, it would be \"/usr/lib/python3.11/site-packages\", \n>> so no arch part. On my PC, though, I get \n>> \"/usr/lib/x86_64-linux-gnu/python3.10/site-packages/libcamera\", which is \n>> not in the python search path. However, even if I did drop the arch \n>> part, it wouldn't be right for my PC as the python system search paths \n>> don't contain \"site-packages\", but \"dist-packages\": \n>> \"/usr/lib/python3.10/dist-packages\". Although there _is_ \"site-packages\" \n>> in the path, but for the user specific pip path: \n>> \"/home/tomba/.local/lib/python3.10/site-packages\"...\n> \n> \"dist-packages\" is Debian-specific. See [1] and [2].\n> \n> [1] https://wiki.debian.org/Python#Deviations_from_upstream\n> [2] https://stackoverflow.com/questions/9387928/whats-the-difference-between-dist-packages-and-site-packages\n> \n> The idea is to support coexistence of a Python interpreter installed\n> from Debian packages, and the same version of the interpreter installed\n> from source. The former would be installed in /usr and the latter in\n> /usr/local, but they will both look in /usr/local/lib/python3.x/ to find\n> site packages installed from source. The Debian interpreter looks in the\n> custom dist-packages directory, and the one compiled from sources in the\n> standard site-packages directory. That way, packages compiled for one of\n> the interpreters won't conflict with packages compiled for the other. It\n> seems a bit of a corner case.\n> \n> Another data point: on my Gentoo machine, libcamera currently installs\n> Python packages in /usr/lib64/python3.13/site-packages, while Python\n> looks for them in /usr/lib/python3.13/site-packages.\n> \n>>> picked up by default python which only looks in the non architecture\n>>> specific libdir (eg /usr/local/lib/python3.11/). It also will always\n>>> build using the system python, rather than building using the same\n>>> python as meson is using. This prevents a user being able to build the\n>>\n>> Well... I don't know which one of those is better or worse =). And it's \n>> not system python (if that means the build system), it's the target python.\n>>\n>> I don't think it's a good idea to always use the same python as meson is \n>> using, and for cross-compiling that's totally wrong, of course. It \n>> should be perfectly fine for meson to always use the normal system \n>> python, while targeting some specific python version.\n>>\n>> In your version, shouldn't the import('python').find_installation() call \n>> be configurable, so that the user would tell meson where to look for the \n>> python installation? The docs say find_installation() can take e.g. a \n>> path to the python.\n>>\n>>> bindings for a different version of python, without changing their\n>>> system python to that version.\n>>\n>> How do you change the python version with your patch?\n> \n> This can be done by specifying the Python interpreter in a meson native\n> file (the equivalent of a cross file for native builds).\n> \n>>> Modify the build process to use the meson Python module to build the\n>>> python bindings targets, so it installs them to the correct directories\n>>> for python, and builds them for the version of python that meson is\n>>> running with. For cross-compiling, still use the previous method to\n>>> build the bindings, as the host machine version of python should be\n>>> used instead.\n>>\n>> To clarify, if using your version (i.e. the \"official\" meson version) \n>> for finding python, the build goes totally bonkers as meson starts \n>> mixing up the build system's and target's libraries. I think it was less \n>> bonkers earlier, but now it looks to be totally broken (probably related \n>> to a meson bug Laurent found recently).\n> \n> It wasn't entirely clear to me if the meson python module is meant to\n> support cross-compilation. I have asked on the #mesonbuild IRC channel,\n> and the information I have received from meson developers is that the\n> python module, and the python_installation object returned by\n> find_installation(), are meant to support compilation of Python\n> extension modules, including both native and cross-compilation.\n> \n> The meson python module, on the other hand, is *not* meant to access the\n> Python interpreter of the build machine, even if the find_installation()\n> method can return an object that refers to that interpreter. The reason\n> is that the build machine Python interpreter, as run for instance from\n> the libcamera code generation scripts (\"#!/usr/bin/env python3\") does\n> not necessarily match the Python interpreter for which the libcamera\n> Python bindings extension module is compiled, even in the case of native\n> compilation. Using find_installation() to check, for instance, the\n> version of a Python module used by Sphinx to build the documentation, is\n> wrong. I have submitted two patches to remove incorrect usage of the\n> meson python module in libcamera.\n> \n> In the text below I'll use \"build machine\" and \"host machine\" in the\n> meson sense, which translate to \"host machine\" and \"target machine\" for\n> buildroot.\n> \n> The python_installation dependency() and extension_module() methods are\n> interesting. In a cross-compilation environment, dependency() tries to\n> find the Python libraries for the host machine, but searches for the\n> exact same Python version as the Python interpreter returned by\n> find_installation(). By default, find_installation() on my machine finds\n> the build machine's native interpreter (v3.13), which doesn't match the\n> Python version from my buildroot cross-compilation environment (v3.12).\n> Meson fails to find the dependency().\n> \n> I think the expected way to handle this is for find_installation() to\n> return the *build* machine interpreter from the *cross-compilation*\n> environment, which will likely be the same version as the *host* machine\n> interpreter in the same cross-compilation environment. The meson\n> documentation is very unclear about this though.\n> \n> Going down this rabbit hole deeper, I've set\n\nSigh, now I'm there too... I'm trying to collect my thoughts here, but I\nguess it's mostly reiterating what you've already covered in your emails.\n\nSo, if my understanding about \"py3 =\nimport('python').find_installation('python3')\" is right, based on what\nyou've written and what I have been testing, py3 here is kind of a mess.\nIt points to a build arch Python interpreter, but the dependencies you\nget from it are for the target machine. You can run the interpreter on\nthe build machine, but if you build an extension module for it, you get\nsomething you can't run on the build machine.\n\nWell, it kind of matches what a compiler is, I guess. But I think this\nis the key: py3 should only be used when dealing with target. Never if\nyou want to run python to, e.g. process some source code. This is what\nyou fixed in the two patches you sent.\n\nAnd, as meson's python module is broken for cross-compiling, we can't\nuse it as such for cross-compiling. You make that a bit better with the\nhacks in your 3 patch series.\n\n Tomi","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 22FD9BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 20 Aug 2025 09:41:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DD257692D7;\n\tWed, 20 Aug 2025 11:41:48 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 793FD613C5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Aug 2025 11:41:46 +0200 (CEST)","from [192.168.88.20] (91-158-153-178.elisa-laajakaista.fi\n\t[91.158.153.178])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id ABABF606;\n\tWed, 20 Aug 2025 11:40:47 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"whcM4bkn\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755682847;\n\tbh=7cb2dM5l8Zb7UJevIzv8FQpF2NXzyGNuiMtKNem9cV0=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=whcM4bknFUdKk/05czkkOLow605zjzq70mSy1GVnAga/pl2JrWgIT2cZlp5A6STyH\n\tqzLRrPy+xVL59A9DUbgBZbBd6pQZ63JW9DwwZF+9DS09WBQQBRPfV9EZqL5MMsdOjM\n\tlFCzFmEyVL+2IB3cTZsNtnk37bubCMMQl2nIFBLs=","Message-ID":"<2c5b3f6f-8d6c-4cfd-83ad-0fd45268e3f9@ideasonboard.com>","Date":"Wed, 20 Aug 2025 12:41:43 +0300","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [libcamera-devel] [PATCH v2] py: libcamera: Improve python\n\tbinding installation","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"William Vinnicombe <william.vinnicombe@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20231026125038.27985-1-william.vinnicombe@raspberrypi.com>\n\t<ab0211a8-17a2-4060-b30e-32cd835a9df4@ideasonboard.com>\n\t<20250819011037.GG5862@pendragon.ideasonboard.com>","Content-Language":"en-US","From":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Autocrypt":"addr=tomi.valkeinen@ideasonboard.com; keydata=\n\txsFNBE6ms0cBEACyizowecZqXfMZtnBniOieTuFdErHAUyxVgtmr0f5ZfIi9Z4l+uUN4Zdw2\n\twCEZjx3o0Z34diXBaMRJ3rAk9yB90UJAnLtb8A97Oq64DskLF81GCYB2P1i0qrG7UjpASgCA\n\tRu0lVvxsWyIwSfoYoLrazbT1wkWRs8YBkkXQFfL7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DESH\n\tmvQcsFS7d3eGVI6eyjCFdcAO8eMAEQEAAcLBXwQYAQIACQUCTqazRwIbDAAKCRD6PaqMvJYe\n\t9fA7EACS6exUedsBKmt4pT7nqXBcRsqm6YzT6DeCM8PWMTeaVGHiR4TnNFiT3otD5UpYQI7S\n\tsuYxoTdHrrrBzdlKe5rUWpzoZkVK6p0s9OIvGzLT0lrb0HC9iNDWT3JgpYDnk4Z2mFi6tTbq\n\txKMtpVFRA6FjviGDRsfkfoURZI51nf2RSAk/A8BEDDZ7lgJHskYoklSpwyrXhkp9FHGMaYII\n\tm9EKuUTX9JPDG2FTthCBrdsgWYPdJQvM+zscq09vFMQ9Fykbx5N8z/oFEUy3ACyPqW2oyfvU\n\tCH5WDpWBG0s5BALp1gBJPytIAd/pY/5ZdNoi0Cx3+Z7jaBFEyYJdWy1hGddpkgnMjyOfLI7B\n\tCFrdecTZbR5upjNSDvQ7RG85SnpYJTIin+SAUazAeA2nS6gTZzumgtdw8XmVXZwdBfF+ICof\n\t92UkbYcYNbzWO/GHgsNT1WnM4sa9lwCSWH8Fw1o/3bX1VVPEsnESOfxkNdu+gAF5S6+I6n3a\n\tueeIlwJl5CpT5l8RpoZXEOVtXYn8zzOJ7oGZYINRV9Pf8qKGLf3Dft7zKBP832I3PQjeok7F\n\tyjt+9S+KgSFSHP3Pa4E7lsSdWhSlHYNdG/czhoUkSCN09C0rEK93wxACx3vtxPLjXu6RptBw\n\t3dRq7n+mQChEB1am0BueV1JZaBboIL0AGlSJkm23kw==","In-Reply-To":"<20250819011037.GG5862@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":35526,"web_url":"https://patchwork.libcamera.org/comment/35526/","msgid":"<20250820095126.GE10308@pendragon.ideasonboard.com>","date":"2025-08-20T09:51:26","subject":"Re: [libcamera-devel] [PATCH v2] py: libcamera: Improve python\n\tbinding installation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Aug 20, 2025 at 12:41:43PM +0300, Tomi Valkeinen wrote:\n> Hi,\n> \n> On 19/08/2025 04:10, Laurent Pinchart wrote:\n> > Hello,\n> > \n> > Reviving this old thread after a weekend of rabbit hole exploration.\n> > \n> > On Thu, Nov 23, 2023 at 05:26:05PM +0200, 📷-dev wrote:\n> >> On 26/10/2023 15:50, William Vinnicombe via libcamera-devel wrote:\n> >>> The existing meson.build file installs the bindings to an architecture\n> >>> specific libdir (eg /usr/local/lib/aarch64-linux-gnu/), which is not\n> >>\n> >> For me, in buildroot, it would be \"/usr/lib/python3.11/site-packages\", \n> >> so no arch part. On my PC, though, I get \n> >> \"/usr/lib/x86_64-linux-gnu/python3.10/site-packages/libcamera\", which is \n> >> not in the python search path. However, even if I did drop the arch \n> >> part, it wouldn't be right for my PC as the python system search paths \n> >> don't contain \"site-packages\", but \"dist-packages\": \n> >> \"/usr/lib/python3.10/dist-packages\". Although there _is_ \"site-packages\" \n> >> in the path, but for the user specific pip path: \n> >> \"/home/tomba/.local/lib/python3.10/site-packages\"...\n> > \n> > \"dist-packages\" is Debian-specific. See [1] and [2].\n> > \n> > [1] https://wiki.debian.org/Python#Deviations_from_upstream\n> > [2] https://stackoverflow.com/questions/9387928/whats-the-difference-between-dist-packages-and-site-packages\n> > \n> > The idea is to support coexistence of a Python interpreter installed\n> > from Debian packages, and the same version of the interpreter installed\n> > from source. The former would be installed in /usr and the latter in\n> > /usr/local, but they will both look in /usr/local/lib/python3.x/ to find\n> > site packages installed from source. The Debian interpreter looks in the\n> > custom dist-packages directory, and the one compiled from sources in the\n> > standard site-packages directory. That way, packages compiled for one of\n> > the interpreters won't conflict with packages compiled for the other. It\n> > seems a bit of a corner case.\n> > \n> > Another data point: on my Gentoo machine, libcamera currently installs\n> > Python packages in /usr/lib64/python3.13/site-packages, while Python\n> > looks for them in /usr/lib/python3.13/site-packages.\n> > \n> >>> picked up by default python which only looks in the non architecture\n> >>> specific libdir (eg /usr/local/lib/python3.11/). It also will always\n> >>> build using the system python, rather than building using the same\n> >>> python as meson is using. This prevents a user being able to build the\n> >>\n> >> Well... I don't know which one of those is better or worse =). And it's \n> >> not system python (if that means the build system), it's the target python.\n> >>\n> >> I don't think it's a good idea to always use the same python as meson is \n> >> using, and for cross-compiling that's totally wrong, of course. It \n> >> should be perfectly fine for meson to always use the normal system \n> >> python, while targeting some specific python version.\n> >>\n> >> In your version, shouldn't the import('python').find_installation() call \n> >> be configurable, so that the user would tell meson where to look for the \n> >> python installation? The docs say find_installation() can take e.g. a \n> >> path to the python.\n> >>\n> >>> bindings for a different version of python, without changing their\n> >>> system python to that version.\n> >>\n> >> How do you change the python version with your patch?\n> > \n> > This can be done by specifying the Python interpreter in a meson native\n> > file (the equivalent of a cross file for native builds).\n> > \n> >>> Modify the build process to use the meson Python module to build the\n> >>> python bindings targets, so it installs them to the correct directories\n> >>> for python, and builds them for the version of python that meson is\n> >>> running with. For cross-compiling, still use the previous method to\n> >>> build the bindings, as the host machine version of python should be\n> >>> used instead.\n> >>\n> >> To clarify, if using your version (i.e. the \"official\" meson version) \n> >> for finding python, the build goes totally bonkers as meson starts \n> >> mixing up the build system's and target's libraries. I think it was less \n> >> bonkers earlier, but now it looks to be totally broken (probably related \n> >> to a meson bug Laurent found recently).\n> > \n> > It wasn't entirely clear to me if the meson python module is meant to\n> > support cross-compilation. I have asked on the #mesonbuild IRC channel,\n> > and the information I have received from meson developers is that the\n> > python module, and the python_installation object returned by\n> > find_installation(), are meant to support compilation of Python\n> > extension modules, including both native and cross-compilation.\n> > \n> > The meson python module, on the other hand, is *not* meant to access the\n> > Python interpreter of the build machine, even if the find_installation()\n> > method can return an object that refers to that interpreter. The reason\n> > is that the build machine Python interpreter, as run for instance from\n> > the libcamera code generation scripts (\"#!/usr/bin/env python3\") does\n> > not necessarily match the Python interpreter for which the libcamera\n> > Python bindings extension module is compiled, even in the case of native\n> > compilation. Using find_installation() to check, for instance, the\n> > version of a Python module used by Sphinx to build the documentation, is\n> > wrong. I have submitted two patches to remove incorrect usage of the\n> > meson python module in libcamera.\n> > \n> > In the text below I'll use \"build machine\" and \"host machine\" in the\n> > meson sense, which translate to \"host machine\" and \"target machine\" for\n> > buildroot.\n> > \n> > The python_installation dependency() and extension_module() methods are\n> > interesting. In a cross-compilation environment, dependency() tries to\n> > find the Python libraries for the host machine, but searches for the\n> > exact same Python version as the Python interpreter returned by\n> > find_installation(). By default, find_installation() on my machine finds\n> > the build machine's native interpreter (v3.13), which doesn't match the\n> > Python version from my buildroot cross-compilation environment (v3.12).\n> > Meson fails to find the dependency().\n> > \n> > I think the expected way to handle this is for find_installation() to\n> > return the *build* machine interpreter from the *cross-compilation*\n> > environment, which will likely be the same version as the *host* machine\n> > interpreter in the same cross-compilation environment. The meson\n> > documentation is very unclear about this though.\n> > \n> > Going down this rabbit hole deeper, I've set\n> \n> Sigh, now I'm there too... I'm trying to collect my thoughts here, but I\n> guess it's mostly reiterating what you've already covered in your emails.\n> \n> So, if my understanding about \"py3 =\n> import('python').find_installation('python3')\" is right, based on what\n> you've written and what I have been testing, py3 here is kind of a mess.\n> It points to a build arch Python interpreter, but the dependencies you\n> get from it are for the target machine. You can run the interpreter on\n> the build machine, but if you build an extension module for it, you get\n> something you can't run on the build machine.\n> \n> Well, it kind of matches what a compiler is, I guess. But I think this\n> is the key: py3 should only be used when dealing with target. Never if\n> you want to run python to, e.g. process some source code. This is what\n> you fixed in the two patches you sent.\n> \n> And, as meson's python module is broken for cross-compiling, we can't\n> use it as such for cross-compiling. You make that a bit better with the\n> hacks in your 3 patch series.\n\nI'll take the \"a bit better\" as a big compliment in Python context :-)\n\nI think py.extension_module() is still the way to go for\ncross-compilation, but that will need to wait until PEP 739 support\nlands (and we'll have to continue using shared_module() until we stop\nsupporting pre-PEP 739 versions of Python and meson). The patches I've\nsent go in that direction, so I'm relatively confident we're getting to\na better state.","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9F796BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 20 Aug 2025 09:51:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5352F692DC;\n\tWed, 20 Aug 2025 11:51:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DA29D613C5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 20 Aug 2025 11:51:48 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 58CA6EFE;\n\tWed, 20 Aug 2025 11:50:50 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Z7OkTNWX\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755683450;\n\tbh=4ezpjp9FMMCJYn7akzhFmLimu4Bg6viCMUbAZ9aTm8s=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Z7OkTNWXN4L7SqG1S1GMx+sb+OouFRkkeo1jYWDJnfetLhXCZWgtaYaC+baSmc3vb\n\tcYr0VFKP0JNBpCpx5ZIkMmCKxljkHnIANQ9mGtaHr/RNnrKBshkY7nmZXg8DCl9/P7\n\tFQwCPsxXmb4kZHd4WVqSxyhCcy3u2SvDdhOrS1Ok=","Date":"Wed, 20 Aug 2025 12:51:26 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Cc":"William Vinnicombe <william.vinnicombe@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [libcamera-devel] [PATCH v2] py: libcamera: Improve python\n\tbinding installation","Message-ID":"<20250820095126.GE10308@pendragon.ideasonboard.com>","References":"<20231026125038.27985-1-william.vinnicombe@raspberrypi.com>\n\t<ab0211a8-17a2-4060-b30e-32cd835a9df4@ideasonboard.com>\n\t<20250819011037.GG5862@pendragon.ideasonboard.com>\n\t<2c5b3f6f-8d6c-4cfd-83ad-0fd45268e3f9@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<2c5b3f6f-8d6c-4cfd-83ad-0fd45268e3f9@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]