Skip to content

Commit 26fecaf

Browse files
committed
fix #2522: Sphinx touches mo files under installed directory
that caused permission error.
1 parent d657225 commit 26fecaf

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Bugs fixed
5252
* #2492: Figure directive with :figwidth: generates incorrect Latex-code
5353
* The caption of figure is always put on center even if ``:align:`` was specified
5454
* #2526: LaTeX writer crashes if the section having only images
55+
* #2522: Sphinx touches mo files under installed directory that caused permission error.
5556

5657

5758
Release 1.4.1 (released Apr 12, 2016)

sphinx/application.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from sphinx.util.logging import is_suppressed_warning
4545
from sphinx.util.console import bold, lightgray, darkgray, darkgreen, \
4646
term_width_line
47+
from sphinx.util.i18n import find_catalog_source_files
4748

4849
if hasattr(sys, 'intern'):
4950
intern = sys.intern
@@ -207,13 +208,17 @@ def _init_i18n(self):
207208
if self.config.language is not None:
208209
self.info(bold('loading translations [%s]... ' %
209210
self.config.language), nonl=True)
210-
locale_dirs = [None, path.join(package_dir, 'locale')] + \
211-
[path.join(self.srcdir, x) for x in self.config.locale_dirs]
211+
user_locale_dirs = [
212+
path.join(self.srcdir, x) for x in self.config.locale_dirs]
213+
# compile mo files if sphinx.po file in user locale directories are updated
214+
for catinfo in find_catalog_source_files(
215+
user_locale_dirs, self.config.language, domains=['sphinx'],
216+
charset=self.config.source_encoding):
217+
catinfo.write_mo(self.config.language)
218+
locale_dirs = [None, path.join(package_dir, 'locale')] + user_locale_dirs
212219
else:
213220
locale_dirs = []
214-
self.translator, has_translation = locale.init(locale_dirs,
215-
self.config.language,
216-
charset=self.config.source_encoding)
221+
self.translator, has_translation = locale.init(locale_dirs, self.config.language)
217222
if self.config.language is not None:
218223
if has_translation or self.config.language == 'en':
219224
# "en" never needs to be translated

sphinx/locale/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def _(message):
195195
return translators['sphinx'].ugettext(message)
196196

197197

198-
def init(locale_dirs, language, catalog='sphinx', charset='utf-8'):
198+
def init(locale_dirs, language, catalog='sphinx'):
199199
"""Look for message catalogs in `locale_dirs` and *ensure* that there is at
200200
least a NullTranslations catalog set in `translators`. If called multiple
201201
times or if several ``.mo`` files are found, their contents are merged
@@ -209,13 +209,6 @@ def init(locale_dirs, language, catalog='sphinx', charset='utf-8'):
209209
# the None entry is the system's default locale path
210210
has_translation = True
211211

212-
# compile mo files if po file is updated
213-
# TODO: remove circular importing
214-
from sphinx.util.i18n import find_catalog_source_files
215-
for catinfo in find_catalog_source_files(locale_dirs, language, domains=[catalog],
216-
charset=charset):
217-
catinfo.write_mo(language)
218-
219212
# loading
220213
for dir_ in locale_dirs:
221214
try:

sphinx/transforms.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,7 @@ def apply(self):
239239
# fetch translations
240240
dirs = [path.join(env.srcdir, directory)
241241
for directory in env.config.locale_dirs]
242-
catalog, has_catalog = init_locale(dirs, env.config.language,
243-
textdomain,
244-
charset=env.config.source_encoding)
242+
catalog, has_catalog = init_locale(dirs, env.config.language, textdomain)
245243
if not has_catalog:
246244
return
247245

0 commit comments

Comments
 (0)