aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Python-module.md4
-rw-r--r--mesonbuild/modules/python.py9
-rw-r--r--test cases/unit/39 python extmodule/meson.build3
-rw-r--r--test cases/unit/39 python extmodule/meson_options.txt1
4 files changed, 12 insertions, 5 deletions
diff --git a/docs/markdown/Python-module.md b/docs/markdown/Python-module.md
index 51721f0..2bcad78 100644
--- a/docs/markdown/Python-module.md
+++ b/docs/markdown/Python-module.md
@@ -45,7 +45,9 @@ Keyword arguments are the following:
abort if no python installation can be found. If `required` is set to `false`,
Meson will continue even if no python installation was found. You can
then use the `.found()` method on the returned object to check
- whether it was found or not.
+ whether it was found or not. Since *0.48.0* the value of a
+ [`feature`](Build-options.md#features) option can also be passed to the
+ `required` keyword argument.
**Returns**: a [python installation][`python_installation` object]
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index d9ec562..0ba086b 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -25,7 +25,7 @@ from ..interpreterbase import (
InterpreterObject, InvalidArguments,
FeatureNew
)
-from ..interpreter import ExternalProgramHolder
+from ..interpreter import ExternalProgramHolder, extract_required_kwarg
from ..interpreterbase import flatten
from ..build import known_shmod_kwargs
from .. import mlog
@@ -477,9 +477,10 @@ class PythonModule(ExtensionModule):
@permittedKwargs(['required'])
def find_installation(self, interpreter, state, args, kwargs):
- required = kwargs.get('required', True)
- if not isinstance(required, bool):
- raise InvalidArguments('"required" argument must be a boolean.')
+ disabled, required, feature = extract_required_kwarg(kwargs, state.subproject)
+ if disabled:
+ mlog.log('find_installation skipped: feature', mlog.bold(feature), 'disabled')
+ return ExternalProgramHolder(NonExistingExternalProgram())
if len(args) > 1:
raise InvalidArguments('find_installation takes zero or one positional argument.')
diff --git a/test cases/unit/39 python extmodule/meson.build b/test cases/unit/39 python extmodule/meson.build
index 4798654..eb00a6a 100644
--- a/test cases/unit/39 python extmodule/meson.build
+++ b/test cases/unit/39 python extmodule/meson.build
@@ -21,3 +21,6 @@ if py.found()
else
error('MESON_SKIP_TEST: Python not found, skipping test.')
endif
+
+py = py_mod.find_installation(get_option('python'), required : get_option('disabled_opt'))
+assert(not py.found(), 'find_installation not working with disabled feature')
diff --git a/test cases/unit/39 python extmodule/meson_options.txt b/test cases/unit/39 python extmodule/meson_options.txt
index b8f645d..c85110d 100644
--- a/test cases/unit/39 python extmodule/meson_options.txt
+++ b/test cases/unit/39 python extmodule/meson_options.txt
@@ -1,3 +1,4 @@
option('python', type: 'string',
description: 'Name of or path to the python executable'
)
+option('disabled_opt', type: 'feature', value: 'disabled')