Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20422 -- Applied makemessage's --ignore patterns to full path

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...
commit 9012a9e2000020493b881a5b79cc801c62180796 1 parent 1d3d040
Baptiste Mispelon authored claudep committed
7  django/core/management/commands/makemessages.py
@@ -309,10 +309,9 @@ def is_ignored(path, ignore_patterns):
309 309
             """
310 310
             Check if the given path should be ignored or not.
311 311
             """
312  
-            for pattern in ignore_patterns:
313  
-                if fnmatch.fnmatchcase(path, pattern):
314  
-                    return True
315  
-            return False
  312
+            filename = os.path.basename(path)
  313
+            ignore = lambda pattern: fnmatch.fnmatchcase(filename, pattern)
  314
+            return any(ignore(pattern) for pattern in ignore_patterns)
316 315
 
317 316
         dir_suffix = '%s*' % os.sep
318 317
         norm_patterns = [p[:-len(dir_suffix)] if p.endswith(dir_suffix) else p for p in self.ignore_patterns]
9  tests/i18n/commands/extraction.py
@@ -279,17 +279,22 @@ class IgnoredExtractorTests(ExtractorTests):
279 279
 
280 280
     def test_ignore_option(self):
281 281
         os.chdir(self.test_dir)
282  
-        pattern1 = os.path.join('ignore_dir', '*')
  282
+        ignore_patterns = [
  283
+            os.path.join('ignore_dir', '*'),
  284
+            'xxx_*',
  285
+        ]
283 286
         stdout = StringIO()
284 287
         management.call_command('makemessages', locale=LOCALE, verbosity=2,
285  
-            ignore_patterns=[pattern1], stdout=stdout)
  288
+            ignore_patterns=ignore_patterns, stdout=stdout)
286 289
         data = stdout.getvalue()
287 290
         self.assertTrue("ignoring directory ignore_dir" in data)
  291
+        self.assertTrue("ignoring file xxx_ignored.html" in data)
288 292
         self.assertTrue(os.path.exists(self.PO_FILE))
289 293
         with open(self.PO_FILE, 'r') as fp:
290 294
             po_contents = fp.read()
291 295
             self.assertMsgId('This literal should be included.', po_contents)
292 296
             self.assertNotMsgId('This should be ignored.', po_contents)
  297
+            self.assertNotMsgId('This should be ignored too.', po_contents)
293 298
 
294 299
 
295 300
 class SymlinkExtractorTests(ExtractorTests):
2  tests/i18n/commands/templates/xxx_ignored.html
... ...
@@ -0,0 +1,2 @@
  1
+{% load i18n %}
  2
+{% trans "This should be ignored too." %}

0 notes on commit 9012a9e

Please sign in to comment.
Something went wrong with that request. Please try again.