diff options
author | Charles Brunet <charles.brunet@optelgroup.com> | 2023-04-19 08:52:21 -0400 |
---|---|---|
committer | Eli Schwartz <eschwartz93@gmail.com> | 2023-05-02 17:52:10 -0400 |
commit | 51b9f2f1a5cd43d903033f4738a4235fe656cb07 (patch) | |
tree | ff342dd376e8cf24af6553348730520bf26dd839 | |
parent | 107f933b528cdaf23c038cbc99f5248c9ca666bd (diff) | |
download | meson-51b9f2f1a5cd43d903033f4738a4235fe656cb07.tar.gz |
Find python3.xx on windows
-rw-r--r-- | docs/markdown/Python-module.md | 5 | ||||
-rw-r--r-- | docs/markdown/snippets/python-find-version.md | 6 | ||||
-rw-r--r-- | mesonbuild/modules/python.py | 4 |
3 files changed, 12 insertions, 3 deletions
diff --git a/docs/markdown/Python-module.md b/docs/markdown/Python-module.md index bc4311f58..f67262abf 100644 --- a/docs/markdown/Python-module.md +++ b/docs/markdown/Python-module.md @@ -37,7 +37,10 @@ If provided, it can be: - One of `python2` or `python3`: in either case, the module will try some alternative names: `py -2` or `py -3` on Windows, and `python` everywhere. In the latter case, it will check whether the version - provided by the sysconfig module matches the required major version + provided by the sysconfig module matches the required major version. + + *Since 1.2.0*, searching for minor version (e.g. `python3.11`) also + works on Windows. Keyword arguments are the following: diff --git a/docs/markdown/snippets/python-find-version.md b/docs/markdown/snippets/python-find-version.md new file mode 100644 index 000000000..0cd6672c2 --- /dev/null +++ b/docs/markdown/snippets/python-find-version.md @@ -0,0 +1,6 @@ +## Find more specific python version on Windows + +You can now use `python3.x`, where `x` is the minor version, +to find a more specific version of python on Windows, when +using the python module. On other platforms, it was already +working as `python3.x` is the executable name. diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index 239c68af7..178f1bdce 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -300,12 +300,12 @@ class PythonModule(ExtensionModule): # https://www.python.org/dev/peps/pep-0397/ @staticmethod def _get_win_pythonpath(name_or_path: str) -> T.Optional[str]: - if name_or_path not in ['python2', 'python3']: + if not name_or_path.startswith(('python2', 'python3')): return None if not shutil.which('py'): # program not installed, return without an exception return None - ver = {'python2': '-2', 'python3': '-3'}[name_or_path] + ver = f'-{name_or_path[6:]}' cmd = ['py', ver, '-c', "import sysconfig; print(sysconfig.get_config_var('BINDIR'))"] _, stdout, _ = mesonlib.Popen_safe(cmd) directory = stdout.strip() |