From 052d918908b4e571a42cd3fc539933f9db139e0c Mon Sep 17 00:00:00 2001 From: "Michael Hirsch, Ph.D" Date: Fri, 8 Nov 2019 03:43:49 -0500 Subject: add fs.with_suffix --- mesonbuild/modules/fs.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'mesonbuild') diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py index a9881c49f..1687d0d80 100644 --- a/mesonbuild/modules/fs.py +++ b/mesonbuild/modules/fs.py @@ -13,7 +13,7 @@ # limitations under the License. import typing -from pathlib import Path +from pathlib import Path, PurePath from . import ExtensionModule from . import ModuleReturnValue @@ -55,5 +55,15 @@ class FSModule(ExtensionModule): def is_dir(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: return self._check('is_dir', state, args) + @stringArgs + @noKwargs + def with_suffix(self, state: 'ModuleState', args: typing.Sequence[str], kwargs: dict) -> ModuleReturnValue: + if len(args) != 2: + MesonException('method takes exactly two arguments.') + original = PurePath(state.source_root) / state.subdir / args[0] + new = original.with_suffix(args[1]) + return ModuleReturnValue(str(new), []) + + def initialize(*args, **kwargs) -> FSModule: return FSModule(*args, **kwargs) -- cgit v1.2.3