mirror of https://github.com/django/django.git
Fixed #31692 -- Prevented unneeded .po file compilation.
Thanks Nick Pope and Simon Charette for the reviews.
This commit is contained in:
parent
ed0a040773
commit
e62d55a4fe
|
@ -122,10 +122,20 @@ class Command(BaseCommand):
|
||||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||||
futures = []
|
futures = []
|
||||||
for i, (dirpath, f) in enumerate(locations):
|
for i, (dirpath, f) in enumerate(locations):
|
||||||
if self.verbosity > 0:
|
|
||||||
self.stdout.write('processing file %s in %s' % (f, dirpath))
|
|
||||||
po_path = Path(dirpath) / f
|
po_path = Path(dirpath) / f
|
||||||
mo_path = po_path.with_suffix('.mo')
|
mo_path = po_path.with_suffix('.mo')
|
||||||
|
try:
|
||||||
|
if mo_path.stat().st_mtime >= po_path.stat().st_mtime:
|
||||||
|
if self.verbosity > 0:
|
||||||
|
self.stdout.write(
|
||||||
|
'File “%s” is already compiled and up to date.'
|
||||||
|
% po_path
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
if self.verbosity > 0:
|
||||||
|
self.stdout.write('processing file %s in %s' % (f, dirpath))
|
||||||
|
|
||||||
if has_bom(po_path):
|
if has_bom(po_path):
|
||||||
self.stderr.write(
|
self.stderr.write(
|
||||||
|
|
|
@ -49,6 +49,8 @@ class PoFileTests(MessageCompilationTests):
|
||||||
# Put file in read-only mode.
|
# Put file in read-only mode.
|
||||||
old_mode = mo_file_en.stat().st_mode
|
old_mode = mo_file_en.stat().st_mode
|
||||||
mo_file_en.chmod(stat.S_IREAD)
|
mo_file_en.chmod(stat.S_IREAD)
|
||||||
|
# Ensure .po file is more recent than .mo file.
|
||||||
|
mo_file_en.with_suffix('.po').touch()
|
||||||
try:
|
try:
|
||||||
with self.assertRaisesMessage(CommandError, 'compilemessages generated one or more errors.'):
|
with self.assertRaisesMessage(CommandError, 'compilemessages generated one or more errors.'):
|
||||||
call_command('compilemessages', locale=['en'], stderr=err_buffer, verbosity=0)
|
call_command('compilemessages', locale=['en'], stderr=err_buffer, verbosity=0)
|
||||||
|
@ -56,6 +58,14 @@ class PoFileTests(MessageCompilationTests):
|
||||||
finally:
|
finally:
|
||||||
mo_file_en.chmod(old_mode)
|
mo_file_en.chmod(old_mode)
|
||||||
|
|
||||||
|
def test_no_compile_when_unneeded(self):
|
||||||
|
mo_file_en = Path(self.MO_FILE_EN)
|
||||||
|
mo_file_en.touch()
|
||||||
|
stdout = StringIO()
|
||||||
|
call_command('compilemessages', locale=['en'], stdout=stdout, verbosity=1)
|
||||||
|
msg = '%s” is already compiled and up to date.' % mo_file_en.with_suffix('.po')
|
||||||
|
self.assertIn(msg, stdout.getvalue())
|
||||||
|
|
||||||
|
|
||||||
class PoFileContentsTests(MessageCompilationTests):
|
class PoFileContentsTests(MessageCompilationTests):
|
||||||
# Ticket #11240
|
# Ticket #11240
|
||||||
|
|
Loading…
Reference in New Issue