Re: Error on missing Python module in Meson setup - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Error on missing Python module in Meson setup
Date
Msg-id 20221115002504.gbuli7reyoswnncd@awork3.anarazel.de
Whole thread Raw
In response to Error on missing Python module in Meson setup  (Daniel Gustafsson <daniel@yesql.se>)
Responses Re: Error on missing Python module in Meson setup
List pgsql-hackers
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



pgsql-hackers by date:

Previous
From: Alexandre hadjinlian guerra
Date:
Subject: Multitable insert syntax support on Postgres?
Next
From: Andres Freund
Date:
Subject: Re: Multitable insert syntax support on Postgres?