Skip to content

Commit 28efafa

Browse files
committed
Ignored STATIC_ROOT and MEDIA_ROOT in makemessages
Also alleviate issues with weird file names typically found in MEDIA_ROOT directories (#23010). Thanks Tim Graham for the review.
1 parent 0154965 commit 28efafa

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

django/core/management/commands/makemessages.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from itertools import dropwhile
1010

1111
import django
12+
from django.conf import settings
1213
from django.core.management.base import CommandError, BaseCommand
1314
from django.core.management.utils import (handle_extensions, find_command,
1415
popen_wrapper)
@@ -56,8 +57,6 @@ def process(self, command, domain):
5657
5758
Uses the xgettext GNU gettext utility.
5859
"""
59-
60-
from django.conf import settings
6160
from django.utils.translation import templatize
6261

6362
if command.verbosity > 1:
@@ -218,9 +217,20 @@ def handle(self, *args, **options):
218217
process_all = options.get('all')
219218
extensions = options.get('extensions')
220219
self.symlinks = options.get('symlinks')
220+
221+
# Need to ensure that the i18n framework is enabled
222+
if settings.configured:
223+
settings.USE_I18N = True
224+
else:
225+
settings.configure(USE_I18N=True)
226+
221227
ignore_patterns = options.get('ignore_patterns')
222228
if options.get('use_default_ignore_patterns'):
223229
ignore_patterns += ['CVS', '.*', '*~', '*.pyc']
230+
base_path = os.path.abspath('.')
231+
for path in (settings.MEDIA_ROOT, settings.STATIC_ROOT):
232+
if path and path.startswith(base_path):
233+
ignore_patterns.append('%s*' % path[len(base_path) + 1:])
224234
self.ignore_patterns = list(set(ignore_patterns))
225235

226236
# Avoid messing with mutable class variables
@@ -251,13 +261,6 @@ def handle(self, *args, **options):
251261
raise CommandError("Type '%s help %s' for usage information." % (
252262
os.path.basename(sys.argv[0]), sys.argv[1]))
253263

254-
# Need to ensure that the i18n framework is enabled
255-
from django.conf import settings
256-
if settings.configured:
257-
settings.USE_I18N = True
258-
else:
259-
settings.configure(USE_I18N=True)
260-
261264
if self.verbosity > 1:
262265
self.stdout.write('examining files with the extensions: %s\n'
263266
% get_text_list(list(self.extensions), 'and'))

tests/i18n/test_extraction.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525

2626
LOCALE = 'de'
2727
has_xgettext = find_command('xgettext')
28+
this_directory = os.path.dirname(upath(__file__))
2829

2930

3031
@skipUnless(has_xgettext, 'xgettext is mandatory for extraction tests')
3132
class ExtractorTests(SimpleTestCase):
3233

33-
test_dir = os.path.abspath(os.path.join(os.path.dirname(upath(__file__)), 'commands'))
34+
test_dir = os.path.abspath(os.path.join(this_directory, 'commands'))
3435

3536
PO_FILE = 'locale/%s/LC_MESSAGES/django.po' % LOCALE
3637

@@ -378,6 +379,17 @@ def test_ignore_option(self):
378379
self.assertNotMsgId('This should be ignored.', po_contents)
379380
self.assertNotMsgId('This should be ignored too.', po_contents)
380381

382+
@override_settings(
383+
STATIC_ROOT=os.path.join(this_directory, 'commands', 'static_root/'),
384+
MEDIA_ROOT=os.path.join(this_directory, 'commands', 'media_root/'))
385+
def test_media_static_dirs_ignored(self):
386+
os.chdir(self.test_dir)
387+
stdout = StringIO()
388+
management.call_command('makemessages', locale=[LOCALE], verbosity=2, stdout=stdout)
389+
data = stdout.getvalue()
390+
self.assertIn("ignoring directory static_root", data)
391+
self.assertIn("ignoring directory media_root", data)
392+
381393

382394
class SymlinkExtractorTests(ExtractorTests):
383395

@@ -550,7 +562,7 @@ class ExcludedLocaleExtractionTests(ExtractorTests):
550562
LOCALES = ['en', 'fr', 'it']
551563
PO_FILE = 'locale/%s/LC_MESSAGES/django.po'
552564

553-
test_dir = os.path.abspath(os.path.join(os.path.dirname(upath(__file__)), 'exclude'))
565+
test_dir = os.path.abspath(os.path.join(this_directory, 'exclude'))
554566

555567
def _set_times_for_all_po_files(self):
556568
"""
@@ -608,7 +620,7 @@ class CustomLayoutExtractionTests(ExtractorTests):
608620

609621
def setUp(self):
610622
self._cwd = os.getcwd()
611-
self.test_dir = os.path.join(os.path.dirname(upath(__file__)), 'project_dir')
623+
self.test_dir = os.path.join(this_directory, 'project_dir')
612624

613625
def test_no_locale_raises(self):
614626
os.chdir(self.test_dir)
@@ -618,7 +630,7 @@ def test_no_locale_raises(self):
618630

619631
@override_settings(
620632
LOCALE_PATHS=(os.path.join(
621-
os.path.dirname(upath(__file__)), 'project_dir', 'project_locale'),)
633+
this_directory, 'project_dir', 'project_locale'),)
622634
)
623635
def test_project_locale_paths(self):
624636
"""

0 commit comments

Comments
 (0)