diff --git a/meson.build b/meson.build index e793a55..e2abd45 100644 --- a/meson.build +++ b/meson.build @@ -62,7 +62,22 @@ if get_option('gtk_doc') subdir('docs') endif -subdir('tests') +if get_option('tests') + # Python 3 required modules + python3_required_modules = ['dbusmock', 'gi'] + + python = import('python') + python3 = python.find_installation('python3') + foreach p : python3_required_modules + # Source: https://docs.python.org/3/library/importlib.html#checking-if-a-module-can-be-imported + script = 'import importlib.util; import sys; exit(1) if importlib.util.find_spec(\''+ p +'\') is None else exit(0)' + if run_command(python3, '-c', script, check: false).returncode() != 0 + error('Python3 module \'' + p + '\' required for running tests but not found') + endif + endforeach + + subdir('tests') +endif meson.add_dist_script( find_program('check-news.sh').path(), diff --git a/meson_options.txt b/meson_options.txt index 7e89619..307bc6a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -10,3 +10,7 @@ option('pylint', type: 'boolean', value: false, description: 'Run pylint checks, for developers only') +option('tests', + description: 'Whether to run tests', + type: 'boolean', + value: false)