Skip to content

Commit

Permalink
Merge branch '4.x' into autosummary___all__
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoshanuikabundi committed Nov 10, 2021
2 parents 68b1ab7 + 096e286 commit 2204c76
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Expand Up @@ -23,6 +23,7 @@ Incompatible changes
* #9695: The rendering of Javascript domain declarations is implemented
with more docutils nodes to allow better CSS styling.
It may break existing styling.
* #9450: mathjax: Load MathJax via "defer" strategy


Deprecated
Expand All @@ -43,6 +44,8 @@ Features added
* #9691: C, added new info-field ``retval``
for :rst:dir:`c:function` and :rst:dir:`c:macro`.
* C++, added new info-field ``retval`` for :rst:dir:`cpp:function`.
* #9618: i18n: Add :confval:`gettext_allow_fuzzy_translations` to allow "fuzzy"
messages for translation
* #9672: More CSS classes on Python domain descriptions
* #9695: More CSS classes on Javascript domain descriptions
* #9683: Revert the removal of ``add_stylesheet()`` API. It will be kept until
Expand All @@ -52,6 +55,8 @@ Features added
inventory specification. Specific types of cross-references can be disabled,
e.g., ``std:doc`` or all cross-references in a specific domain,
e.g., ``std:*``.
* #9623: Allow to suppress "toctree contains reference to excluded document"
warnings using :confval:`suppress_warnings`
* #9831: Autosummary now documents only the members specified in a module's
``__all__`` attribute if :confval:`autosummary_ignore___all__` is set to
``False``. The default behaviour is unchanged. Autogen also now supports
Expand Down
13 changes: 13 additions & 0 deletions doc/usage/configuration.rst
Expand Up @@ -329,6 +329,8 @@ General configuration
* ``ref.python``
* ``misc.highlighting_failure``
* ``toc.circular``
* ``toc.excluded``
* ``toc.not_readable``
* ``toc.secnum``
* ``epub.unknown_project_files``
* ``epub.duplicated_toc_entry``
Expand Down Expand Up @@ -360,6 +362,10 @@ General configuration

Added ``epub.duplicated_toc_entry``

.. versionchanged:: 4.3

Added ``toc.excluded`` and ``toc.not_readable``

.. confval:: needs_sphinx

If set to a ``major.minor`` version string like ``'1.1'``, Sphinx will
Expand Down Expand Up @@ -802,6 +808,13 @@ documentation on :ref:`intl` for details.
.. versionchanged:: 1.5
Use ``locales`` directory as a default value

.. confval:: gettext_allow_fuzzy_translations

If true, "fuzzy" messages in the message catalogs are used for translation.
The default is ``False``.

.. versionadded:: 4.3

.. confval:: gettext_compact

.. versionadded:: 1.1
Expand Down
3 changes: 2 additions & 1 deletion sphinx/application.py
Expand Up @@ -284,7 +284,8 @@ def _init_i18n(self) -> None:
self.config.language, self.config.source_encoding)
for catalog in repo.catalogs:
if catalog.domain == 'sphinx' and catalog.is_outdated():
catalog.write_mo(self.config.language)
catalog.write_mo(self.config.language,
self.config.gettext_allow_fuzzy_translations)

locale_dirs: List[Optional[str]] = list(repo.locale_dirs)
locale_dirs += [None]
Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/__init__.py
Expand Up @@ -217,7 +217,8 @@ def cat2relpath(cat: CatalogInfo) -> str:
for catalog in status_iterator(catalogs, __('writing output... '), "darkgreen",
len(catalogs), self.app.verbosity,
stringify_func=cat2relpath):
catalog.write_mo(self.config.language)
catalog.write_mo(self.config.language,
self.config.gettext_allow_fuzzy_translations)

def compile_all_catalogs(self) -> None:
repo = CatalogRepository(self.srcdir, self.config.locale_dirs,
Expand Down
1 change: 1 addition & 0 deletions sphinx/config.py
Expand Up @@ -103,6 +103,7 @@ class Config:
'language': (None, 'env', [str]),
'locale_dirs': (['locales'], 'env', []),
'figure_language_filename': ('{root}.{language}{ext}', 'env', [str]),
'gettext_allow_fuzzy_translations': (False, 'gettext', []),

'master_doc': ('index', 'env', []),
'root_doc': (lambda config: config.master_doc, 'env', []),
Expand Down
35 changes: 19 additions & 16 deletions sphinx/directives/other.py
Expand Up @@ -18,8 +18,8 @@

from sphinx import addnodes
from sphinx.domains.changeset import VersionChange # NOQA # for compatibility
from sphinx.locale import _
from sphinx.util import docname_join, url_re
from sphinx.locale import _, __
from sphinx.util import docname_join, logging, url_re
from sphinx.util.docutils import SphinxDirective
from sphinx.util.matching import Matcher, patfilter
from sphinx.util.nodes import explicit_title_re
Expand All @@ -30,6 +30,7 @@


glob_re = re.compile(r'.*[*?\[].*')
logger = logging.getLogger(__name__)


def int_or_nothing(argument: str) -> int:
Expand Down Expand Up @@ -106,9 +107,8 @@ def parse_content(self, toctree: addnodes.toctree) -> List[Node]:
toctree['entries'].append((None, docname))
toctree['includefiles'].append(docname)
if not docnames:
ret.append(self.state.document.reporter.warning(
'toctree glob pattern %r didn\'t match any documents'
% entry, line=self.lineno))
logger.warning(__('toctree glob pattern %r didn\'t match any documents'),
entry, location=toctree)
else:
if explicit:
ref = explicit.group(2)
Expand All @@ -128,20 +128,21 @@ def parse_content(self, toctree: addnodes.toctree) -> List[Node]:
toctree['entries'].append((title, ref))
elif docname not in self.env.found_docs:
if excluded(self.env.doc2path(docname, None)):
message = 'toctree contains reference to excluded document %r'
message = __('toctree contains reference to excluded document %r')
subtype = 'excluded'
else:
message = 'toctree contains reference to nonexisting document %r'
message = __('toctree contains reference to nonexisting document %r')
subtype = 'not_readable'

ret.append(self.state.document.reporter.warning(message % docname,
line=self.lineno))
logger.warning(message, docname, type='toc', subtype=subtype,
location=toctree)
self.env.note_reread()
else:
if docname in all_docnames:
all_docnames.remove(docname)
else:
message = 'duplicated entry found in toctree: %s'
ret.append(self.state.document.reporter.warning(message % docname,
line=self.lineno))
logger.warning(__('duplicated entry found in toctree: %s'), docname,
location=toctree)

toctree['entries'].append((title, docname))
toctree['includefiles'].append(docname)
Expand Down Expand Up @@ -250,8 +251,9 @@ def run(self) -> List[Node]:
self.state.nested_parse(self.content, self.content_offset, node)
if len(node.children) != 1 or not isinstance(node.children[0],
nodes.bullet_list):
reporter = self.state.document.reporter
return [reporter.warning('.. acks content is not a list', line=self.lineno)]
logger.warning(__('.. acks content is not a list'),
location=(self.env.docname, self.lineno))
return []
return [node]


Expand All @@ -274,8 +276,9 @@ def run(self) -> List[Node]:
self.state.nested_parse(self.content, self.content_offset, node)
if len(node.children) != 1 or not isinstance(node.children[0],
nodes.bullet_list):
reporter = self.state.document.reporter
return [reporter.warning('.. hlist content is not a list', line=self.lineno)]
logger.warning(__('.. hlist content is not a list'),
location=(self.env.docname, self.lineno))
return []
fulllist = node.children[0]
# create a hlist node where the items are distributed
npercol, nmore = divmod(len(fulllist), ncolumns)
Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/mathjax.py
Expand Up @@ -81,7 +81,7 @@ def install_mathjax(app: Sphinx, pagename: str, templatename: str, context: Dict
domain = cast(MathDomain, app.env.get_domain('math'))
if app.registry.html_assets_policy == 'always' or domain.has_equations(pagename):
# Enable mathjax only if equations exists
options = {'async': 'async'}
options = {'defer': 'defer'}
if app.config.mathjax_options:
options.update(app.config.mathjax_options)
app.add_js_file(app.config.mathjax_path, **options) # type: ignore
Expand Down
4 changes: 2 additions & 2 deletions sphinx/util/i18n.py
Expand Up @@ -59,7 +59,7 @@ def is_outdated(self) -> bool:
not path.exists(self.mo_path) or
path.getmtime(self.mo_path) < path.getmtime(self.po_path))

def write_mo(self, locale: str) -> None:
def write_mo(self, locale: str, use_fuzzy: bool = False) -> None:
with open(self.po_path, encoding=self.charset) as file_po:
try:
po = read_po(file_po, locale)
Expand All @@ -69,7 +69,7 @@ def write_mo(self, locale: str) -> None:

with open(self.mo_path, 'wb') as file_mo:
try:
write_mo(file_mo, po)
write_mo(file_mo, po, use_fuzzy)
except Exception as exc:
logger.warning(__('writing error: %s, %s'), self.mo_path, exc)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_ext_math.py
Expand Up @@ -71,7 +71,7 @@ def test_mathjax_options(app, status, warning):
app.builder.build_all()

content = (app.outdir / 'index.html').read_text()
assert ('<script async="async" integrity="sha384-0123456789" '
assert ('<script defer="defer" integrity="sha384-0123456789" '
'src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">'
'</script>' in content)

Expand Down
38 changes: 38 additions & 0 deletions tests/test_intl.py
Expand Up @@ -1301,6 +1301,44 @@ def getwarning(warnings):
return strip_escseq(warnings.getvalue().replace(os.sep, '/'))


@pytest.mark.sphinx('html', testroot='basic',
srcdir='gettext_allow_fuzzy_translations',
confoverrides={
'language': 'de',
'gettext_allow_fuzzy_translations': True
})
def test_gettext_allow_fuzzy_translations(app):
locale_dir = app.srcdir / 'locales' / 'de' / 'LC_MESSAGES'
locale_dir.makedirs()
with (locale_dir / 'index.po').open('wb') as f:
catalog = Catalog()
catalog.add('features', 'FEATURES', flags=('fuzzy',))
pofile.write_po(f, catalog)

app.build()
content = (app.outdir / 'index.html').read_text()
assert 'FEATURES' in content


@pytest.mark.sphinx('html', testroot='basic',
srcdir='gettext_disallow_fuzzy_translations',
confoverrides={
'language': 'de',
'gettext_allow_fuzzy_translations': False
})
def test_gettext_disallow_fuzzy_translations(app):
locale_dir = app.srcdir / 'locales' / 'de' / 'LC_MESSAGES'
locale_dir.makedirs()
with (locale_dir / 'index.po').open('wb') as f:
catalog = Catalog()
catalog.add('features', 'FEATURES', flags=('fuzzy',))
pofile.write_po(f, catalog)

app.build()
content = (app.outdir / 'index.html').read_text()
assert 'FEATURES' not in content


@pytest.mark.sphinx('html', testroot='basic', confoverrides={'language': 'de'})
def test_customize_system_message(make_app, app_params, sphinx_test_tempdir):
try:
Expand Down

0 comments on commit 2204c76

Please sign in to comment.