Skip to content

Commit

Permalink
Fixed #20422 -- Applied makemessage's --ignore patterns to full path
Browse files Browse the repository at this point in the history
Fix makemessage's --ignore patterns being applied to the full path
instead of the file name. Thanks to nnseva for the report and the
original patch.
  • Loading branch information
bmispelon authored and claudep committed May 18, 2013
1 parent 1d3d040 commit 9012a9e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 3 additions & 4 deletions django/core/management/commands/makemessages.py
Expand Up @@ -309,10 +309,9 @@ def is_ignored(path, ignore_patterns):
""" """
Check if the given path should be ignored or not. Check if the given path should be ignored or not.
""" """
for pattern in ignore_patterns: filename = os.path.basename(path)
if fnmatch.fnmatchcase(path, pattern): ignore = lambda pattern: fnmatch.fnmatchcase(filename, pattern)
return True return any(ignore(pattern) for pattern in ignore_patterns)
return False


dir_suffix = '%s*' % os.sep dir_suffix = '%s*' % os.sep
norm_patterns = [p[:-len(dir_suffix)] if p.endswith(dir_suffix) else p for p in self.ignore_patterns] norm_patterns = [p[:-len(dir_suffix)] if p.endswith(dir_suffix) else p for p in self.ignore_patterns]
Expand Down
9 changes: 7 additions & 2 deletions tests/i18n/commands/extraction.py
Expand Up @@ -279,17 +279,22 @@ class IgnoredExtractorTests(ExtractorTests):


def test_ignore_option(self): def test_ignore_option(self):
os.chdir(self.test_dir) os.chdir(self.test_dir)
pattern1 = os.path.join('ignore_dir', '*') ignore_patterns = [
os.path.join('ignore_dir', '*'),
'xxx_*',
]
stdout = StringIO() stdout = StringIO()
management.call_command('makemessages', locale=LOCALE, verbosity=2, management.call_command('makemessages', locale=LOCALE, verbosity=2,
ignore_patterns=[pattern1], stdout=stdout) ignore_patterns=ignore_patterns, stdout=stdout)
data = stdout.getvalue() data = stdout.getvalue()
self.assertTrue("ignoring directory ignore_dir" in data) self.assertTrue("ignoring directory ignore_dir" in data)
self.assertTrue("ignoring file xxx_ignored.html" in data)
self.assertTrue(os.path.exists(self.PO_FILE)) self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp: with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read() po_contents = fp.read()
self.assertMsgId('This literal should be included.', po_contents) self.assertMsgId('This literal should be included.', po_contents)
self.assertNotMsgId('This should be ignored.', po_contents) self.assertNotMsgId('This should be ignored.', po_contents)
self.assertNotMsgId('This should be ignored too.', po_contents)




class SymlinkExtractorTests(ExtractorTests): class SymlinkExtractorTests(ExtractorTests):
Expand Down
2 changes: 2 additions & 0 deletions tests/i18n/commands/templates/xxx_ignored.html
@@ -0,0 +1,2 @@
{% load i18n %}
{% trans "This should be ignored too." %}

0 comments on commit 9012a9e

Please sign in to comment.