mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #23583 -- More selectively ignored static/media roots
Fixed a regression introduced by 28efafa24c.
Thanks Michal Čihař for the report and initial patch, and
Collin Anderson and Tim Graham for the reviews.
			
			
This commit is contained in:
		| @@ -227,10 +227,6 @@ class Command(BaseCommand): | |||||||
|         ignore_patterns = options.get('ignore_patterns') |         ignore_patterns = options.get('ignore_patterns') | ||||||
|         if options.get('use_default_ignore_patterns'): |         if options.get('use_default_ignore_patterns'): | ||||||
|             ignore_patterns += ['CVS', '.*', '*~', '*.pyc'] |             ignore_patterns += ['CVS', '.*', '*~', '*.pyc'] | ||||||
|         base_path = os.path.abspath('.') |  | ||||||
|         for path in (settings.MEDIA_ROOT, settings.STATIC_ROOT): |  | ||||||
|             if path and path.startswith(base_path): |  | ||||||
|                 ignore_patterns.append('%s*' % path[len(base_path) + 1:]) |  | ||||||
|         self.ignore_patterns = list(set(ignore_patterns)) |         self.ignore_patterns = list(set(ignore_patterns)) | ||||||
|  |  | ||||||
|         # Avoid messing with mutable class variables |         # Avoid messing with mutable class variables | ||||||
| @@ -376,9 +372,11 @@ class Command(BaseCommand): | |||||||
|                 norm_patterns.append(p) |                 norm_patterns.append(p) | ||||||
|  |  | ||||||
|         all_files = [] |         all_files = [] | ||||||
|  |         ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT)] | ||||||
|         for dirpath, dirnames, filenames in os.walk(root, topdown=True, followlinks=self.symlinks): |         for dirpath, dirnames, filenames in os.walk(root, topdown=True, followlinks=self.symlinks): | ||||||
|             for dirname in dirnames[:]: |             for dirname in dirnames[:]: | ||||||
|                 if is_ignored(os.path.normpath(os.path.join(dirpath, dirname)), norm_patterns): |                 if (is_ignored(os.path.normpath(os.path.join(dirpath, dirname)), norm_patterns) or | ||||||
|  |                         os.path.join(os.path.abspath(dirpath), dirname) in ignored_roots): | ||||||
|                     dirnames.remove(dirname) |                     dirnames.remove(dirname) | ||||||
|                     if self.verbosity > 1: |                     if self.verbosity > 1: | ||||||
|                         self.stdout.write('ignoring directory %s\n' % dirname) |                         self.stdout.write('ignoring directory %s\n' % dirname) | ||||||
|   | |||||||
| @@ -132,3 +132,6 @@ Bugfixes | |||||||
|  |  | ||||||
| * Fixed a regression when feeding the Django test client with an empty data | * Fixed a regression when feeding the Django test client with an empty data | ||||||
|   string (:ticket:`21740`). |   string (:ticket:`21740`). | ||||||
|  |  | ||||||
|  | * Fixed a regression in :djadmin:`makemessages` where static files were | ||||||
|  |   unexpectedly ignored (:ticket:`23583`). | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								tests/i18n/commands/someapp/static/javascript.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/i18n/commands/someapp/static/javascript.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | gettext('Static content inside app should be included.') | ||||||
							
								
								
									
										1
									
								
								tests/i18n/commands/static/javascript_ignored.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/i18n/commands/static/javascript_ignored.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | gettext('Content from STATIC_ROOT should not be included.') | ||||||
| @@ -55,6 +55,17 @@ class ExtractorTests(SimpleTestCase): | |||||||
|             pass |             pass | ||||||
|         os.chdir(self._cwd) |         os.chdir(self._cwd) | ||||||
|  |  | ||||||
|  |     def _run_makemessages(self, **options): | ||||||
|  |         os.chdir(self.test_dir) | ||||||
|  |         stdout = StringIO() | ||||||
|  |         management.call_command('makemessages', locale=[LOCALE], verbosity=2, | ||||||
|  |             stdout=stdout, **options) | ||||||
|  |         output = stdout.getvalue() | ||||||
|  |         self.assertTrue(os.path.exists(self.PO_FILE)) | ||||||
|  |         with open(self.PO_FILE, 'r') as fp: | ||||||
|  |             po_contents = fp.read() | ||||||
|  |         return output, po_contents | ||||||
|  |  | ||||||
|     def assertMsgId(self, msgid, s, use_quotes=True): |     def assertMsgId(self, msgid, s, use_quotes=True): | ||||||
|         q = '"' |         q = '"' | ||||||
|         if use_quotes: |         if use_quotes: | ||||||
| @@ -339,10 +350,7 @@ class JavascriptExtractorTests(ExtractorTests): | |||||||
|  |  | ||||||
|     def test_javascript_literals(self): |     def test_javascript_literals(self): | ||||||
|         os.chdir(self.test_dir) |         os.chdir(self.test_dir) | ||||||
|         management.call_command('makemessages', domain='djangojs', locale=[LOCALE], verbosity=0) |         _, po_contents = self._run_makemessages(domain='djangojs') | ||||||
|         self.assertTrue(os.path.exists(self.PO_FILE)) |  | ||||||
|         with open(self.PO_FILE, 'r') as fp: |  | ||||||
|             po_contents = fp.read() |  | ||||||
|         self.assertMsgId('This literal should be included.', po_contents) |         self.assertMsgId('This literal should be included.', po_contents) | ||||||
|         self.assertMsgId('This one as well.', po_contents) |         self.assertMsgId('This one as well.', po_contents) | ||||||
|         self.assertMsgId(r'He said, \"hello\".', po_contents) |         self.assertMsgId(r'He said, \"hello\".', po_contents) | ||||||
| @@ -357,20 +365,20 @@ class JavascriptExtractorTests(ExtractorTests): | |||||||
|         self.assertMsgId("quz", po_contents) |         self.assertMsgId("quz", po_contents) | ||||||
|         self.assertMsgId("foobar", po_contents) |         self.assertMsgId("foobar", po_contents) | ||||||
|  |  | ||||||
|  |     @override_settings( | ||||||
|  |         STATIC_ROOT=os.path.join(this_directory, 'commands', 'static/'), | ||||||
|  |         MEDIA_ROOT=os.path.join(this_directory, 'commands', 'media_root/')) | ||||||
|  |     def test_media_static_dirs_ignored(self): | ||||||
|  |         """ | ||||||
|  |         Regression test for #23583. | ||||||
|  |         """ | ||||||
|  |         _, po_contents = self._run_makemessages(domain='djangojs') | ||||||
|  |         self.assertMsgId("Static content inside app should be included.", po_contents) | ||||||
|  |         self.assertNotMsgId("Content from STATIC_ROOT should not be included", po_contents) | ||||||
|  |  | ||||||
|  |  | ||||||
| class IgnoredExtractorTests(ExtractorTests): | class IgnoredExtractorTests(ExtractorTests): | ||||||
|  |  | ||||||
|     def _run_makemessages(self, **options): |  | ||||||
|         os.chdir(self.test_dir) |  | ||||||
|         stdout = StringIO() |  | ||||||
|         management.call_command('makemessages', locale=[LOCALE], verbosity=2, |  | ||||||
|             stdout=stdout, **options) |  | ||||||
|         data = stdout.getvalue() |  | ||||||
|         self.assertTrue(os.path.exists(self.PO_FILE)) |  | ||||||
|         with open(self.PO_FILE, 'r') as fp: |  | ||||||
|             po_contents = fp.read() |  | ||||||
|         return data, po_contents |  | ||||||
|  |  | ||||||
|     def test_ignore_directory(self): |     def test_ignore_directory(self): | ||||||
|         out, po_contents = self._run_makemessages(ignore_patterns=[ |         out, po_contents = self._run_makemessages(ignore_patterns=[ | ||||||
|             os.path.join('ignore_dir', '*'), |             os.path.join('ignore_dir', '*'), | ||||||
| @@ -395,11 +403,11 @@ class IgnoredExtractorTests(ExtractorTests): | |||||||
|         self.assertNotMsgId('This should be ignored too.', po_contents) |         self.assertNotMsgId('This should be ignored too.', po_contents) | ||||||
|  |  | ||||||
|     @override_settings( |     @override_settings( | ||||||
|         STATIC_ROOT=os.path.join(this_directory, 'commands', 'static_root/'), |         STATIC_ROOT=os.path.join(this_directory, 'commands', 'static/'), | ||||||
|         MEDIA_ROOT=os.path.join(this_directory, 'commands', 'media_root/')) |         MEDIA_ROOT=os.path.join(this_directory, 'commands', 'media_root/')) | ||||||
|     def test_media_static_dirs_ignored(self): |     def test_media_static_dirs_ignored(self): | ||||||
|         out, _ = self._run_makemessages() |         out, _ = self._run_makemessages() | ||||||
|         self.assertIn("ignoring directory static_root", out) |         self.assertIn("ignoring directory static", out) | ||||||
|         self.assertIn("ignoring directory media_root", out) |         self.assertIn("ignoring directory media_root", out) | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user