aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/modules/i18n.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-09-29 21:20:27 -0700
committerDylan Baker <dylan@pnwbakers.com>2021-09-30 16:09:14 -0700
commit6399544e4c2768d7c83cec97ce0e106b71010ce4 (patch)
tree36635c6cb09cff58d5c5ff5b2030975e921672f4 /mesonbuild/modules/i18n.py
parent6b1a80024c79876dc3b75f2b525be24ca8fe671a (diff)
downloadmeson-6399544e4c2768d7c83cec97ce0e106b71010ce4.zip
meson-6399544e4c2768d7c83cec97ce0e106b71010ce4.tar.gz
meson-6399544e4c2768d7c83cec97ce0e106b71010ce4.tar.bz2
modules/i18n: use typed_kwargs for gettext
There were two allowed kwargs that were unused, I've dropped them for now, though I need to check if they were documented. If they are then we need to deprecate them to remove them, otherwise we'll just leave them removed.
Diffstat (limited to 'mesonbuild/modules/i18n.py')
-rw-r--r--mesonbuild/modules/i18n.py69
1 files changed, 50 insertions, 19 deletions
diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py
index 16f6127..367af25 100644
--- a/mesonbuild/modules/i18n.py
+++ b/mesonbuild/modules/i18n.py
@@ -18,11 +18,10 @@ import typing as T
from . import ExtensionModule, ModuleReturnValue
from .. import build
-from .. import coredata
from .. import mesonlib
from .. import mlog
-from ..interpreter.type_checking import CT_BUILD_BY_DEFAULT, CT_INPUT_KW, CT_INSTALL_DIR_KW, CT_INSTALL_TAG_KW, CT_OUTPUT_KW, INSTALL_KW, in_set_validator
-from ..interpreterbase import permittedKwargs, FeatureNew, FeatureNewKwargs
+from ..interpreter.type_checking import CT_BUILD_BY_DEFAULT, CT_INPUT_KW, CT_INSTALL_DIR_KW, CT_INSTALL_TAG_KW, CT_OUTPUT_KW, INSTALL_KW, NoneType, in_set_validator
+from ..interpreterbase import FeatureNew
from ..interpreterbase.decorators import ContainerTypeInfo, KwargInfo, noPosargs, typed_kwargs, typed_pos_args
from ..scripts.gettext import read_linguas
@@ -50,6 +49,29 @@ if T.TYPE_CHECKING:
po_dir: str
type: Literal['xml', 'desktop']
+ class Gettext(TypedDict):
+
+ args: T.List[str]
+ data_dirs: T.List[str]
+ install: bool
+ install_dir: T.Optional[str]
+ languages: T.List[str]
+ preset: T.Optional[str]
+
+
+_ARGS: KwargInfo[T.List[str]] = KwargInfo(
+ 'args',
+ ContainerTypeInfo(list, str),
+ default=[],
+ listify=True,
+)
+
+_DATA_DIRS: KwargInfo[T.List[str]] = KwargInfo(
+ 'data_dirs',
+ ContainerTypeInfo(list, str),
+ default=[],
+ listify=True
+)
PRESET_ARGS = {
'glib': [
@@ -114,8 +136,8 @@ class I18nModule(ExtensionModule):
CT_INSTALL_TAG_KW,
CT_OUTPUT_KW,
INSTALL_KW,
- KwargInfo('args', ContainerTypeInfo(list, str), default=[], listify=True, since='0.51.0'),
- KwargInfo('data_dirs', ContainerTypeInfo(list, str), default=[], listify=True),
+ _ARGS.evolve(since='0.51.0'),
+ _DATA_DIRS,
KwargInfo('po_dir', str, required=True),
KwargInfo('type', str, default='xml', validator=in_set_validator({'xml', 'desktop'})),
)
@@ -174,27 +196,35 @@ class I18nModule(ExtensionModule):
return ModuleReturnValue(ct, [ct])
- @FeatureNewKwargs('i18n.gettext', '0.37.0', ['preset'])
- @FeatureNewKwargs('i18n.gettext', '0.50.0', ['install_dir'])
- @permittedKwargs({'po_dir', 'data_dirs', 'type', 'languages', 'args', 'preset', 'install', 'install_dir'})
@typed_pos_args('i81n.gettex', str)
- def gettext(self, state: 'ModuleState', args: T.Tuple[str], kwargs) -> ModuleReturnValue:
+ @typed_kwargs(
+ 'i18n.gettext',
+ _ARGS,
+ _DATA_DIRS,
+ INSTALL_KW.evolve(default=True),
+ KwargInfo('install_dir', (str, NoneType), since='0.50.0'),
+ KwargInfo('languages', ContainerTypeInfo(list, str), default=[], listify=True),
+ KwargInfo(
+ 'preset',
+ (str, NoneType),
+ validator=in_set_validator(set(PRESET_ARGS)),
+ since='0.37.0',
+ ),
+ )
+ def gettext(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'Gettext') -> ModuleReturnValue:
if not shutil.which('xgettext'):
self.nogettext_warning()
return
packagename = args[0]
- languages = mesonlib.stringlistify(kwargs.get('languages', []))
- datadirs = self._get_data_dirs(state, mesonlib.stringlistify(kwargs.get('data_dirs', [])))
- extra_args = mesonlib.stringlistify(kwargs.get('args', []))
+ languages = kwargs['languages']
+ datadirs = self._get_data_dirs(state, kwargs['data_dirs'])
+ extra_args = kwargs['args']
targets = []
gmotargets = []
- preset = kwargs.pop('preset', None)
+ preset = kwargs['preset']
if preset:
- preset_args = PRESET_ARGS.get(preset)
- if not preset_args:
- raise coredata.MesonException('i18n: Preset "{}" is not one of the valid options: {}'.format(
- preset, list(PRESET_ARGS.keys())))
+ preset_args = PRESET_ARGS[preset]
extra_args = set(preset_args + extra_args)
pkg_arg = '--pkgname=' + packagename
@@ -210,8 +240,9 @@ class I18nModule(ExtensionModule):
pottarget = build.RunTarget(packagename + '-pot', potargs, [], state.subdir, state.subproject)
targets.append(pottarget)
- install = kwargs.get('install', True)
- install_dir = kwargs.get('install_dir', state.environment.coredata.get_option(mesonlib.OptionKey('localedir')))
+ install = kwargs['install']
+ install_dir = kwargs['install_dir'] or state.environment.coredata.get_option(mesonlib.OptionKey('localedir'))
+ assert isinstance(install_dir, str), 'for mypy'
if not languages:
languages = read_linguas(path.join(state.environment.source_dir, state.subdir))
for l in languages: