[1/2] Documentation: Use python3 directly to check for doxylink version
diff mbox series

Message ID 20250818121103.20073-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit ac09782a17603c828e202edf04b60548e2ab0371
Headers show
Series
  • [1/2] Documentation: Use python3 directly to check for doxylink version
Related show

Commit Message

Laurent Pinchart Aug. 18, 2025, 12:11 p.m. UTC
When checking the version of the sphinxcontrib.doxylink module, the
Python interpreter used by Sphinx must be used, as that's where the
module will be imported from. Using the meson python_installation object
for this purpose is incorrect, as it's meant to access the Python
installation of the host machine, not the native Python interpreter on
the host machine. Fix this by using python3 directly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 Documentation/meson.build | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)


base-commit: af43c2f945c42cc7d111de63abed9ca3df830ca4
--
Regards,

Laurent Pinchart

Comments

Tomi Valkeinen Aug. 19, 2025, 8:01 a.m. UTC | #1
Hi,

On 18/08/2025 15:11, Laurent Pinchart wrote:
> When checking the version of the sphinxcontrib.doxylink module, the
> Python interpreter used by Sphinx must be used, as that's where the
> module will be imported from. Using the meson python_installation object
> for this purpose is incorrect, as it's meant to access the Python
> installation of the host machine, not the native Python interpreter on
> the host machine. Fix this by using python3 directly.

Can you give an example here? I'm not sure I understand "Python
installation of the host machine" vs "Python interpreter on the host
machine".

 Tomi

> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  Documentation/meson.build | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/Documentation/meson.build b/Documentation/meson.build
> index b898ba3a0b7e..163875014eec 100644
> --- a/Documentation/meson.build
> +++ b/Documentation/meson.build
> @@ -124,12 +124,9 @@ if sphinx.found()
>      # Many distributions do not provide a recent-enough version of the doxylink
>      # module. This results in a build error with a cryptic message. Check the
>      # version manually and print clear error messages.
> -    py_mod = import('python')
> -    py3 = py_mod.find_installation('python3')
> -
>      mod = 'sphinxcontrib.doxylink'
>      min_version = '>=1.6.1'
> -    version = run_command(py3, '-c',
> +    version = run_command('python3', '-c',
>                            'import @0@ ; print(@0@.__version__)'.format(mod),
>                            check : false).stdout().strip()
> 
> 
> base-commit: af43c2f945c42cc7d111de63abed9ca3df830ca4
> --
> Regards,
> 
> Laurent Pinchart
>
Laurent Pinchart Aug. 19, 2025, 8:32 a.m. UTC | #2
Hi Tomi,

On Tue, Aug 19, 2025 at 11:01:18AM +0300, Tomi Valkeinen wrote:
> On 18/08/2025 15:11, Laurent Pinchart wrote:
> > When checking the version of the sphinxcontrib.doxylink module, the
> > Python interpreter used by Sphinx must be used, as that's where the
> > module will be imported from. Using the meson python_installation object
> > for this purpose is incorrect, as it's meant to access the Python
> > installation of the host machine, not the native Python interpreter on
> > the host machine. Fix this by using python3 directly.
> 
> Can you give an example here? I'm not sure I understand "Python
> installation of the host machine" vs "Python interpreter on the host
> machine".

Oops, the second "host" should be "build".

I'll rewrite the commit message as

----------
When checking the version of the sphinxcontrib.doxylink module, the
Python interpreter used by Sphinx must be used, as that's where the
module will be imported from. Using the meson python_installation object
for this purpose is incorrect, as it's meant to access the Python
installation of the host machine, not the system Python interpreter on
the build machine.

For instance, when cross-compiling libcamera against a Buildroot
environment, and pointing meson in the cross-file to the build machine
Python interpreter from Buildroot, the meson python module will refer to
the latter, while Sphinx will use the former.

Fix this by using python3 directly.
----------

> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  Documentation/meson.build | 5 +----
> >  1 file changed, 1 insertion(+), 4 deletions(-)
> > 
> > diff --git a/Documentation/meson.build b/Documentation/meson.build
> > index b898ba3a0b7e..163875014eec 100644
> > --- a/Documentation/meson.build
> > +++ b/Documentation/meson.build
> > @@ -124,12 +124,9 @@ if sphinx.found()
> >      # Many distributions do not provide a recent-enough version of the doxylink
> >      # module. This results in a build error with a cryptic message. Check the
> >      # version manually and print clear error messages.
> > -    py_mod = import('python')
> > -    py3 = py_mod.find_installation('python3')
> > -
> >      mod = 'sphinxcontrib.doxylink'
> >      min_version = '>=1.6.1'
> > -    version = run_command(py3, '-c',
> > +    version = run_command('python3', '-c',
> >                            'import @0@ ; print(@0@.__version__)'.format(mod),
> >                            check : false).stdout().strip()
> > 
> > 
> > base-commit: af43c2f945c42cc7d111de63abed9ca3df830ca4
Barnabás Pőcze Aug. 19, 2025, 10:01 a.m. UTC | #3
Hi

2025. 08. 18. 14:11 keltezéssel, Laurent Pinchart írta:
> When checking the version of the sphinxcontrib.doxylink module, the
> Python interpreter used by Sphinx must be used, as that's where the
> module will be imported from. Using the meson python_installation object
> for this purpose is incorrect, as it's meant to access the Python
> installation of the host machine, not the native Python interpreter on
> the host machine. Fix this by using python3 directly.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>   Documentation/meson.build | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/Documentation/meson.build b/Documentation/meson.build
> index b898ba3a0b7e..163875014eec 100644
> --- a/Documentation/meson.build
> +++ b/Documentation/meson.build
> @@ -124,12 +124,9 @@ if sphinx.found()
>       # Many distributions do not provide a recent-enough version of the doxylink
>       # module. This results in a build error with a cryptic message. Check the
>       # version manually and print clear error messages.
> -    py_mod = import('python')
> -    py3 = py_mod.find_installation('python3')
> -
>       mod = 'sphinxcontrib.doxylink'
>       min_version = '>=1.6.1'
> -    version = run_command(py3, '-c',
> +    version = run_command('python3', '-c',

Should this not use `find_program(nature: true)`? (Or does it already implicitly?)

I feel like that we should maybe use `find_program()` to find a python interpreter,
and use that everywhere a native python executable is needed? And for example invoke
sphinx as follows:

   py3 = find_program(...)
   [py3, '-m', 'sphinx', ...]

Or am I missing something?


Regards,
Barnabás Pőcze

>                             'import @0@ ; print(@0@.__version__)'.format(mod),
>                             check : false).stdout().strip()
> 
> 
> base-commit: af43c2f945c42cc7d111de63abed9ca3df830ca4
> --
> Regards,
> 
> Laurent Pinchart
>
Laurent Pinchart Aug. 19, 2025, 10:57 a.m. UTC | #4
On Tue, Aug 19, 2025 at 12:01:22PM +0200, Barnabás Pőcze wrote:
> 2025. 08. 18. 14:11 keltezéssel, Laurent Pinchart írta:
> > When checking the version of the sphinxcontrib.doxylink module, the
> > Python interpreter used by Sphinx must be used, as that's where the
> > module will be imported from. Using the meson python_installation object
> > for this purpose is incorrect, as it's meant to access the Python
> > installation of the host machine, not the native Python interpreter on
> > the host machine. Fix this by using python3 directly.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >   Documentation/meson.build | 5 +----
> >   1 file changed, 1 insertion(+), 4 deletions(-)
> > 
> > diff --git a/Documentation/meson.build b/Documentation/meson.build
> > index b898ba3a0b7e..163875014eec 100644
> > --- a/Documentation/meson.build
> > +++ b/Documentation/meson.build
> > @@ -124,12 +124,9 @@ if sphinx.found()
> >       # Many distributions do not provide a recent-enough version of the doxylink
> >       # module. This results in a build error with a cryptic message. Check the
> >       # version manually and print clear error messages.
> > -    py_mod = import('python')
> > -    py3 = py_mod.find_installation('python3')
> > -
> >       mod = 'sphinxcontrib.doxylink'
> >       min_version = '>=1.6.1'
> > -    version = run_command(py3, '-c',
> > +    version = run_command('python3', '-c',
> 
> Should this not use `find_program(nature: true)`? (Or does it already implicitly?)

When run_command() receives a string, it wraps them in an
ExternalProgram() instance, which is also what find_program() gives.
find_program() gives more control and supports features such as wraps.

When cross-compiling libcamera with a cross-file that specifies a Python
interpreter binary from buildroot, meson prints the following to its log
for the about run_command('python3', ...) call:

Running command: /usr/bin/python3 -c 'import sphinxcontrib.doxylink ; print(sphinxcontrib.doxylink.__version__)'

It seems we're fine.

> I feel like that we should maybe use `find_program()` to find a python interpreter,
> and use that everywhere a native python executable is needed? And for example invoke
> sphinx as follows:
> 
>    py3 = find_program(...)
>    [py3, '-m', 'sphinx', ...]

Possibly, but that may be a bit overkill. I'm tempted to leave it as-is
for now as nothing seems broken.

> Or am I missing something?
> 
> >                             'import @0@ ; print(@0@.__version__)'.format(mod),
> >                             check : false).stdout().strip()
> > 
> > 
> > base-commit: af43c2f945c42cc7d111de63abed9ca3df830ca4
Pőcze Barnabás Aug. 19, 2025, 11:39 a.m. UTC | #5
2025. 08. 19. 12:57 keltezéssel, Laurent Pinchart írta:
> On Tue, Aug 19, 2025 at 12:01:22PM +0200, Barnabás Pőcze wrote:
>> 2025. 08. 18. 14:11 keltezéssel, Laurent Pinchart írta:
>>> When checking the version of the sphinxcontrib.doxylink module, the
>>> Python interpreter used by Sphinx must be used, as that's where the
>>> module will be imported from. Using the meson python_installation object
>>> for this purpose is incorrect, as it's meant to access the Python
>>> installation of the host machine, not the native Python interpreter on
>>> the host machine. Fix this by using python3 directly.
>>>
>>> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>> ---
>>>    Documentation/meson.build | 5 +----
>>>    1 file changed, 1 insertion(+), 4 deletions(-)
>>>
>>> diff --git a/Documentation/meson.build b/Documentation/meson.build
>>> index b898ba3a0b7e..163875014eec 100644
>>> --- a/Documentation/meson.build
>>> +++ b/Documentation/meson.build
>>> @@ -124,12 +124,9 @@ if sphinx.found()
>>>        # Many distributions do not provide a recent-enough version of the doxylink
>>>        # module. This results in a build error with a cryptic message. Check the
>>>        # version manually and print clear error messages.
>>> -    py_mod = import('python')
>>> -    py3 = py_mod.find_installation('python3')
>>> -
>>>        mod = 'sphinxcontrib.doxylink'
>>>        min_version = '>=1.6.1'
>>> -    version = run_command(py3, '-c',
>>> +    version = run_command('python3', '-c',
>>
>> Should this not use `find_program(nature: true)`? (Or does it already implicitly?)
> 
> When run_command() receives a string, it wraps them in an
> ExternalProgram() instance, which is also what find_program() gives.
> find_program() gives more control and supports features such as wraps.
> 
> When cross-compiling libcamera with a cross-file that specifies a Python
> interpreter binary from buildroot, meson prints the following to its log
> for the about run_command('python3', ...) call:
> 
> Running command: /usr/bin/python3 -c 'import sphinxcontrib.doxylink ; print(sphinxcontrib.doxylink.__version__)'
> 
> It seems we're fine.

As far as I am aware program overrides in cross/native files won't take effect
in this case (not using `find_program()`), no? Although I suppose overriding python
might be incompatible with other parts using the python module?


> 
>> I feel like that we should maybe use `find_program()` to find a python interpreter,
>> and use that everywhere a native python executable is needed? And for example invoke
>> sphinx as follows:
>>
>>     py3 = find_program(...)
>>     [py3, '-m', 'sphinx', ...]
> 
> Possibly, but that may be a bit overkill. I'm tempted to leave it as-is
> for now as nothing seems broken.
> 
>> Or am I missing something?
>>
>>>                              'import @0@ ; print(@0@.__version__)'.format(mod),
>>>                              check : false).stdout().strip()
>>>
>>>
>>> base-commit: af43c2f945c42cc7d111de63abed9ca3df830ca4
> 
> --
> Regards,
> 
> Laurent Pinchart
Barnabás Pőcze Aug. 19, 2025, 11:43 a.m. UTC | #6
2025. 08. 19. 12:57 keltezéssel, Laurent Pinchart írta:
> On Tue, Aug 19, 2025 at 12:01:22PM +0200, Barnabás Pőcze wrote:
>> 2025. 08. 18. 14:11 keltezéssel, Laurent Pinchart írta:
>>> When checking the version of the sphinxcontrib.doxylink module, the
>>> Python interpreter used by Sphinx must be used, as that's where the
>>> module will be imported from. Using the meson python_installation object
>>> for this purpose is incorrect, as it's meant to access the Python
>>> installation of the host machine, not the native Python interpreter on
>>> the host machine. Fix this by using python3 directly.
>>>
>>> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>> ---
>>>    Documentation/meson.build | 5 +----
>>>    1 file changed, 1 insertion(+), 4 deletions(-)
>>>
>>> diff --git a/Documentation/meson.build b/Documentation/meson.build
>>> index b898ba3a0b7e..163875014eec 100644
>>> --- a/Documentation/meson.build
>>> +++ b/Documentation/meson.build
>>> @@ -124,12 +124,9 @@ if sphinx.found()
>>>        # Many distributions do not provide a recent-enough version of the doxylink
>>>        # module. This results in a build error with a cryptic message. Check the
>>>        # version manually and print clear error messages.
>>> -    py_mod = import('python')
>>> -    py3 = py_mod.find_installation('python3')
>>> -
>>>        mod = 'sphinxcontrib.doxylink'
>>>        min_version = '>=1.6.1'
>>> -    version = run_command(py3, '-c',
>>> +    version = run_command('python3', '-c',
>>
>> Should this not use `find_program(nature: true)`? (Or does it already implicitly?)
> 
> When run_command() receives a string, it wraps them in an
> ExternalProgram() instance, which is also what find_program() gives.
> find_program() gives more control and supports features such as wraps.
> 
> When cross-compiling libcamera with a cross-file that specifies a Python
> interpreter binary from buildroot, meson prints the following to its log
> for the about run_command('python3', ...) call:
> 
> Running command: /usr/bin/python3 -c 'import sphinxcontrib.doxylink ; print(sphinxcontrib.doxylink.__version__)'
> 

As far as I am aware program overrides in cross/native files won't take effect
in this case (not using `find_program()`), no? Although I suppose overriding python
might be incompatible with other parts using the python module?


> It seems we're fine.
> 
>> I feel like that we should maybe use `find_program()` to find a python interpreter,
>> and use that everywhere a native python executable is needed? And for example invoke
>> sphinx as follows:
>>
>>     py3 = find_program(...)
>>     [py3, '-m', 'sphinx', ...]
> 
> Possibly, but that may be a bit overkill. I'm tempted to leave it as-is
> for now as nothing seems broken.
> 
>> Or am I missing something?
>>
>>>                              'import @0@ ; print(@0@.__version__)'.format(mod),
>>>                              check : false).stdout().strip()
>>>
>>>
>>> base-commit: af43c2f945c42cc7d111de63abed9ca3df830ca4
>
Laurent Pinchart Aug. 19, 2025, 12:21 p.m. UTC | #7
On Tue, Aug 19, 2025 at 11:39:08AM +0000, Barnabás Pőcze wrote:
> 2025. 08. 19. 12:57 keltezéssel, Laurent Pinchart írta:
> > On Tue, Aug 19, 2025 at 12:01:22PM +0200, Barnabás Pőcze wrote:
> >> 2025. 08. 18. 14:11 keltezéssel, Laurent Pinchart írta:
> >>> When checking the version of the sphinxcontrib.doxylink module, the
> >>> Python interpreter used by Sphinx must be used, as that's where the
> >>> module will be imported from. Using the meson python_installation object
> >>> for this purpose is incorrect, as it's meant to access the Python
> >>> installation of the host machine, not the native Python interpreter on
> >>> the host machine. Fix this by using python3 directly.
> >>>
> >>> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >>> ---
> >>>    Documentation/meson.build | 5 +----
> >>>    1 file changed, 1 insertion(+), 4 deletions(-)
> >>>
> >>> diff --git a/Documentation/meson.build b/Documentation/meson.build
> >>> index b898ba3a0b7e..163875014eec 100644
> >>> --- a/Documentation/meson.build
> >>> +++ b/Documentation/meson.build
> >>> @@ -124,12 +124,9 @@ if sphinx.found()
> >>>        # Many distributions do not provide a recent-enough version of the doxylink
> >>>        # module. This results in a build error with a cryptic message. Check the
> >>>        # version manually and print clear error messages.
> >>> -    py_mod = import('python')
> >>> -    py3 = py_mod.find_installation('python3')
> >>> -
> >>>        mod = 'sphinxcontrib.doxylink'
> >>>        min_version = '>=1.6.1'
> >>> -    version = run_command(py3, '-c',
> >>> +    version = run_command('python3', '-c',
> >>
> >> Should this not use `find_program(nature: true)`? (Or does it already implicitly?)
> > 
> > When run_command() receives a string, it wraps them in an
> > ExternalProgram() instance, which is also what find_program() gives.
> > find_program() gives more control and supports features such as wraps.
> > 
> > When cross-compiling libcamera with a cross-file that specifies a Python
> > interpreter binary from buildroot, meson prints the following to its log
> > for the about run_command('python3', ...) call:
> > 
> > Running command: /usr/bin/python3 -c 'import sphinxcontrib.doxylink ; print(sphinxcontrib.doxylink.__version__)'
> > 
> > It seems we're fine.
> 
> As far as I am aware program overrides in cross/native files won't take effect
> in this case (not using `find_program()`), no?

Oops indeed, you're right.

I've tried

    host_py3 = find_program('python3')
    version = run_command(host_py3, '-c',
                          'import @0@ ; print(@0@.__version__)'.format(mod),
                          check : false).stdout().strip()

and meson still picks /usr/bin/python3. However, with

    host_py3 = find_program('python')
    version = run_command(host_py3, '-c',
                          'import @0@ ; print(@0@.__version__)'.format(mod),
                          check : false).stdout().strip()

meson picks the interpreter from the cross file. With

    version = run_command('python', '-c',
                          'import @0@ ; print(@0@.__version__)'.format(mod),
                          check : false).stdout().strip()

meson picks /usr/bin/python3.

> Although I suppose overriding python
> might be incompatible with other parts using the python module?

I think it's another big rabbit hole :-) In theory it would be nice, in
practice I'm not sure anyone would care.

> >> I feel like that we should maybe use `find_program()` to find a python interpreter,
> >> and use that everywhere a native python executable is needed? And for example invoke
> >> sphinx as follows:
> >>
> >>     py3 = find_program(...)
> >>     [py3, '-m', 'sphinx', ...]
> > 
> > Possibly, but that may be a bit overkill. I'm tempted to leave it as-is
> > for now as nothing seems broken.
> > 
> >> Or am I missing something?
> >>
> >>>                              'import @0@ ; print(@0@.__version__)'.format(mod),
> >>>                              check : false).stdout().strip()
> >>>
> >>>
> >>> base-commit: af43c2f945c42cc7d111de63abed9ca3df830ca4

Patch
diff mbox series

diff --git a/Documentation/meson.build b/Documentation/meson.build
index b898ba3a0b7e..163875014eec 100644
--- a/Documentation/meson.build
+++ b/Documentation/meson.build
@@ -124,12 +124,9 @@  if sphinx.found()
     # Many distributions do not provide a recent-enough version of the doxylink
     # module. This results in a build error with a cryptic message. Check the
     # version manually and print clear error messages.
-    py_mod = import('python')
-    py3 = py_mod.find_installation('python3')
-
     mod = 'sphinxcontrib.doxylink'
     min_version = '>=1.6.1'
-    version = run_command(py3, '-c',
+    version = run_command('python3', '-c',
                           'import @0@ ; print(@0@.__version__)'.format(mod),
                           check : false).stdout().strip()