diff --git a/CHANGES b/CHANGES index e33793525..0593c478d 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,8 @@ Deprecated * ``sphinx.io.SphinxI18nReader.set_lineno_for_reporter()`` is deprecated * ``sphinx.io.SphinxI18nReader.line`` is deprecated +* ``sphinx.util.i18n.find_catalog_source_file()`` has changed; the + *gettext_compact* argument has been deprecated Features added -------------- @@ -41,6 +43,7 @@ Bugs fixed * #2720, #4034: Incorrect links with ``:download:``, duplicate names, and parallel builds * #5290: autodoc: failed to analyze source code in egg package +* #5399: Sphinx crashes if unknown po file exists Testing -------- diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst index 13a08e49b..6af027dd8 100644 --- a/doc/extdev/index.rst +++ b/doc/extdev/index.rst @@ -136,6 +136,12 @@ The following is a list of deprecated interface. - 4.0 - :confval:`autodoc_default_options` + * - ``gettext_compact`` arguments of + ``sphinx.util.i18n.find_catalog_source_files()`` + - 1.8 + - 3.0 + - N/A + * - ``sphinx.io.SphinxI18nReader.set_lineno_for_reporter()`` - 1.8 - 3.0 diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index e446ca94a..9c7537631 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -261,7 +261,6 @@ class Builder(object): [path.join(self.srcdir, x) for x in self.config.locale_dirs], self.config.language, charset=self.config.source_encoding, - gettext_compact=self.config.gettext_compact, force_all=True, excluded=Matcher(['**/.?**'])) message = __('all of %d po files') % len(catalogs) @@ -284,7 +283,6 @@ class Builder(object): self.config.language, domains=list(specified_domains), charset=self.config.source_encoding, - gettext_compact=self.config.gettext_compact, excluded=Matcher(['**/.?**'])) message = __('targets for %d po files that are specified') % len(catalogs) self.compile_catalogs(catalogs, message) @@ -295,7 +293,6 @@ class Builder(object): [path.join(self.srcdir, x) for x in self.config.locale_dirs], self.config.language, charset=self.config.source_encoding, - gettext_compact=self.config.gettext_compact, excluded=Matcher(['**/.?**'])) message = __('targets for %d po files that are out of date') % len(catalogs) self.compile_catalogs(catalogs, message) diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py index 106455302..edaebebda 100644 --- a/sphinx/util/i18n.py +++ b/sphinx/util/i18n.py @@ -12,6 +12,7 @@ import gettext import io import os import re +import warnings from collections import namedtuple from datetime import datetime from os import path @@ -20,6 +21,7 @@ import babel.dates from babel.messages.mofile import write_mo from babel.messages.pofile import read_po +from sphinx.deprecation import RemovedInSphinx30Warning from sphinx.errors import SphinxError from sphinx.locale import __ from sphinx.util import logging @@ -103,7 +105,7 @@ def find_catalog_files(docname, srcdir, locale_dirs, lang, compaction): return files # type: ignore -def find_catalog_source_files(locale_dirs, locale, domains=None, gettext_compact=False, +def find_catalog_source_files(locale_dirs, locale, domains=None, gettext_compact=None, charset='utf-8', force_all=False, excluded=Matcher([])): # type: (List[unicode], unicode, List[unicode], bool, unicode, bool, Matcher) -> Set[CatalogInfo] # NOQA @@ -115,14 +117,15 @@ def find_catalog_source_files(locale_dirs, locale, domains=None, gettext_compact :param str locale: a language as `'en'` :param list domains: list of domain names to get. If empty list or None is specified, get all domain names. default is None. - :param boolean gettext_compact: - * False: keep domains directory structure (default). - * True: domains in the sub directory will be merged into 1 file. :param boolean force_all: Set True if you want to get all catalogs rather than updated catalogs. default is False. :return: [CatalogInfo(), ...] """ + if gettext_compact is not None: + warnings.warn('gettext_compact argument for find_catalog_source_files() ' + 'is deprecated.', RemovedInSphinx30Warning) + catalogs = set() # type: Set[CatalogInfo] if not locale: @@ -143,10 +146,7 @@ def find_catalog_source_files(locale_dirs, locale, domains=None, gettext_compact if excluded(path.join(relpath(dirpath, base_dir), filename)): continue base = path.splitext(filename)[0] - domain = relpath(path.join(dirpath, base), base_dir) - if gettext_compact and path.sep in domain: - domain = path.split(domain)[0] - domain = domain.replace(path.sep, SEP) + domain = relpath(path.join(dirpath, base), base_dir).replace(path.sep, SEP) if domains and domain not in domains: continue cat = CatalogInfo(base_dir, domain, charset) diff --git a/tests/test_util_i18n.py b/tests/test_util_i18n.py index da8abe265..b7f460cd7 100644 --- a/tests/test_util_i18n.py +++ b/tests/test_util_i18n.py @@ -154,7 +154,7 @@ def test_get_catalogs_with_compact(tempdir): catalogs = i18n.find_catalog_source_files([tempdir / 'loc1'], 'xx', gettext_compact=True) domains = set(c.domain for c in catalogs) - assert domains == set(['test1', 'test2', 'sub']) + assert domains == set(['test1', 'test2', 'sub/test3', 'sub/test4']) def test_get_catalogs_excluded(tempdir):