From 6dcdce685dbcefa8021a9e06819318fc640ef4a8 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Tue, 1 May 2018 22:57:32 +0200 Subject: [PATCH 1/5] i18n: Ignore dot-directories like .git/ in LC_MESSAGES/. This avoids warnings when find_catalog_source_files returns files found in .git/ like: WARNING: Start of line didn't match any expected keyword./refs/heads/freezed-library/colorsys.mo WARNING: Problem on line 1: 0000000000000000000000000000000000000000 032a00a7391ec8a155bbc54d66ba72fb1b7bdbf1 Julien Palard 1521582790 +0100 branch: Created from freezed/library/colorsys.po `.po` files can typically reside in .git/refs/heads/ if some branches name end with .po, in which case they contain a SHA1, not translations, leading to warnings. --- sphinx/builders/__init__.py | 10 +++++++--- sphinx/util/i18n.py | 13 +++++++++++-- tests/test_util_i18n.py | 11 +++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index a587f11e0..7464e055b 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -19,6 +19,7 @@ from sphinx.environment.adapters.asset import ImageAdapter from sphinx.util import i18n, logging, status_iterator from sphinx.util.console import bold # type: ignore from sphinx.util.i18n import find_catalog +from sphinx.util.matching import Matcher from sphinx.util.osutil import SEP, ensuredir, relative_uri, relpath from sphinx.util.parallel import ParallelTasks, SerialTasks, make_chunks, \ parallel_available @@ -252,7 +253,8 @@ class Builder(object): self.config.language, charset=self.config.source_encoding, gettext_compact=self.config.gettext_compact, - force_all=True) + force_all=True, + excluded=Matcher(['**/.?**'])) message = 'all of %d po files' % len(catalogs) self.compile_catalogs(catalogs, message) @@ -273,7 +275,8 @@ class Builder(object): self.config.language, domains=list(specified_domains), charset=self.config.source_encoding, - gettext_compact=self.config.gettext_compact) + gettext_compact=self.config.gettext_compact, + excluded=Matcher(['**/.?**'])) message = 'targets for %d po files that are specified' % len(catalogs) self.compile_catalogs(catalogs, message) @@ -283,7 +286,8 @@ 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) + 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 ff7f8bd75..14b4f9d5b 100644 --- a/sphinx/util/i18n.py +++ b/sphinx/util/i18n.py @@ -24,6 +24,12 @@ from sphinx.errors import SphinxError from sphinx.util import logging from sphinx.util.osutil import SEP, relpath, walk +if False: + # For type annotation + from typing import Union # NOQA + from sphinx.util.matching import Matcher # NOQA + + logger = logging.getLogger(__name__) if False: @@ -101,8 +107,9 @@ def find_catalog_files(docname, srcdir, locale_dirs, lang, compaction): def find_catalog_source_files(locale_dirs, locale, domains=None, gettext_compact=False, - charset='utf-8', force_all=False): - # type: (List[unicode], unicode, List[unicode], bool, unicode, bool) -> Set[CatalogInfo] + charset='utf-8', force_all=False, + excluded=lambda path: False): + # type: (List[unicode], unicode, List[unicode], bool, unicode, bool, Union[Callable[[unicode], bool], Matcher]) -> Set[CatalogInfo] # NOQA """ :param list locale_dirs: list of path as `['locale_dir1', 'locale_dir2', ...]` to find @@ -136,6 +143,8 @@ def find_catalog_source_files(locale_dirs, locale, domains=None, gettext_compact for dirpath, dirnames, filenames in walk(base_dir, followlinks=True): filenames = [f for f in filenames if f.endswith('.po')] for filename in filenames: + 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: diff --git a/tests/test_util_i18n.py b/tests/test_util_i18n.py index 1ae6dcb67..da8abe265 100644 --- a/tests/test_util_i18n.py +++ b/tests/test_util_i18n.py @@ -157,6 +157,17 @@ def test_get_catalogs_with_compact(tempdir): assert domains == set(['test1', 'test2', 'sub']) +def test_get_catalogs_excluded(tempdir): + (tempdir / 'loc1' / 'en' / 'LC_MESSAGES' / '.git').makedirs() + (tempdir / 'loc1' / 'en' / 'LC_MESSAGES' / 'en_dom.po').write_text('#') + (tempdir / 'loc1' / 'en' / 'LC_MESSAGES' / '.git' / 'no_no.po').write_text('#') + + catalogs = i18n.find_catalog_source_files( + [tempdir / 'loc1'], 'en', force_all=False, excluded=lambda path: '.git' in path) + domains = set(c.domain for c in catalogs) + assert domains == set(['en_dom']) + + def test_format_date(): date = datetime.date(2016, 2, 7) From 269becfbf6eadbf00c03c35c18580e31af9b46d4 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 19 May 2018 02:29:47 +0900 Subject: [PATCH 2/5] Fix #4978: latex: shorthandoff is not set up for Brazil locale --- CHANGES | 1 + sphinx/writers/latex.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index c3dc3996d..abafe5bb0 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,7 @@ Bugs fixed * #4825: C++, properly parse expr roles and give better error messages when (escaped) line breaks are present. * #4915, #4916: links on search page are broken when using dirhtml builder +* #4978: latex: shorthandoff is not set up for Brazil locale Testing -------- diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 17eabc462..9356bcee4 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -196,7 +196,7 @@ class ExtBabel(Babel): shortlang = self.language.split('_')[0] if shortlang in ('de', 'ngerman', 'sl', 'slovene', 'pt', 'portuges', 'es', 'spanish', 'nl', 'dutch', 'pl', 'polish', 'it', - 'italian'): + 'italian', 'pt-BR', 'brazil'): return '\\ifnum\\catcode`\\"=\\active\\shorthandoff{"}\\fi' elif shortlang in ('tr', 'turkish'): # memo: if ever Sphinx starts supporting 'Latin', do as for Turkish From 6740d2d3918e22d820f0b70df5c2c71a788d3a36 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Wed, 16 May 2018 10:50:23 +0200 Subject: [PATCH 3/5] Use a Matcher as default argument to simplify type anotation. --- sphinx/util/i18n.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py index 14b4f9d5b..1826d25c5 100644 --- a/sphinx/util/i18n.py +++ b/sphinx/util/i18n.py @@ -22,13 +22,9 @@ from babel.messages.pofile import read_po from sphinx.errors import SphinxError from sphinx.util import logging +from sphinx.util.matching import Matcher from sphinx.util.osutil import SEP, relpath, walk -if False: - # For type annotation - from typing import Union # NOQA - from sphinx.util.matching import Matcher # NOQA - logger = logging.getLogger(__name__) @@ -108,8 +104,8 @@ def find_catalog_files(docname, srcdir, locale_dirs, lang, compaction): def find_catalog_source_files(locale_dirs, locale, domains=None, gettext_compact=False, charset='utf-8', force_all=False, - excluded=lambda path: False): - # type: (List[unicode], unicode, List[unicode], bool, unicode, bool, Union[Callable[[unicode], bool], Matcher]) -> Set[CatalogInfo] # NOQA + excluded=Matcher([])): + # type: (List[unicode], unicode, List[unicode], bool, unicode, bool, Matcher) -> Set[CatalogInfo] # NOQA """ :param list locale_dirs: list of path as `['locale_dir1', 'locale_dir2', ...]` to find From bd6442bf96fd736559a65088fe648947f6142868 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 19 May 2018 16:44:55 +0900 Subject: [PATCH 4/5] Update CHANGES for PR #4928 --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index ad85ccd93..9f2c96dea 100644 --- a/CHANGES +++ b/CHANGES @@ -31,6 +31,7 @@ Bugs fixed * latex: deeply nested enumerated list which is beginning with non-1 causes LaTeX engine crashed * #4978: latex: shorthandoff is not set up for Brazil locale +* #4928: i18n: Ignore dot-directories like .git/ in LC_MESSAGES/ Testing -------- From 9ccff74f66a55ea84276291c3d7ec474e675d621 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 19 May 2018 22:50:10 +0900 Subject: [PATCH 5/5] Fix #4946: py domain: type field could not handle "None" as a type --- CHANGES | 1 + sphinx/domains/python.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 9f2c96dea..f9b6e6af5 100644 --- a/CHANGES +++ b/CHANGES @@ -32,6 +32,7 @@ Bugs fixed LaTeX engine crashed * #4978: latex: shorthandoff is not set up for Brazil locale * #4928: i18n: Ignore dot-directories like .git/ in LC_MESSAGES/ +* #4946: py domain: type field could not handle "None" as a type Testing -------- diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 2b46596af..1d1f28b03 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -156,7 +156,15 @@ class PyGroupedField(PyXrefMixin, GroupedField): class PyTypedField(PyXrefMixin, TypedField): - pass + def make_xref(self, rolename, domain, target, + innernode=nodes.emphasis, contnode=None, env=None): + # type: (unicode, unicode, unicode, nodes.Node, nodes.Node, BuildEnvironment) -> nodes.Node # NOQA + if rolename == 'class' and target == 'None': + # None is not a type, so use obj role instead. + rolename = 'obj' + + return super(PyTypedField, self).make_xref(rolename, domain, target, + innernode, contnode, env) class PyObject(ObjectDescription):