From b6e06dd80be961c5924f331f9b6b3682a8e949c4 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sat, 25 Mar 2017 06:04:07 -0400 Subject: [PATCH 1/3] python3: Add language_version() method --- mesonbuild/modules/python3.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mesonbuild/modules/python3.py b/mesonbuild/modules/python3.py index 53e28c4d0..d7d03e307 100644 --- a/mesonbuild/modules/python3.py +++ b/mesonbuild/modules/python3.py @@ -13,11 +13,13 @@ # limitations under the License. import sys +import sysconfig from .. import mesonlib, dependencies from . import ExtensionModule from mesonbuild.modules import ModuleReturnValue + class Python3Module(ExtensionModule): def __init__(self): super().__init__() @@ -45,5 +47,11 @@ class Python3Module(ExtensionModule): py3 = dependencies.ExternalProgram('python3', sys.executable, silent=True) return ModuleReturnValue(py3, [py3]) + def language_version(self, state, args, kwargs): + if args or kwargs: + raise mesonlib.MesonException('language_version() takes no arguments.') + return ModuleReturnValue(sysconfig.get_python_version(), []) + + def initialize(): return Python3Module() From a9c30ce8b54752caedacd1eacfcd9156f190101b Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sat, 25 Mar 2017 06:04:32 -0400 Subject: [PATCH 2/3] python3: Add sysconfig_path() method This returns the value of sysconfig paths, useful for installing modules for example. --- mesonbuild/modules/python3.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mesonbuild/modules/python3.py b/mesonbuild/modules/python3.py index d7d03e307..9f010435a 100644 --- a/mesonbuild/modules/python3.py +++ b/mesonbuild/modules/python3.py @@ -52,6 +52,20 @@ class Python3Module(ExtensionModule): raise mesonlib.MesonException('language_version() takes no arguments.') return ModuleReturnValue(sysconfig.get_python_version(), []) + def sysconfig_path(self, state, args, kwargs): + if len(args) != 1: + raise mesonlib.MesonException('sysconfig_path() requires passing the name of path to get.') + if kwargs: + raise mesonlib.MesonException('sysconfig_path() does not accept keywords.') + path_name = args[0] + valid_names = sysconfig.get_path_names() + if path_name not in valid_names: + raise mesonlib.MesonException('{} is not a valid path name {}.'.format(path_name, valid_names)) + + # Get a relative path without a prefix, e.g. lib/python3.6/site-packages + path = sysconfig.get_path(path_name, vars={'base': ''})[1:] + return ModuleReturnValue(path, []) + def initialize(): return Python3Module() From 86644bbdfce9c859801fb405f4253bb3d88440d6 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Thu, 30 Mar 2017 09:16:26 -0400 Subject: [PATCH 3/3] python3: Add tests for sysconfig_path() and language_version() --- test cases/python3/1 basic/meson.build | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test cases/python3/1 basic/meson.build b/test cases/python3/1 basic/meson.build index 9d5f874c6..111b71724 100644 --- a/test cases/python3/1 basic/meson.build +++ b/test cases/python3/1 basic/meson.build @@ -3,6 +3,16 @@ project('python sample', 'c') py3_mod = import('python3') py3 = py3_mod.find_python() +py3_version = py3_mod.language_version() +if py3_version.version_compare('< 3.2') + error('Invalid python version!?') +endif + +py3_purelib = py3_mod.sysconfig_path('purelib') +if not py3_purelib.endswith('site-packages') + error('Python3 purelib path seems invalid?') +endif + main = files('prog.py') test('toplevel', py3, args : main)