From f4d2efbed3a589bc7dbb129778eb2debb1f5fb2e Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 14 Jun 2021 15:36:16 -0700 Subject: [PATCH] interpreter: use typed_kwargs for install_headers --- mesonbuild/interpreter/interpreter.py | 23 +++++++++++------------ mesonbuild/interpreter/kwargs.py | 7 +++++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 3b881e8eb..851305411 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1885,23 +1885,22 @@ This will become a hard error in the future.''' % kwargs['input'], location=self mlog.debug('Adding benchmark', mlog.bold(t.name, True)) @typed_pos_args('install_headers', varargs=(str, mesonlib.File), min_varargs=1) + @typed_kwargs( + 'install_headers', + KwargInfo('install_dir', (str, None)), + KwargInfo('subdir', (str, None)), + _INSTALL_MODE_KW.evolve(since='0.47.0'), + ) def func_install_headers(self, node: mparser.BaseNode, args: T.Tuple[T.List['mesonlib.FileOrString']], - kwargs) -> build.Headers: + kwargs: 'kwargs.FuncInstallHeaders') -> build.Headers: source_files = self.source_strings_to_files(args[0]) - install_mode = self._get_kwarg_install_mode(kwargs) - - install_subdir = kwargs.get('subdir', '') - if not isinstance(install_subdir, str): - raise InterpreterException('subdir keyword argument must be a string') - elif os.path.isabs(install_subdir): + install_subdir = kwargs['subdir'] + if install_subdir is not None and os.path.isabs(install_subdir): mlog.deprecation('Subdir keyword must not be an absolute path. This will be a hard error in the next release.') - install_dir = kwargs.get('install_dir', None) - if install_dir is not None and not isinstance(install_dir, str): - raise InterpreterException('install_dir keyword argument must be a string if provided') - - h = build.Headers(source_files, install_subdir, install_dir, install_mode, self.subproject) + h = build.Headers(source_files, install_subdir, kwargs['install_dir'], + kwargs['install_mode'], self.subproject) self.build.headers.append(h) return h diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index 300bb1c26..1906d8556 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -118,3 +118,10 @@ class FuncInstallData(TypedDict): sources: T.List[FileOrString] rename: T.List[str] install_mode: FileMode + + +class FuncInstallHeaders(TypedDict): + + install_dir: T.Optional[str] + install_mode: FileMode + subdir: T.Optional[str]