[damned-lies] Read and use `args` parameters from meson.build gettext calls
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Read and use `args` parameters from meson.build gettext calls
- Date: Wed, 21 Feb 2018 14:05:37 +0000 (UTC)
commit 720a991b728d35c91c2ea8d54dc91572d0677afc
Author: Claude Paroz <claude 2xlibre net>
Date: Wed Feb 21 15:03:45 2018 +0100
Read and use `args` parameters from meson.build gettext calls
stats/models.py | 48 +++++++++++++++++++++++--------------------
stats/tests/meson-ui.build | 3 +-
stats/tests/tests.py | 7 +++--
stats/utils.py | 32 +++++++++++++++++-----------
4 files changed, 51 insertions(+), 39 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index ef756ce..ca59ddd 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -835,28 +835,32 @@ class Domain(models.Model):
pot_command.extend(kwds_vars.split())
else:
makefile = utils.MakefileWrapper.find_file([vcs_path], file_name='meson.build')
- if makefile and makefile.read_variable('preset') == 'glib':
- # These args should be kept in sync with
- # https://github.com/mesonbuild/meson/blob/master/mesonbuild/modules/i18n.py#L25
- pot_command.extend([
- '--keyword=_',
- '--keyword=N_',
- '--keyword=C_:1c,2',
- '--keyword=NC_:1c,2',
- '--keyword=g_dcgettext:2',
- '--keyword=g_dngettext:2,3',
- '--keyword=g_dpgettext2:2c,3',
-
- '--flag=N_:1:pass-c-format',
- '--flag=C_:2:pass-c-format',
- '--flag=NC_:2:pass-c-format',
- '--flag=g_dngettext:2:pass-c-format',
- '--flag=g_strdup_printf:1:c-format',
- '--flag=g_string_printf:2:c-format',
- '--flag=g_string_append_printf:2:c-format',
- '--flag=g_error_new:3:c-format',
- '--flag=g_set_error:4:c-format',
- ])
+ if makefile:
+ if makefile.read_variable('gettext.preset') == 'glib':
+ # These args should be kept in sync with
+ # https://github.com/mesonbuild/meson/blob/master/mesonbuild/modules/i18n.py#L25
+ pot_command.extend([
+ '--keyword=_',
+ '--keyword=N_',
+ '--keyword=C_:1c,2',
+ '--keyword=NC_:1c,2',
+ '--keyword=g_dcgettext:2',
+ '--keyword=g_dngettext:2,3',
+ '--keyword=g_dpgettext2:2c,3',
+
+ '--flag=N_:1:pass-c-format',
+ '--flag=C_:2:pass-c-format',
+ '--flag=NC_:2:pass-c-format',
+ '--flag=g_dngettext:2:pass-c-format',
+ '--flag=g_strdup_printf:1:c-format',
+ '--flag=g_string_printf:2:c-format',
+ '--flag=g_string_append_printf:2:c-format',
+ '--flag=g_error_new:3:c-format',
+ '--flag=g_set_error:4:c-format',
+ ])
+ extra_args = makefile.read_variable('gettext.args')
+ if extra_args:
+ pot_command.extend(extra_args)
# Added last as some chars in it may disturb CLI parsing
bugs_url = self.module.get_bugs_enter_url()
if bugs_url:
diff --git a/stats/tests/meson-ui.build b/stats/tests/meson-ui.build
index 0e920d0..f233869 100644
--- a/stats/tests/meson-ui.build
+++ b/stats/tests/meson-ui.build
@@ -4,5 +4,6 @@ if get_option('plugin_uefi_labels')
meson.add_install_script('make-images.sh')
endif
-i18n.gettext(gnomebt_gettext_package + meson.project_name(), preset : 'glib')
+i18n.gettext(gnomebt_gettext_package + meson.project_name(), preset : 'glib',
+ args: [ '--keyword=Description' ])
install_data('Makefile.in.in')
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index a81423e..691c7bd 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -547,15 +547,16 @@ class UtilsTests(TestCase):
def test_read_meson_variables(self):
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "help_mallard")
meson_file = utils.MakefileWrapper.find_file([path], file_name='meson.build')
- self.assertEqual(meson_file.read_variable('languages'), ['es', 'fr'])
+ self.assertEqual(meson_file.read_variable('yelp.languages'), ['es', 'fr'])
self.assertEqual(
- meson_file.read_variable('sources'),
+ meson_file.read_variable('yelp.sources'),
['index.page', 'what-is.page', 'legal.xml']
)
# UI meson file
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'meson-ui.build')
meson_file = utils.MesonfileWrapper(path)
- self.assertEqual(meson_file.read_variable('preset'), 'glib')
+ self.assertEqual(meson_file.read_variable('gettext.preset'), 'glib')
+ self.assertEqual(meson_file.read_variable('gettext.args'), ['--keyword=Description'])
def test_read_cmake_variables(self):
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "help_mallard")
diff --git a/stats/utils.py b/stats/utils.py
index 5c48e17..415f715 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -56,7 +56,7 @@ class DocFormat:
@property
def module_var(self):
if self.use_meson:
- return "project_id"
+ return "yelp.project_id"
elif self.tool == "itstool":
return "HELP_ID"
elif self.format == "mallard":
@@ -67,7 +67,7 @@ class DocFormat:
@property
def include_var(self):
if self.use_meson:
- return "sources"
+ return "yelp.sources"
if self.tool == "itstool":
return "HELP_FILES"
elif self.format == "mallard":
@@ -176,23 +176,24 @@ class MesonfileWrapper(MakefileWrapper):
content = content.replace('true', 'True').replace('false', 'False').replace("i18n = import('i18n')",
'')
return content
- def read_variable(self, *variables):
- if self.content is None:
- return None
+ @cached_property
+ def _parsed_variables(self):
catched = {}
+ if self.content is None:
+ return catched
class VarCatcher:
def yelp(self, *args, **kwargs):
- catched['project_id'] = args[0]
+ catched['yelp.project_id'] = args[0]
for var_name in {'sources', 'languages'}:
if var_name in kwargs:
- catched[var_name] = kwargs[var_name]
+ catched['yelp.%s' % var_name] = kwargs[var_name]
def gettext(self, *args, **kwargs):
- catched['project_id'] = args[0]
+ catched['gettext.project_id'] = args[0]
for var_name in {'languages', 'args', 'preset'}:
if var_name in kwargs:
- catched[var_name] = kwargs[var_name]
+ catched['gettext.%s' % var_name] = kwargs[var_name]
catcher = VarCatcher()
meson_locals = {
@@ -213,9 +214,14 @@ class MesonfileWrapper(MakefileWrapper):
break
except Exception:
break
+ return catched
+
+ def read_variable(self, *variables):
+ """Return the value of the first found variable name in the variables list."""
+ parsed_vars = self._parsed_variables
for var in variables:
- if var in catched and not isinstance(catched[var], MagicMock):
- return catched[var]
+ if var in parsed_vars and not isinstance(parsed_vars[var], MagicMock):
+ return parsed_vars[var]
class CMakefileWrapper(MakefileWrapper):
@@ -360,7 +366,7 @@ def generate_doc_pot_file(vcs_path, potbase, moduleid):
)
return "", errors, None
- doc_id = makefile.read_variable("HELP_ID", "project_id")
+ doc_id = makefile.read_variable("HELP_ID", "yelp.project_id")
uses_itstool = doc_id is not None or isinstance(makefile, MesonfileWrapper)
all_C_files = os.listdir(os.path.join(vcs_path, "C"))
has_page_files = any(f.endswith('.page') for f in all_C_files)
@@ -564,7 +570,7 @@ def get_doc_linguas(module_path, po_path):
linguas = None
linguas_file = MakefileWrapper.find_file([po_path, module_path])
if linguas_file:
- linguas = linguas_file.read_variable("DOC_LINGUAS", "HELP_LINGUAS", "languages")
+ linguas = linguas_file.read_variable("DOC_LINGUAS", "HELP_LINGUAS", "gettext.languages")
if linguas is None:
return {'langs':None,
'error': ugettext_noop("Don’t know where to look for the DOC_LINGUAS variable, ask the
module maintainer.") }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]