Repository: mesonbuild/meson

Issue:
install_sources installs python sources into wrong directory on windows
Standard MSVC python:
```
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils import sysconfig
>>> sysconfig.get_python_lib()
'C:\\Python36\\Lib\\site-packages'
```

modules/python.py  - INSTALL_PATHS_COMMAND - sets posix_prefix (on windows)

```
print (json.dumps(sysconfig.get_paths(scheme='posix_prefix', vars={'base': '', 'platbase': '', 'installed_base': ''})))
{"stdlib": "\\lib\\python3.6", "platstdlib": "\\lib\\python3.6", "purelib": "\\lib\\python3.6\\site-packages", "platlib": "\\lib\\python3.6\\site-packages", "include": "\\include\\python3.6", "platinclude": "C:\\Python36\\include\\python3.6", "scripts": "\\bin", "data": "."}
```

syconfig does the right thing when not forced into posix_prefix
```
print (json.dumps(sysconfig.get_paths( vars={'base': '', 'platbase': '', 'installed_base': ''})))
>>> print (json.dumps(sysconfig.get_paths( vars={'base': '', 'platbase': '', 'installed_base': ''})))
{"stdlib": "\\Lib", "platstdlib": "\\Lib", "purelib": "\\Lib\\site-packages", "platlib": "\\Lib\\site-packages", "include": "\\Include", "platinclude": "\\Include", "scripts": "\\Scripts", "data": "."}
```


Discussion:
I'm not sure I understand the issue here, what are you writing in your build file, what do you expect, and what actually happens?

CCing @MathieuDuponchelle 
We probably want to use scheme='nt' on Windows, in any case meson's prefix will be prepended to these, so afaiu if you want the module to do "the right thing" you will probably need to pass a `C:\python36` prefix in that case as well, which is slightly weird :)
Hi @MathieuDuponchelle ,

Sorry - I guess there is to much information,

The install should go to:
```
'C:\\Python36\\Lib\\site-packages'
```

Instead it goes to:
```
'C:\\Python36\\lib\\python3.6\\site-packages`
```

which is invalid and not recognized by the windows python. scheme='nt' or just not setting the scheme would likely fix this.
@fpn , I'm still missing some information here, can you confirm that in your example, you have passed `--prefix=C:\Python36` ? I have just given `scheme='nt'` a quick try to confirm its behaviour, and while the layout does match the python install better, with no prefix specified it will install python sources to `C:\Lib\site-packages` , not `C:\path\to\python\Lib\site-packages`, and that is the expected behaviour as we want to respect whatever prefix was provided by the user.
@MathieuDuponchelle  - here is what I am currently using and that seemed to have fixed this problem for me:

https://github.com/mesonbuild/meson/compare/master...bebo:scheme_nt?expand=1

The only concern with the code as a generic fix (and why I didn't do a pull request) is that I think on windows it may be better to not set the scheme at all and let python decide.

For example if I use the python3 from msys2 it implicitly uses the posix style and using the python3 for regular windows I get nt style.
@fpn, can you please answer the question I had regarding the prefix?
@MathieuDuponchelle so I use DESTDIR and have the default prefix ```C:/``` - sorry I broke my build somehow and wanted to make sure I give you the right information





@fpn then unless your DESTDIR is set to `C:\\Python36`, I don't understand how changing the scheme will lead to the source files being installed to `C:\\Python36\\Lib\\site-packages` :)
Hi @MathieuDuponchelle you are correct, I guess I have a pythoncentric view point;-)

Since I want to use the installed python modules with gst-python / gstreamer, I do point it to a python installation, that way I can use all the modules. As a python user on windows I could also point it to a virtualenv (which would behave the same). The DESTDIR environment variable worked fine for me.

Removing the scheme (or changing the scheme to nt) on windows makes it go to:

```<prefix>\\lib\\site-packages```

instead of the posix:

```<prefix>\\lib\\python3.6\\site-packages```

Which means that python can find the files, whereas in the posix directory they just sit there until I find them and manually copy the expected location.

Which is the reason why I opened this ticket.

P.S.
In my particular case I am actually building a windows python app, so my case is:
* clean windows python install into a staging directory
* meson build gstreamer, gobjectintrospection, pygobject, gst-python and install into the same staging directory
* pyinstaller against a python application that uses that python/g* directory to create a quite different structure

Resolving patch:
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -279,7 +279,7 @@ def set_env(name, value):
 import json
 import sys
 
-install_paths = sysconfig.get_paths(scheme='posix_prefix', vars={'base': '', 'platbase': '', 'installed_base': ''})
+install_paths = sysconfig.get_paths(vars={'base': '', 'platbase': '', 'installed_base': ''})
 
 def links_against_libpython():
     from distutils.core import Distribution, Extension


Test patch: