aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-04-03 23:38:07 +0300
committerGitHub <noreply@github.com>2017-04-03 23:38:07 +0300
commit99649e66908693c58fa0c015dbcce19ad8f55b19 (patch)
treeac8448f3658d48e095d008d47511dd136ef90fff
parent8b73d807924dde250f1c4340885ef46a22b82ba7 (diff)
parent86644bbdfce9c859801fb405f4253bb3d88440d6 (diff)
downloadmeson-99649e66908693c58fa0c015dbcce19ad8f55b19.zip
meson-99649e66908693c58fa0c015dbcce19ad8f55b19.tar.gz
meson-99649e66908693c58fa0c015dbcce19ad8f55b19.tar.bz2
Merge pull request #1520 from mesonbuild/tingping/python3-module
Add get_path() and get_version() methods to the python3 module
-rw-r--r--mesonbuild/modules/python3.py22
-rw-r--r--test cases/python3/1 basic/meson.build10
2 files changed, 32 insertions, 0 deletions
diff --git a/mesonbuild/modules/python3.py b/mesonbuild/modules/python3.py
index 53e28c4..9f01043 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,25 @@ 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 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()
diff --git a/test cases/python3/1 basic/meson.build b/test cases/python3/1 basic/meson.build
index 9d5f874..111b717 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)