aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/modules/i18n.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-09-29 20:52:46 -0700
committerDylan Baker <dylan@pnwbakers.com>2021-09-30 16:09:14 -0700
commitb9231631098d999ae0f3f5fd7a85e7097c10ae62 (patch)
tree10006cb26a0f4a711860d22ca9fc5912ab996342 /mesonbuild/modules/i18n.py
parent57d0d4e95aac1cfd4e39004490584bbbeae36a18 (diff)
downloadmeson-b9231631098d999ae0f3f5fd7a85e7097c10ae62.zip
meson-b9231631098d999ae0f3f5fd7a85e7097c10ae62.tar.gz
meson-b9231631098d999ae0f3f5fd7a85e7097c10ae62.tar.bz2
modules/i18n: add easy type annotations
Diffstat (limited to 'mesonbuild/modules/i18n.py')
-rw-r--r--mesonbuild/modules/i18n.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py
index ed44eca..3d504ac 100644
--- a/mesonbuild/modules/i18n.py
+++ b/mesonbuild/modules/i18n.py
@@ -14,6 +14,7 @@
from os import path
import shutil
+import typing as T
from . import ExtensionModule, ModuleReturnValue
from .. import build
@@ -24,6 +25,10 @@ from ..interpreterbase import permittedKwargs, FeatureNew, FeatureNewKwargs
from ..mesonlib import MesonException
from ..scripts.gettext import read_linguas
+if T.TYPE_CHECKING:
+ from . import ModuleState
+ from ..interpreter import Interpreter
+
PRESET_ARGS = {
'glib': [
'--from-code=UTF-8',
@@ -60,7 +65,7 @@ PRESET_ARGS = {
class I18nModule(ExtensionModule):
- def __init__(self, interpreter):
+ def __init__(self, interpreter: 'Interpreter'):
super().__init__(interpreter)
self.methods.update({
'merge_file': self.merge_file,
@@ -68,11 +73,11 @@ class I18nModule(ExtensionModule):
})
@staticmethod
- def nogettext_warning():
+ def nogettext_warning() -> None:
mlog.warning('Gettext not found, all translation targets will be ignored.', once=True)
@staticmethod
- def _get_data_dirs(state, dirs):
+ def _get_data_dirs(state: 'ModuleState', dirs: T.Iterable[str]) -> T.List[str]:
"""Returns source directories of relative paths"""
src_dir = path.join(state.environment.get_source_dir(), state.subdir)
return [path.join(src_dir, d) for d in dirs]
@@ -80,7 +85,7 @@ class I18nModule(ExtensionModule):
@FeatureNew('i18n.merge_file', '0.37.0')
@FeatureNewKwargs('i18n.merge_file', '0.51.0', ['args'])
@permittedKwargs(build.CustomTarget.known_kwargs | {'data_dirs', 'po_dir', 'type', 'args'})
- def merge_file(self, state, args, kwargs):
+ def merge_file(self, state: 'ModuleState', args, kwargs) -> ModuleReturnValue:
if not shutil.which('xgettext'):
self.nogettext_warning()
return
@@ -134,7 +139,7 @@ class I18nModule(ExtensionModule):
@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'})
- def gettext(self, state, args, kwargs):
+ def gettext(self, state: 'ModuleState', args, kwargs) -> ModuleReturnValue:
if len(args) != 1:
raise coredata.MesonException('Gettext requires one positional argument (package name).')
if not shutil.which('xgettext'):
@@ -205,5 +210,5 @@ class I18nModule(ExtensionModule):
return ModuleReturnValue([gmotargets, pottarget, updatepotarget], targets)
-def initialize(*args, **kwargs):
- return I18nModule(*args, **kwargs)
+def initialize(interp: 'Interpreter') -> I18nModule:
+ return I18nModule(interp)