diff --git a/CHANGES b/CHANGES index bfbd4327a..e61007f3b 100644 --- a/CHANGES +++ b/CHANGES @@ -49,6 +49,8 @@ Features added -------------- * #6707: C++, support bit-fields. +* #267: html: Eliminate prompt characters of doctest block from copyable text +* #6729: html theme: agogo theme now supports ``rightsidebar`` option Bugs fixed ---------- @@ -62,6 +64,8 @@ Bugs fixed * #6655: image URLs containing ``data:`` causes gettext builder crashed * #6584: i18n: Error when compiling message catalogs on Hindi * #6718: i18n: KeyError is raised if section title and table title are same +* #6708: mathbase: Some deprecated functions have removed +* #6709: autodoc: mock object does not work as a class decorator Testing -------- @@ -85,6 +89,7 @@ Bugs fixed ---------- * #6641: LaTeX: Undefined control sequence ``\sphinxmaketitle`` +* #6710: LaTeX not well configured for Greek language as main language Testing -------- diff --git a/doc/latex.rst b/doc/latex.rst index 39c87484d..2501d1594 100644 --- a/doc/latex.rst +++ b/doc/latex.rst @@ -289,6 +289,11 @@ into the generated ``.tex`` files. Its ``'sphinxsetup'`` key is described .. attention:: + If Greek is main language, do not use this key. Since Sphinx 2.2.1, + ``xelatex`` will be used automatically as :confval:`latex_engine`. + Formerly, Sphinx did not support producing PDF via LaTeX with Greek as + main language. + Prior to 2.0, Unicode Greek letters were escaped to use LaTeX math mark-up. This is not the case anymore, and the above must be used (only in case of ``'pdflatex'`` engine) if the source contains such diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index dcf1ad4fe..8c6b0f425 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -1841,7 +1841,17 @@ These options influence LaTeX output. ``'xelatex'`` or ``'lualatex'`` and making sure to use an OpenType font with wide-enough glyph coverage is often easier than trying to make ``'pdflatex'`` work with the extra Unicode characters. Since Sphinx 2.0 - the default is the GNU FreeFont which covers well Latin, Cyrillic and Greek. + the default is the GNU FreeFont which covers well Latin, Cyrillic and + Greek. + + .. versionchanged:: 2.1.0 + + Use ``xelatex`` (and LaTeX package ``xeCJK``) by default for Chinese + documents. + + .. versionchanged:: 2.2.1 + + Use ``xelatex`` by default for Greek documents. Contrarily to :ref:`MathJaX math rendering in HTML output `, LaTeX requires some extra configuration to support Unicode literals in diff --git a/doc/usage/theming.rst b/doc/usage/theming.rst index e0d779b99..3b42bc4cb 100644 --- a/doc/usage/theming.rst +++ b/doc/usage/theming.rst @@ -237,6 +237,8 @@ These themes are: - **documentwidth** (CSS length): Width of the document (without sidebar), default 50em. - **sidebarwidth** (CSS length): Width of the sidebar, default 20em. + - **rightsidebar** (true or false): Put the sidebar on the right side. + Defaults to ``True``. - **bgcolor** (CSS color): Background color. - **headerbg** (CSS value for "background"): background for the header area, default a grayish gradient. diff --git a/setup.py b/setup.py index 1f3999490..17d4f8fc6 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ extras_require = { 'html5lib', 'flake8>=3.5.0', 'flake8-import-order', - 'mypy>=0.730', + 'mypy>=0.740', 'docutils-stubs', ], } diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py index 69735ec47..9c34b5568 100644 --- a/sphinx/builders/latex/__init__.py +++ b/sphinx/builders/latex/__init__.py @@ -418,6 +418,8 @@ def default_latex_engine(config: Config) -> str: return 'platex' elif (config.language or '').startswith('zh'): return 'xelatex' + elif config.language == 'el': + return 'xelatex' else: return 'pdflatex' diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index 4a8a73380..4928fb997 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -32,7 +32,8 @@ from sphinx.util.nodes import make_refnode if False: # For type annotation - from typing import Any, Callable, Dict, Iterator, List, Match, Pattern, Tuple, Union # NOQA + from docutils.nodes import TextElement + from typing import Any, Callable, Dict, Iterator, List, Match, Pattern, Tuple, Type, Union # NOQA from sphinx.application import Sphinx # NOQA from sphinx.builders import Builder # NOQA from sphinx.config import Config # NOQA @@ -7037,7 +7038,7 @@ class CPPExprRole: if asCode: # render the expression as inline code self.class_type = 'cpp-expr' - self.node_type = nodes.literal + self.node_type = nodes.literal # type: Type[TextElement] else: # render the expression as inline text self.class_type = 'cpp-texpr' diff --git a/sphinx/ext/autodoc/mock.py b/sphinx/ext/autodoc/mock.py index b13c5ee61..bc57d9078 100644 --- a/sphinx/ext/autodoc/mock.py +++ b/sphinx/ext/autodoc/mock.py @@ -58,7 +58,7 @@ class _MockObject: return _make_subclass(key, self.__display_name__, self.__class__)() def __call__(self, *args, **kw) -> Any: - if args and type(args[0]) in [FunctionType, MethodType]: + if args and type(args[0]) in [type, FunctionType, MethodType]: # Appears to be a decorator, pass through unchanged return args[0] return self diff --git a/sphinx/themes/agogo/layout.html b/sphinx/themes/agogo/layout.html index 1ab82f7f0..b46440203 100644 --- a/sphinx/themes/agogo/layout.html +++ b/sphinx/themes/agogo/layout.html @@ -33,15 +33,7 @@ {% endblock %} -{% block content %} -
-
-
- {%- block document %} - {{ super() }} - {%- endblock %} -
- {%- endblock %} +{% endmacro %} + +{% block content %} +
+
+ {%- if not theme_rightsidebar|tobool %} + + {%- endif %} +
+ {%- block document %} + {{ super() }} + {%- endblock %} +
+ {%- if theme_rightsidebar|tobool %} + + {%- endif %}
diff --git a/sphinx/themes/agogo/static/agogo.css_t b/sphinx/themes/agogo/static/agogo.css_t index f8951421e..f7b257719 100644 --- a/sphinx/themes/agogo/static/agogo.css_t +++ b/sphinx/themes/agogo/static/agogo.css_t @@ -175,7 +175,11 @@ div.document { } div.body { + {%- if theme_rightsidebar|tobool %} padding-right: 2em; + {%- else %} + padding-left: 2em; + {% endif %} text-align: {{ theme_textalign }}; } @@ -270,7 +274,11 @@ div.document ol { div.sidebar { width: {{ theme_sidebarwidth|todim }}; + {%- if theme_rightsidebar|tobool %} float: right; + {%- else %} + float: left; + {%- endif %} font-size: .9em; } diff --git a/sphinx/themes/agogo/theme.conf b/sphinx/themes/agogo/theme.conf index 28f6b040a..6a4457e95 100644 --- a/sphinx/themes/agogo/theme.conf +++ b/sphinx/themes/agogo/theme.conf @@ -8,6 +8,7 @@ bodyfont = "Verdana", Arial, sans-serif headerfont = "Georgia", "Times New Roman", serif pagewidth = 70em documentwidth = 50em +rightsidebar = true sidebarwidth = 20em bgcolor = #eeeeec headerbg = #555573 url(bgtop.png) top left repeat-x diff --git a/sphinx/themes/basic/static/basic.css_t b/sphinx/themes/basic/static/basic.css_t index 1c278e88b..354267567 100644 --- a/sphinx/themes/basic/static/basic.css_t +++ b/sphinx/themes/basic/static/basic.css_t @@ -672,6 +672,10 @@ div.code-block-caption + div > div.highlight > pre { margin-top: 0; } +div.doctest > div.highlight span.gp { /* gp: Generic.Prompt */ + user-select: none; +} + div.code-block-caption span.caption-number { padding: 0.1em 0.3em; font-style: italic; diff --git a/sphinx/transforms/__init__.py b/sphinx/transforms/__init__.py index f3af5cd47..3d72b88df 100644 --- a/sphinx/transforms/__init__.py +++ b/sphinx/transforms/__init__.py @@ -269,6 +269,16 @@ class UnreferencedFootnotesDetector(SphinxTransform): location=node) +class DoctestTransform(SphinxTransform): + """Set "doctest" style to each doctest_block node""" + default_priority = 500 + + def apply(self, **kwargs): + # type: (Any) -> None + for node in self.document.traverse(nodes.doctest_block): + node['classes'].append('doctest') + + class FigureAligner(SphinxTransform): """ Align figures to center by default. @@ -402,6 +412,7 @@ def setup(app: "Sphinx") -> Dict[str, Any]: app.add_transform(MoveModuleTargets) app.add_transform(HandleCodeBlocks) app.add_transform(SortIds) + app.add_transform(DoctestTransform) app.add_transform(FigureAligner) app.add_transform(AutoNumbering) app.add_transform(AutoIndexUpgrader) diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py index 00b340118..aeb069960 100644 --- a/sphinx/util/docutils.py +++ b/sphinx/util/docutils.py @@ -183,7 +183,7 @@ class sphinx_domains: def __enter__(self) -> None: self.enable() - def __exit__(self, exc_type: "Type[Exception]", exc_value: Exception, traceback: Any) -> bool: # NOQA + def __exit__(self, exc_type: "Type[Exception]", exc_value: Exception, traceback: Any) -> bool: # type: ignore # NOQA self.disable() return False diff --git a/sphinx/util/matching.py b/sphinx/util/matching.py index 97eeff40f..cd8e16e20 100644 --- a/sphinx/util/matching.py +++ b/sphinx/util/matching.py @@ -9,7 +9,7 @@ """ import re -from typing import Callable, Dict, List, Match, Pattern +from typing import Callable, Dict, Iterable, List, Match, Pattern from sphinx.util.osutil import canon_path @@ -96,7 +96,7 @@ def patmatch(name: str, pat: str) -> Match[str]: return _pat_cache[pat].match(name) -def patfilter(names: List[str], pat: str) -> List[str]: +def patfilter(names: Iterable[str], pat: str) -> List[str]: """Return the subset of the list NAMES that match PAT. Adapted from fnmatch module. diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 06d3bcc2c..18c44ad18 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -55,7 +55,7 @@ class UnicodeMixin: def __str__(self): warnings.warn('UnicodeMixin is deprecated', RemovedInSphinx40Warning, stacklevel=2) - return self.__unicode__() + return self.__unicode__() # type: ignore def execfile_(filepath: str, _globals: Any, open: Callable = open) -> None: diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index d0bd38ce2..7a2874d2c 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -113,6 +113,10 @@ XELATEX_DEFAULT_FONTPKG = r''' BoldItalicFont = *BoldOblique, ] ''' +XELATEX_GREEK_DEFAULT_FONTPKG = (XELATEX_DEFAULT_FONTPKG + + '\n\\newfontfamily\\greekfont{FreeSerif}' + + '\n\\newfontfamily\\greekfontsf{FreeSans}' + + '\n\\newfontfamily\\greekfonttt{FreeMono}') LUALATEX_DEFAULT_FONTPKG = XELATEX_DEFAULT_FONTPKG DEFAULT_SETTINGS = { @@ -223,6 +227,9 @@ ADDITIONAL_SETTINGS = { ('xelatex', 'zh'): { 'fontenc': '\\usepackage{xeCJK}', }, + ('xelatex', 'el'): { + 'fontpkg': XELATEX_GREEK_DEFAULT_FONTPKG, + }, } # type: Dict[Any, Dict[str, Any]] EXTRA_RE = re.compile(r'^(.*\S)\s+\(([^()]*)\)\s*$') diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index a6e891ec6..8410bbd03 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -175,6 +175,17 @@ def test_latex_additional_settings_for_language_code(app, status, warning): assert r'\usepackage{xeCJK}' in result +@pytest.mark.sphinx('latex', testroot='basic', confoverrides={'language': 'el'}) +def test_latex_additional_settings_for_greek(app, status, warning): + app.builder.build_all() + result = (app.outdir / 'test.tex').text(encoding='utf8') + print(result) + print(status.getvalue()) + print(warning.getvalue()) + assert '\\usepackage{polyglossia}\n\\setmainlanguage{greek}' in result + assert '\\newfontfamily\\greekfonttt{FreeMono}' in result + + @pytest.mark.sphinx('latex', testroot='latex-title') def test_latex_title_after_admonitions(app, status, warning): app.builder.build_all() diff --git a/tests/test_ext_autodoc_mock.py b/tests/test_ext_autodoc_mock.py index 750feefa2..52033bec4 100644 --- a/tests/test_ext_autodoc_mock.py +++ b/tests/test_ext_autodoc_mock.py @@ -96,3 +96,24 @@ def test_abc_MockObject(): assert isinstance(obj, Base) assert isinstance(obj, _MockObject) assert isinstance(obj.some_method(), Derived) + + +def test_mock_decorator(): + mock = _MockObject() + + @mock.function_deco + def func(): + """docstring""" + + class Foo: + @mock.method_deco + def meth(self): + """docstring""" + + @mock.class_deco + class Bar: + """docstring""" + + assert func.__doc__ == "docstring" + assert Foo.meth.__doc__ == "docstring" + assert Bar.__doc__ == "docstring"