summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-10-18 12:00:38 +0200
committerClaude Paroz <claude@2xlibre.net>2014-10-21 20:20:26 +0200
commitd5a273eadb00ee3edd7e81d373b7237220b42571 (patch)
treeb85fd439fca306d54cb28aef52e75c0ff67b3631
parent53bc81dca3d785d0b399cacbf84cc660355895fc (diff)
[1.7.x] 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. Backport of 8b4cc9df9c from master.
-rw-r--r--django/core/management/commands/makemessages.py8
-rw-r--r--docs/releases/1.7.1.txt3
-rw-r--r--tests/i18n/commands/someapp/static/javascript.js1
-rw-r--r--tests/i18n/commands/static/javascript_ignored.js1
-rw-r--r--tests/i18n/commands/static/static_ignored.html (renamed from tests/i18n/commands/static_root/static_ignored.html)0
-rw-r--r--tests/i18n/test_extraction.py68
6 files changed, 46 insertions, 35 deletions
diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
index c3a291bf4f..2e6ac3d839 100644
--- a/django/core/management/commands/makemessages.py
+++ b/django/core/management/commands/makemessages.py
@@ -216,10 +216,6 @@ class Command(NoArgsCommand):
ignore_patterns = options.get('ignore_patterns')
if options.get('use_default_ignore_patterns'):
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))
# Avoid messing with mutable class variables
@@ -359,9 +355,11 @@ class Command(NoArgsCommand):
norm_patterns.append(p)
all_files = []
+ ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT)]
for dirpath, dirnames, filenames in os.walk(force_text(root), topdown=True, followlinks=self.symlinks):
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)
if self.verbosity > 1:
self.stdout.write('ignoring directory %s\n' % dirname)
diff --git a/docs/releases/1.7.1.txt b/docs/releases/1.7.1.txt
index cedb54d420..bfdbb0ca1a 100644
--- a/docs/releases/1.7.1.txt
+++ b/docs/releases/1.7.1.txt
@@ -131,3 +131,6 @@ Bugfixes
* Fixed a regression when feeding the Django test client with an empty data
string (:ticket:`21740`).
+
+* Fixed a regression in :djadmin:`makemessages` where static files were
+ unexpectedly ignored (:ticket:`23583`).
diff --git a/tests/i18n/commands/someapp/static/javascript.js b/tests/i18n/commands/someapp/static/javascript.js
new file mode 100644
index 0000000000..ddedf5974a
--- /dev/null
+++ b/tests/i18n/commands/someapp/static/javascript.js
@@ -0,0 +1 @@
+gettext('Static content inside app should be included.')
diff --git a/tests/i18n/commands/static/javascript_ignored.js b/tests/i18n/commands/static/javascript_ignored.js
new file mode 100644
index 0000000000..28b14732a4
--- /dev/null
+++ b/tests/i18n/commands/static/javascript_ignored.js
@@ -0,0 +1 @@
+gettext('Content from STATIC_ROOT should not be included.')
diff --git a/tests/i18n/commands/static_root/static_ignored.html b/tests/i18n/commands/static/static_ignored.html
index e69de29bb2..e69de29bb2 100644
--- a/tests/i18n/commands/static_root/static_ignored.html
+++ b/tests/i18n/commands/static/static_ignored.html
diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py
index 2809a727bb..e0d3b51eb0 100644
--- a/tests/i18n/test_extraction.py
+++ b/tests/i18n/test_extraction.py
@@ -51,6 +51,17 @@ class ExtractorTests(SimpleTestCase):
pass
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):
q = '"'
if use_quotes:
@@ -321,38 +332,35 @@ class JavascriptExtractorTests(ExtractorTests):
def test_javascript_literals(self):
os.chdir(self.test_dir)
- management.call_command('makemessages', domain='djangojs', locale=[LOCALE], verbosity=0)
- 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 one as well.', po_contents)
- self.assertMsgId(r'He said, \"hello\".', po_contents)
- self.assertMsgId("okkkk", po_contents)
- self.assertMsgId("TEXT", po_contents)
- self.assertMsgId("It's at http://example.com", po_contents)
- self.assertMsgId("String", po_contents)
- self.assertMsgId("/* but this one will be too */ 'cause there is no way of telling...", po_contents)
- self.assertMsgId("foo", po_contents)
- self.assertMsgId("bar", po_contents)
- self.assertMsgId("baz", po_contents)
- self.assertMsgId("quz", po_contents)
- self.assertMsgId("foobar", po_contents)
+ _, po_contents = self._run_makemessages(domain='djangojs')
+ self.assertMsgId('This literal should be included.', po_contents)
+ self.assertMsgId('This one as well.', po_contents)
+ self.assertMsgId(r'He said, \"hello\".', po_contents)
+ self.assertMsgId("okkkk", po_contents)
+ self.assertMsgId("TEXT", po_contents)
+ self.assertMsgId("It's at http://example.com", po_contents)
+ self.assertMsgId("String", po_contents)
+ self.assertMsgId("/* but this one will be too */ 'cause there is no way of telling...", po_contents)
+ self.assertMsgId("foo", po_contents)
+ self.assertMsgId("bar", po_contents)
+ self.assertMsgId("baz", po_contents)
+ self.assertMsgId("quz", 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):
- 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):
out, po_contents = self._run_makemessages(ignore_patterns=[
os.path.join('ignore_dir', '*'),
@@ -377,11 +385,11 @@ class IgnoredExtractorTests(ExtractorTests):
self.assertNotMsgId('This should be ignored too.', po_contents)
@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/'))
def test_media_static_dirs_ignored(self):
out, _ = self._run_makemessages()
- self.assertIn("ignoring directory static_root", out)
+ self.assertIn("ignoring directory static", out)
self.assertIn("ignoring directory media_root", out)