Repository: mesonbuild/meson

Issue:
python.find_installation() fails on Windows
The following meson.build file fails to build on Windows using a meson MSI installed package:

```
project('foo')

python = import('python').find_installation()
```

Same with both meson 0.60.0 and 0.61.1

Complete output:
```
The Meson build system
Version: 0.61.1
Source dir: C:\temp
Build dir: C:\temp\build
Build type: native build
Project name: foo
Project version: undefined
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program python3 found: YES (C:\Program Files\Meson\meson.exe runpython)

meson.build:3:0: ERROR: <PythonExternalProgram 'python3' -> ['C:\\Program Files\\Meson\\meson.exe', 'runpython']> is not a valid python or it is missing distutils

A full log can be found at C:\temp\build\meson-logs\meson-log.txt
```

This appears to be a regression of #5217


Discussion:
[meson-log.txt](https://github.com/mesonbuild/meson/files/8034565/meson-log.txt)

Didn't Microsoft do something stupid where the Python on default Windows is just a program which launches and helps you to install regular Python? On my default Windows 10 it is. Tell Microsoft they make broken software. Not sure if that is the issue however. Nevermind. Just me ranting :)
@tristan957  Microsoft does do that, but it doesn't matter because Meson bundles its own python. And meson is not trying to use the MS python. It's trying to use the bundled python via `meson.exe runpython`, and that is failing with
```
Program stdout:


ERROR: Unhandled python exception

    This is a Meson bug and should be reported!
```
in meson-log.txt
Actually the real error there is `ModuleNotFoundError: No module named 'distutils.command.install'`

I totally forgot `runpython` exists, because on Linux it just uses `sys.executable`.

Obviously this should not have a generic catch-all for exceptions that claims everything is a "meson bug", applying to that one meson subcommand which is literally a passthrough to sys.executable for platforms where sys.executable may not exist standalone. I keep finding odd edge cases for that "unhandled python exception" warning, but this is an especially odd one. Maybe I can somehow rethink how it applies...

Be that as it may, the python module will *always* claim any found python without distutils is an "invalid python".
(Or it will do so until either python 3.12, or we can migrate over detection of "links to libpython" to something else.)

On 2022-02-09 6:00 p.m., Eli Schwartz wrote:
> Be that as it may, the python module will /always/ claim any found 
> python without distutils is an "invalid python".
> (Or it will do so until either python 3.12, or we can migrate over 
> detection of "links to libpython" to something else.)

So the issue is that the msi doesn't bundle distutils?

(Aside: the meson.exe inside the MSI should statically know whether or 
not it "links to libpython", shouldn't it?)


Resolving patch:
diff --git a/packaging/createmsi.py b/packaging/createmsi.py
--- a/packaging/createmsi.py
+++ b/packaging/createmsi.py
@@ -72,6 +72,7 @@ def get_more_modules():
             'distutils.version',
             'distutils.command.build_ext',
             'distutils.command.build',
+            'distutils.command.install',
             'filecmp',
             ]
 


Test patch: