aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/modules/python.py
diff options
context:
space:
mode:
authorHavard Graff <havard.graff@gmail.com>2018-04-19 14:09:14 +0200
committerMathieu Duponchelle <mathieu@centricular.com>2018-04-21 19:50:53 +0200
commit14db3861d832d30721ad43671b5a434e2f4abeb3 (patch)
tree698c36d964ada196a45e4f3e97379717d1f695ea /mesonbuild/modules/python.py
parent74404db469bc37fbe184cc708a19ccbe58bf83df (diff)
downloadmeson-14db3861d832d30721ad43671b5a434e2f4abeb3.zip
meson-14db3861d832d30721ad43671b5a434e2f4abeb3.tar.gz
meson-14db3861d832d30721ad43671b5a434e2f4abeb3.tar.bz2
modules/python: add some more options around path and config_vars
What is actually defined here varies wildly on different python-versions for different platforms. On my python2.7 on Windows len(sysconfig.get_config_vars()) returns 17, whereas in my Ubuntu that number is 517! Hence it is useful to be able to check which keys are available, as well as allowing specifying a default option.
Diffstat (limited to 'mesonbuild/modules/python.py')
-rw-r--r--mesonbuild/modules/python.py52
1 files changed, 39 insertions, 13 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index 16bdfd6..afcae8f 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -313,32 +313,58 @@ class PythonInstallation(ExternalProgramHolder, InterpreterObject):
return ModuleReturnValue(True, [])
@noKwargs
- def get_path(self, node, args, kwargs):
+ def has_path(self, node, args, kwargs):
if len(args) != 1:
- raise InvalidArguments('get_path takes exactly one positional argument.')
+ raise InvalidArguments('has_path takes exactly one positional argument.')
path_name = args[0]
if not isinstance(path_name, str):
- raise InvalidArguments('get_path argument must be a string.')
+ raise InvalidArguments('has_path argument must be a string.')
+
+ return ModuleReturnValue(path_name in self.paths, [])
- path = self.paths.get(path_name)
+ @noKwargs
+ def get_path(self, node, args, kwargs):
+ if len(args) not in (1, 2):
+ raise InvalidArguments('get_path must have one or two arguments.')
+ path_name = args[0]
+ if not isinstance(path_name, str):
+ raise InvalidArguments('get_path argument must be a string.')
- if path is None:
- raise InvalidArguments('{} is not a valid path name'.format(path_name))
+ try:
+ path = self.paths[path_name]
+ except KeyError:
+ if len(args) == 2:
+ path = args[1]
+ else:
+ raise InvalidArguments('{} is not a valid path name'.format(path_name))
return ModuleReturnValue(path, [])
@noKwargs
- def get_variable(self, node, args, kwargs):
+ def has_variable(self, node, args, kwargs):
if len(args) != 1:
- raise InvalidArguments('get_variable takes exactly one positional argument.')
+ raise InvalidArguments('has_variable takes exactly one positional argument.')
var_name = args[0]
if not isinstance(var_name, str):
- raise InvalidArguments('get_variable argument must be a string.')
+ raise InvalidArguments('has_variable argument must be a string.')
+
+ return ModuleReturnValue(var_name in self.variables, [])
- var = self.variables.get(var_name)
+ @noKwargs
+ def get_variable(self, node, args, kwargs):
+ if len(args) not in (1, 2):
+ raise InvalidArguments('get_variable must have one or two arguments.')
+ var_name = args[0]
+ if not isinstance(var_name, str):
+ raise InvalidArguments('get_variable argument must be a string.')
- if var is None:
- raise InvalidArguments('{} is not a valid path name'.format(var_name))
+ try:
+ var = self.variables[var_name]
+ except KeyError:
+ if len(args) == 2:
+ var = args[1]
+ else:
+ raise InvalidArguments('{} is not a valid variable name'.format(var_name))
return ModuleReturnValue(var, [])
@@ -351,7 +377,7 @@ class PythonInstallation(ExternalProgramHolder, InterpreterObject):
if method_name in ['extension_module', 'dependency', 'install_sources']:
value = fn(self.interpreter, None, args, kwargs)
return self.interpreter.holderify(value)
- elif method_name in ['get_variable', 'get_path', 'found', 'language_version', 'get_install_dir']:
+ elif method_name in ['has_variable', 'get_variable', 'has_path', 'get_path', 'found', 'language_version', 'get_install_dir']:
value = fn(None, args, kwargs)
return self.interpreter.module_method_callback(value)
else: