fix #2522: Sphinx touches mo files under installed directory

that caused permission error.
This commit is contained in:
shimizukawa 2016-05-05 23:26:19 +09:00
parent d6572259d6
commit 26fecafb49
4 changed files with 13 additions and 16 deletions

View File

@ -52,6 +52,7 @@ Bugs fixed
* #2492: Figure directive with :figwidth: generates incorrect Latex-code * #2492: Figure directive with :figwidth: generates incorrect Latex-code
* The caption of figure is always put on center even if ``:align:`` was specified * The caption of figure is always put on center even if ``:align:`` was specified
* #2526: LaTeX writer crashes if the section having only images * #2526: LaTeX writer crashes if the section having only images
* #2522: Sphinx touches mo files under installed directory that caused permission error.
Release 1.4.1 (released Apr 12, 2016) Release 1.4.1 (released Apr 12, 2016)

View File

@ -44,6 +44,7 @@ from sphinx.util.osutil import ENOENT
from sphinx.util.logging import is_suppressed_warning from sphinx.util.logging import is_suppressed_warning
from sphinx.util.console import bold, lightgray, darkgray, darkgreen, \ from sphinx.util.console import bold, lightgray, darkgray, darkgreen, \
term_width_line term_width_line
from sphinx.util.i18n import find_catalog_source_files
if hasattr(sys, 'intern'): if hasattr(sys, 'intern'):
intern = sys.intern intern = sys.intern
@ -207,13 +208,17 @@ class Sphinx(object):
if self.config.language is not None: if self.config.language is not None:
self.info(bold('loading translations [%s]... ' % self.info(bold('loading translations [%s]... ' %
self.config.language), nonl=True) self.config.language), nonl=True)
locale_dirs = [None, path.join(package_dir, 'locale')] + \ user_locale_dirs = [
[path.join(self.srcdir, x) for x in self.config.locale_dirs] path.join(self.srcdir, x) for x in self.config.locale_dirs]
# compile mo files if sphinx.po file in user locale directories are updated
for catinfo in find_catalog_source_files(
user_locale_dirs, self.config.language, domains=['sphinx'],
charset=self.config.source_encoding):
catinfo.write_mo(self.config.language)
locale_dirs = [None, path.join(package_dir, 'locale')] + user_locale_dirs
else: else:
locale_dirs = [] locale_dirs = []
self.translator, has_translation = locale.init(locale_dirs, self.translator, has_translation = locale.init(locale_dirs, self.config.language)
self.config.language,
charset=self.config.source_encoding)
if self.config.language is not None: if self.config.language is not None:
if has_translation or self.config.language == 'en': if has_translation or self.config.language == 'en':
# "en" never needs to be translated # "en" never needs to be translated

View File

@ -195,7 +195,7 @@ else:
return translators['sphinx'].ugettext(message) return translators['sphinx'].ugettext(message)
def init(locale_dirs, language, catalog='sphinx', charset='utf-8'): def init(locale_dirs, language, catalog='sphinx'):
"""Look for message catalogs in `locale_dirs` and *ensure* that there is at """Look for message catalogs in `locale_dirs` and *ensure* that there is at
least a NullTranslations catalog set in `translators`. If called multiple least a NullTranslations catalog set in `translators`. If called multiple
times or if several ``.mo`` files are found, their contents are merged 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'):
# the None entry is the system's default locale path # the None entry is the system's default locale path
has_translation = True has_translation = True
# compile mo files if po file is updated
# TODO: remove circular importing
from sphinx.util.i18n import find_catalog_source_files
for catinfo in find_catalog_source_files(locale_dirs, language, domains=[catalog],
charset=charset):
catinfo.write_mo(language)
# loading # loading
for dir_ in locale_dirs: for dir_ in locale_dirs:
try: try:

View File

@ -239,9 +239,7 @@ class Locale(Transform):
# fetch translations # fetch translations
dirs = [path.join(env.srcdir, directory) dirs = [path.join(env.srcdir, directory)
for directory in env.config.locale_dirs] for directory in env.config.locale_dirs]
catalog, has_catalog = init_locale(dirs, env.config.language, catalog, has_catalog = init_locale(dirs, env.config.language, textdomain)
textdomain,
charset=env.config.source_encoding)
if not has_catalog: if not has_catalog:
return return