New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i18n: Introduce i18n.files() metedata wrapper #1757
base: master
Are you sure you want to change the base?
Conversation
mesonbuild/modules/i18n.py
Outdated
|
||
from os import path | ||
from .. import coredata, mesonlib, build | ||
from ..mesonlib import MesonException | ||
from . import ModuleReturnValue | ||
from . import ExtensionModule | ||
from ..interpreterbase import InterpreterObject, MutableInterpreterObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [F401] '..interpreterbase.MutableInterpreterObject' imported but unused
mesonbuild/modules/i18n.py
Outdated
'--add-comments', | ||
'none': { | ||
'args': [], | ||
'keywords' : [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E203] whitespace before ':'
mesonbuild/modules/i18n.py
Outdated
'--flag=g_error_new:3:c-format', | ||
'--flag=g_set_error:4:c-format', | ||
] | ||
'keywords' : [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E203] whitespace before ':'
mesonbuild/modules/i18n.py
Outdated
|
||
def _get_preset(self, kwargs): | ||
preset = kwargs.pop('preset', self.preset) | ||
if not preset in PRESET_ARGS: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E713] test for membership should be 'not in'
mesonbuild/modules/i18n.py
Outdated
self.datadirs = I18nModule._get_data_dirs(self.environment, self.subdir, mesonlib.stringlistify(kwargs.get('data_dirs', []))) | ||
|
||
self.preset = kwargs.pop('preset', 'none') | ||
if not self.preset in PRESET_ARGS: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E713] test for membership should be 'not in'
mesonbuild/modules/i18n.py
Outdated
preset = self._get_preset(kwargs) | ||
|
||
files = { | ||
'files': [ path.join(self.interpreter.subdir, f) for f in args ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E201] whitespace after '['
- [E202] whitespace before ']'
mesonbuild/modules/i18n.py
Outdated
datadirs = '--datadirs=' + ':'.join(self.datadirs) if self.datadirs else None | ||
pot_data_file = None | ||
extra_args = None | ||
preset = self._get_preset(kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [F841] local variable 'preset' is assigned to but never used
mesonbuild/modules/i18n.py
Outdated
extra_args = set(preset_args + extra_args) | ||
preset = PRESET_ARGS.get(preset) | ||
extra_args = set(preset['args'] + | ||
[ '--keyword=' + k for k in preset['keywords'] ] + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E201] whitespace after '['
- [E202] whitespace before ']'
mesonbuild/modules/i18n.py
Outdated
preset = PRESET_ARGS.get(preset) | ||
extra_args = set(preset['args'] + | ||
[ '--keyword=' + k for k in preset['keywords'] ] + | ||
[ '--flag=' + f for f in preset['flags'] ] + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E201] whitespace after '['
- [E202] whitespace before ']'
mesonbuild/scripts/gettext.py
Outdated
if datafilename: | ||
with open(datafilename, 'rb') as ifile: | ||
files = pickle.load(ifile) | ||
tmp_pot = os.path.join(os.path.dirname(datafilename), 'i18n-' + pkgname + '.pot') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E221] multiple spaces before operator
mesonbuild/scripts/gettext.py
Outdated
os.remove(tmp_pot) | ||
join_arg = [] | ||
for f in files: | ||
language = [ '--language=' + f['language'] ] if 'language' in f else [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E201] whitespace after '['
- [E202] whitespace before ']'
mesonbuild/scripts/gettext.py
Outdated
join_arg = [] | ||
for f in files: | ||
language = [ '--language=' + f['language'] ] if 'language' in f else [] | ||
keywords = [ '--keyword=' + k for k in f['keywords'] ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E201] whitespace after '['
- [E202] whitespace before ']'
mesonbuild/scripts/gettext.py
Outdated
for f in files: | ||
language = [ '--language=' + f['language'] ] if 'language' in f else [] | ||
keywords = [ '--keyword=' + k for k in f['keywords'] ] | ||
flags = [ '--flag=' + f for f in f['flags'] ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E201] whitespace after '['
- [E202] whitespace before ']'
mesonbuild/scripts/gettext.py
Outdated
keywords = [ '--keyword=' + k for k in f['keywords'] ] | ||
flags = [ '--flag=' + f for f in f['flags'] ] | ||
subprocess.check_call(['xgettext', '--package-name=' + pkgname, '-p', src_sub, | ||
'-D', os.environ['MESON_SOURCE_ROOT'], '-o', tmp_pot] + join_arg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E128] continuation line under-indented for visual indent
mesonbuild/scripts/gettext.py
Outdated
flags = [ '--flag=' + f for f in f['flags'] ] | ||
subprocess.check_call(['xgettext', '--package-name=' + pkgname, '-p', src_sub, | ||
'-D', os.environ['MESON_SOURCE_ROOT'], '-o', tmp_pot] + join_arg | ||
+ language + keywords + flags + f['extra_args'] + f['files'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [W503] line break before binary operator
- [E128] continuation line under-indented for visual indent
mesonbuild/scripts/gettext.py
Outdated
subprocess.check_call(['xgettext', '--package-name=' + pkgname, '-p', src_sub, | ||
'-D', os.environ['MESON_SOURCE_ROOT'], '-o', tmp_pot] + join_arg | ||
+ language + keywords + flags + f['extra_args'] + f['files'], | ||
env=child_env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E128] continuation line under-indented for visual indent
mesonbuild/scripts/gettext.py
Outdated
+ language + keywords + flags + f['extra_args'] + f['files'], | ||
env=child_env) | ||
if os.path.exists(tmp_pot): | ||
join_arg = [ '-j' ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E201] whitespace after '['
- [E202] whitespace before ']'
It's unfortunate that the user has to write |
666a6c2
to
7ae132c
Compare
mesonbuild/modules/i18n.py
Outdated
datadirs = '--datadirs=' + ':'.join(self.datadirs) if self.datadirs else None | ||
pot_data_file = None | ||
extra_args = None | ||
preset = self._get_preset(kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [F841] local variable 'preset' is assigned to but never used
mesonbuild/scripts/gettext.py
Outdated
flags = ['--flag=' + f for f in f['flags']] | ||
subprocess.check_call(['xgettext', '--package-name=' + pkgname, '-p', src_sub, | ||
'-D', os.environ['MESON_SOURCE_ROOT'], '-o', tmp_pot] + join_arg + | ||
language + keywords + flags + f['extra_args'] + f['files'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [E127] continuation line over-indented for visual indent
|
Codecov Report
@@ Coverage Diff @@
## master #1757 +/- ##
==========================================
- Coverage 63.84% 63.82% -0.02%
==========================================
Files 71 71
Lines 17086 17238 +152
Branches 3517 3556 +39
==========================================
+ Hits 10908 11002 +94
- Misses 5098 5137 +39
- Partials 1080 1099 +19
Continue to review full report at Codecov.
|
docs/markdown/i18n-module.md
Outdated
pot.add_merge_files(*file1*, *file2*, ...) | ||
``` | ||
|
||
This method is a shortcut to `pot.add_files()` then `pot.merge_files()` on a set of files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a case when you want merge_files()
but never to add them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not me, but there is i18n.merge_file()
and you’re not forced to call i18n.gettext()
so I just wanted to keep that option.
Also, you cannot use extra_args
iwth pot.add_merge_files()
because there is no way to know which are for the xgettext
call and which are for the msgfmt
call. Since I wanted to keep extra_args
as the standard name, and not having xgettext_extra_args
and msgfmt_extra_args
, this is the simplest way.
Just let me know what you prefer I’ll happily rework the code to fit. :-)
Btw, should I write (a) new test(s) or add to the existing one? |
Whatever feels most natural to you. |
7ae132c
to
f3ad0a5
Compare
⚔️ conflicts. Also needs a mention in release notes. |
f3ad0a5
to
578af85
Compare
This goes against the grain of current design of not using mutable objects. Mutating methods are not nice. Could this be converted behave like other parts do is to have |
That would require more than just |
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
578af85
to
1d8f69e
Compare
mesonbuild/modules/i18n.py
Outdated
elif isinstance(f, mesonlib.File): | ||
files.append(f) | ||
elif isinstance(f, list): | ||
files += self._flatten_files(f, source_dir, subdir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [F821] undefined name 'self'
mesonbuild/modules/i18n.py
Outdated
|
||
MERGE_LANGUAGES = ('xml', 'desktop') | ||
if self.language not in MERGE_LANGUAGES: | ||
raise MesonException('i18n: "{}" is not a valid merge language {}'.format(language, MERGE_LANGUAGES)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [F821] undefined name 'language'
mesonbuild/modules/i18n.py
Outdated
elif isinstance(f, mesonlib.File): | ||
files.append(f) | ||
elif isinstance(f, list): | ||
r = self._flatten_files(f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8]
- [F821] undefined name 'self'
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
1d8f69e
to
cd1802f
Compare
New design, you now create files object, containing a list of files and metadata, then pass all of them to As said on IRC, there is still an issue, I generate the |
As a side note: |
This is definitely better. But how about doing the encapsulation slightly differently:
This would mirror the way |
I thought objects where immutable? And that you didn’t like the “it needs final
FTR, the first design was: |
FWIW, I like the 'associate metadata with files' design. We might need this for more things in the future, so it is a good precedent. For instance, currently we guess the file type based on the extension throughout meson, but some day we may need to change that. |
Christ on a Cracker. Please close ancient pull-requests like this one. Either it is still relevant and should be merged (possibly with changes) or it is irrelevant and should be rejected. |
IMHO, it is still relevant, even though I didn’t have time to keep it up to date |
Why does one need per-file gettext flags? Meson's design has been to not permit those in general, because they add a lot of complexity in both implementing the feature and to build files (i.e. the "where do these unexpected flags in my invocations come from, I never specify them" problem). |
It is less per-file as it is per-language |
This would “fix” #1733, #1739 and replace #1630.
It is still RFC as the code is not completely clean and maybe not up to Meson standards (at least the test part).
Would that be an acceptable design?