Thread: Error on missing Python module in Meson setup

Error on missing Python module in Meson setup

From
Daniel Gustafsson
Date:
When setting up a postgres tree with Meson on an almost empty Debian 11 VM I
hit an error on "meson setup -Ddebug=true build ." like this:

    Program python3 found: YES (/usr/bin/python3)
    meson.build:987:2: ERROR: Unknown method "dependency" in object.

The error in itself isn't terribly self-explanatory.  According to the log the
error was a missing Python package:

    Traceback (most recent call last):
    File "<string>", line 20, in <module>
    File "<string>", line 8, in links_against_libpython
    ModuleNotFoundError: No module named ‘distutils.core'

Installing the distutils package fixes it, but it seems harsh to fail setup on
a missing package. Would something like the attached make sense?

--
Daniel Gustafsson        https://vmware.com/


Attachment

Re: Error on missing Python module in Meson setup

From
Andres Freund
Date:
Hi,

On 2022-11-14 14:23:02 +0100, Daniel Gustafsson wrote:
> When setting up a postgres tree with Meson on an almost empty Debian 11 VM I
> hit an error on "meson setup -Ddebug=true build ." like this:
> 
>     Program python3 found: YES (/usr/bin/python3)
>     meson.build:987:2: ERROR: Unknown method "dependency" in object.
> 
> The error in itself isn't terribly self-explanatory.  According to the log the
> error was a missing Python package:

>     Traceback (most recent call last):
>     File "<string>", line 20, in <module>
>     File "<string>", line 8, in links_against_libpython
>     ModuleNotFoundError: No module named ‘distutils.core'
> 
> Installing the distutils package fixes it, but it seems harsh to fail setup on
> a missing package. Would something like the attached make sense?

The error is a bit better in newer versions of meson:
meson.build:986: WARNING: <PythonExternalProgram 'python3' -> ['/usr/bin/python3']> is not a valid python or it is
missingdistutils
 
but we do still error out weirdly afterwards.

We probably should report this to the meson folks regardless of us working
around it or not.


> diff --git a/meson.build b/meson.build
> index 058382046e..1a7e301fc9 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -984,8 +984,12 @@ pyopt = get_option('plpython')
>  if not pyopt.disabled()
>    pm = import('python')
>    python3_inst = pm.find_installation(required: pyopt.enabled())
> -  python3_dep = python3_inst.dependency(embed: true, required: pyopt.enabled())
> -  if not cc.check_header('Python.h', dependencies: python3_dep, required: pyopt.enabled())
> +  if python3_inst.found()
> +    python3_dep = python3_inst.dependency(embed: true, required: pyopt.enabled())
> +    if not cc.check_header('Python.h', dependencies: python3_dep, required: pyopt.enabled())
> +      python3_dep = not_found_dep
> +    endif
> +  else
>      python3_dep = not_found_dep
>    endif
>  else

Perhaps worth simplifying a bit. What do you think about:


pyopt = get_option('plpython')
python3_dep = not_found_dep
if not pyopt.disabled()
  pm = import('python')
  python3_inst = pm.find_installation(required: pyopt.enabled())
  if python3_inst.found()
    python3_dep_int = python3_inst.dependency(embed: true, required: pyopt.enabled())
    if cc.check_header('Python.h', dependencies: python3_dep_int, required: pyopt.enabled())
      python3_dep = python3_dep
    endif
  endif
endif


Greetings,

Andres Freund



Re: Error on missing Python module in Meson setup

From
Daniel Gustafsson
Date:
> On 15 Nov 2022, at 01:25, Andres Freund <andres@anarazel.de> wrote:
> On 2022-11-14 14:23:02 +0100, Daniel Gustafsson wrote

>> Installing the distutils package fixes it, but it seems harsh to fail setup on
>> a missing package. Would something like the attached make sense?
>
> The error is a bit better in newer versions of meson:
> meson.build:986: WARNING: <PythonExternalProgram 'python3' -> ['/usr/bin/python3']> is not a valid python or it is
missingdistutils 
> but we do still error out weirdly afterwards.
>
> We probably should report this to the meson folks regardless of us working
> around it or not.

Thats better, but I wish meson could be more specific since it at that point
should know if Python works at all or is missing distutils.

> Perhaps worth simplifying a bit. What do you think about:
>
> ...

Agreed, that's a better version.  The attached version with a disabler object
is even more to the point, and seems to works on my box both with and without
distutils and libpython.  Is this the correct way to use disablers?

--
Daniel Gustafsson        https://vmware.com/


Attachment