From 71a5f990d09f04d8eb8d636abf7e2b446fdf826a Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 18 Sep 2018 15:17:31 -0700 Subject: [PATCH] modules/python: Allow use of the native file Currently this just allows setting a "python" variable that always overrides, probably we want to have the option for "python2" and "python3" as well. --- mesonbuild/modules/python.py | 4 +++- run_unittests.py | 8 ++++++++ test cases/unit/46 native file binary/meson.build | 4 ++++ test cases/unit/46 native file binary/meson_options.txt | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index 954220bde..3b2bf077e 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -480,7 +480,9 @@ class PythonModule(ExtensionModule): if len(args) > 1: raise InvalidArguments('find_installation takes zero or one positional argument.') - if args: + if 'python' in state.environment.config_info.binaries: + name_or_path = state.environment.config_info.binaries['python'] + elif args: name_or_path = args[0] if not isinstance(name_or_path, str): raise InvalidArguments('find_installation argument must be a string.') diff --git a/run_unittests.py b/run_unittests.py index fc4e82b8b..05a84579b 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -4557,6 +4557,14 @@ class NativeFileTests(BasePlatformTests): def test_python3_module(self): self._simple_test('python3', 'python3') + def test_python_module(self): + if is_windows(): + # Bat adds extra crap to stdout, so the version check logic in the + # python module breaks. This is fine on other OSes because they + # don't need the extra indirection. + raise unittest.SkipTest('bat indirection breaks internal sanity checks.') + self._simple_test('python', 'python') + def unset_envs(): # For unit tests we must fully control all command lines diff --git a/test cases/unit/46 native file binary/meson.build b/test cases/unit/46 native file binary/meson.build index 76d69835a..4489ac1e6 100644 --- a/test cases/unit/46 native file binary/meson.build +++ b/test cases/unit/46 native file binary/meson.build @@ -14,4 +14,8 @@ elif case == 'python3' prog = import('python3').find_python() result = run_command(prog, ['--version']) assert(result.stdout().strip().endswith('12345'), 'Didn\'t load python3 from config file') +elif case == 'python' + prog = import('python').find_installation() + result = run_command(prog, ['--version']) + assert(result.stdout().strip().endswith('12345'), 'Didn\'t load python from config file') endif diff --git a/test cases/unit/46 native file binary/meson_options.txt b/test cases/unit/46 native file binary/meson_options.txt index ef7fe0228..651da0ebe 100644 --- a/test cases/unit/46 native file binary/meson_options.txt +++ b/test cases/unit/46 native file binary/meson_options.txt @@ -1,5 +1,5 @@ option( 'case', type : 'combo', - choices : ['find_program', 'config_dep', 'python3'] + choices : ['find_program', 'config_dep', 'python3', 'python'] )