interpreterobjects: use typed_kwargs for dependency.get_variable

pull/9850/head
Dylan Baker 3 years ago committed by Eli Schwartz
parent 1751dc4701
commit 1ff2abcd9c
  1. 28
      mesonbuild/interpreter/interpreterobjects.py
  2. 11
      mesonbuild/interpreter/kwargs.py

@ -16,8 +16,8 @@ from ..backend.backends import TestProtocol
from ..interpreterbase import ( from ..interpreterbase import (
ContainerTypeInfo, KwargInfo, MesonOperator, ContainerTypeInfo, KwargInfo, MesonOperator,
InterpreterObject, MesonInterpreterObject, ObjectHolder, MutableInterpreterObject, InterpreterObject, MesonInterpreterObject, ObjectHolder, MutableInterpreterObject,
FeatureCheckBase, FeatureNewKwargs, FeatureNew, FeatureDeprecated, FeatureCheckBase, FeatureNew, FeatureDeprecated,
typed_pos_args, typed_kwargs, typed_operator, permittedKwargs, typed_pos_args, typed_kwargs, typed_operator,
noArgsFlattening, noPosargs, noKwargs, unholder_return, TYPE_var, TYPE_kwargs, TYPE_nvar, TYPE_nkwargs, noArgsFlattening, noPosargs, noKwargs, unholder_return, TYPE_var, TYPE_kwargs, TYPE_nvar, TYPE_nkwargs,
flatten, resolve_second_level_holders, InterpreterException, InvalidArguments, InvalidCode) flatten, resolve_second_level_holders, InterpreterException, InvalidArguments, InvalidCode)
from ..interpreter.type_checking import NoneType from ..interpreter.type_checking import NoneType
@ -493,15 +493,27 @@ class DependencyHolder(ObjectHolder[Dependency]):
@FeatureNew('dependency.get_variable', '0.51.0') @FeatureNew('dependency.get_variable', '0.51.0')
@typed_pos_args('dependency.get_variable', optargs=[str]) @typed_pos_args('dependency.get_variable', optargs=[str])
@permittedKwargs({'cmake', 'pkgconfig', 'configtool', 'internal', 'default_value', 'pkgconfig_define'}) @typed_kwargs(
@FeatureNewKwargs('dependency.get_variable', '0.54.0', ['internal']) 'dependency.get_variable',
def variable_method(self, args: T.Tuple[T.Optional[str]], kwargs: T.Dict[str, T.Any]) -> T.Union[str, T.List[str]]: KwargInfo('cmake', (str, NoneType)),
KwargInfo('pkgconfig', (str, NoneType)),
KwargInfo('configtool', (str, NoneType)),
KwargInfo('internal', (str, NoneType), since='0.54.0'),
KwargInfo('default_value', (str, NoneType)),
KwargInfo('pkgconfig_define', ContainerTypeInfo(list, str, pairs=True), default=[], listify=True),
)
def variable_method(self, args: T.Tuple[T.Optional[str]], kwargs: 'kwargs.DependencyGetVariable') -> T.Union[str, T.List[str]]:
default_varname = args[0] default_varname = args[0]
if default_varname is not None: if default_varname is not None:
FeatureNew('Positional argument to dependency.get_variable()', '0.58.0', location=self.current_node).use(self.subproject) FeatureNew('Positional argument to dependency.get_variable()', '0.58.0', location=self.current_node).use(self.subproject)
for k in ['cmake', 'pkgconfig', 'configtool', 'internal']: return self.held_object.get_variable(
kwargs.setdefault(k, default_varname) cmake=kwargs['cmake'] or default_varname,
return self.held_object.get_variable(**kwargs) pkgconfig=kwargs['pkgconfig'] or default_varname,
configtool=kwargs['configtool'] or default_varname,
internal=kwargs['internal'] or default_varname,
default_value=kwargs['default_value'],
pkgconfig_define=kwargs['pkgconfig_define'],
)
@FeatureNew('dependency.include_type', '0.52.0') @FeatureNew('dependency.include_type', '0.52.0')
@noPosargs @noPosargs

@ -250,3 +250,14 @@ class DependencyPkgConfigVar(TypedDict):
default: T.Optional[str] default: T.Optional[str]
define_variable: T.List[str] define_variable: T.List[str]
class DependencyGetVariable(TypedDict):
cmake: T.Optional[str]
pkgconfig: T.Optional[str]
configtool: T.Optional[str]
internal: T.Optional[str]
default_value: T.Optional[str]
pkgconfig_define: T.List[str]

Loading…
Cancel
Save