'charset to use in the output file (default "utf-8")'),
('keywords=', 'k',
'space-separated list of keywords to look for in addition to the '
- 'defaults'),
+ 'defaults (may be repeated multiple times)'),
('no-default-keywords', None,
'do not include the default keywords'),
('mapping-file=', 'F',
'set project version in output'),
('add-comments=', 'c',
'place comment block with TAG (or those preceding keyword lines) in '
- 'output file. Separate multiple TAGs with commas(,)'),
+ 'output file. Separate multiple TAGs with commas(,)'), # TODO: Support repetition of this argument
('strip-comments', None,
'strip the comment TAGs from the comments.'),
('input-paths=', None,
'files or directories that should be scanned for messages. Separate multiple '
- 'files or directories with commas(,)'),
+ 'files or directories with commas(,)'), # TODO: Support repetition of this argument
('input-dirs=', None, # TODO (3.x): Remove me.
'alias for input-paths (does allow files as well as directories).'),
]
'sort-output', 'sort-by-file', 'strip-comments'
]
as_args = 'input-paths'
- multiple_value_options = ('add-comments',)
+ multiple_value_options = ('add-comments', 'keywords')
def initialize_options(self):
self.charset = 'utf-8'
- self.keywords = ''
- self._keywords = DEFAULT_KEYWORDS.copy()
+ self.keywords = None
self.no_default_keywords = False
self.mapping_file = None
self.no_location = False
'input-dirs and input-paths are mutually exclusive'
)
- if self.no_default_keywords and not self.keywords:
+ if self.no_default_keywords:
+ keywords = {}
+ else:
+ keywords = DEFAULT_KEYWORDS.copy()
+
+ for kwarg in (self.keywords or ()):
+ keywords.update(parse_keywords(kwarg.split()))
+
+ self.keywords = keywords
+
+ if not self.keywords:
raise DistutilsOptionError('you must specify new keywords if you '
'disable the default ones')
- if self.no_default_keywords:
- self._keywords = {}
- if self.keywords:
- self._keywords.update(parse_keywords(self.keywords.split()))
if not self.output_file:
raise DistutilsOptionError('no output file specified')
current_dir = os.getcwd()
extracted = check_and_call_extract_file(
path, method_map, options_map,
- callback, self._keywords, self.add_comments,
+ callback, self.keywords, self.add_comments,
self.strip_comments, current_dir
)
else:
extracted = extract_from_dir(
path, method_map, options_map,
- keywords=self._keywords,
+ keywords=self.keywords,
comment_tags=self.add_comments,
callback=callback,
strip_comment_tags=self.strip_comments
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://babel.edgewall.org/log/.
-
+import shlex
from datetime import datetime
from distutils.dist import Distribution
from distutils.errors import DistutilsOptionError
import time
import unittest
+import pytest
+
from babel import __version__ as VERSION
from babel.dates import format_datetime
from babel.messages import frontend, Catalog
+from babel.messages.frontend import CommandLineInterface, extract_messages
from babel.util import LOCALTZ
from babel.messages.pofile import read_po, write_po
from babel._compat import StringIO
'dngettext': (2, 3),
'pgettext': ((1, 'c'), 2),
}
+
+
+@pytest.mark.parametrize("split", (False, True))
+def test_extract_keyword_args_384(split):
+ # This is a regression test for https://github.com/python-babel/babel/issues/384
+
+ kwarg_specs = [
+ "gettext_noop",
+ "gettext_lazy",
+ "ngettext_lazy:1,2",
+ "ugettext_noop",
+ "ugettext_lazy",
+ "ungettext_lazy:1,2",
+ "pgettext_lazy:1c,2",
+ "npgettext_lazy:1c,2,3",
+ ]
+
+ if split: # Generate a command line with multiple -ks
+ kwarg_text = " ".join("-k %s" % kwarg_spec for kwarg_spec in kwarg_specs)
+ else: # Generate a single space-separated -k
+ kwarg_text = "-k \"%s\"" % " ".join(kwarg_specs)
+
+ # (Both of those invocation styles should be equivalent, so there is no parametrization from here on out)
+
+ cmdline = "extract -F babel-django.cfg --add-comments Translators: -o django232.pot %s ." % kwarg_text
+
+ args = shlex.split(cmdline)
+ cli = CommandLineInterface()
+ cmdinst = cli._configure_command(cmdname=args[0], argv=args[1:])
+ assert isinstance(cmdinst, extract_messages)
+ assert set(cmdinst.keywords.keys()) == set((
+ '_',
+ 'dgettext',
+ 'dngettext',
+ 'gettext',
+ 'gettext_lazy',
+ 'gettext_noop',
+ 'N_',
+ 'ngettext',
+ 'ngettext_lazy',
+ 'npgettext',
+ 'npgettext_lazy',
+ 'pgettext',
+ 'pgettext_lazy',
+ 'ugettext',
+ 'ugettext_lazy',
+ 'ugettext_noop',
+ 'ungettext',
+ 'ungettext_lazy',
+ ))