From dd711a7dc786060582e6f6580572d9ae6f7c78a7 Mon Sep 17 00:00:00 2001 From: Jakob Lykke Andersen Date: Sat, 9 Jun 2018 13:03:38 +0200 Subject: [PATCH 001/174] Search: make a difference between fullname and dispname --- sphinx/search/__init__.py | 4 ++-- tests/test_search.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py index fc55a2a45..1c5d0a848 100644 --- a/sphinx/search/__init__.py +++ b/sphinx/search/__init__.py @@ -331,13 +331,13 @@ class IndexBuilder(object): for domainname, domain in sorted(iteritems(self.env.domains)): for fullname, dispname, type, docname, anchor, prio in \ sorted(domain.get_objects()): - # XXX use dispname? if docname not in fn2index: continue if prio < 0: continue fullname = htmlescape(fullname) - prefix, name = rpartition(fullname, '.') + dispname = htmlescape(dispname) + prefix, name = rpartition(dispname, '.') pdict = rv.setdefault(prefix, {}) try: typeindex = otypes[domainname, type] diff --git a/tests/test_search.py b/tests/test_search.py index aa315c405..886151831 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -161,7 +161,7 @@ def test_IndexBuilder(): 'docnames': ('docname', 'docname2'), 'envversion': '1.0', 'filenames': ['filename', 'filename2'], - 'objects': {'': {'objname': (0, 0, 1, '#anchor')}}, + 'objects': {'': {'objdispname': (0, 0, 1, '#anchor')}}, 'objnames': {0: ('dummy', 'objtype', 'objtype')}, 'objtypes': {0: 'dummy:objtype'}, 'terms': {'comment': [0, 1], From 3691d6ca6418a2d1d2a7715126c158ec852d5904 Mon Sep 17 00:00:00 2001 From: Gabriel Laskar Date: Mon, 24 Apr 2017 02:49:15 +0200 Subject: [PATCH 002/174] latex writer: move ever template parts into latex.tex_t Signed-off-by: Gabriel Laskar --- sphinx/templates/latex/latex.tex_t | 4 ++++ sphinx/writers/latex.py | 8 -------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/sphinx/templates/latex/latex.tex_t b/sphinx/templates/latex/latex.tex_t index 0ea75557f..41f517330 100644 --- a/sphinx/templates/latex/latex.tex_t +++ b/sphinx/templates/latex/latex.tex_t @@ -44,6 +44,10 @@ \newcommand{\sphinxlogo}{<%= logo %>} \renewcommand{\releasename}{<%= releasename %>} <%= makeindex %> +\begin{document} +<%= shorthandoff %> +<%= maketitle %> +<%= tableofcontents %> <%= body %> <%= atendofbody %> <%= indices %> diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index e4fdf3ca1..afde39e18 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -47,13 +47,6 @@ if False: logger = logging.getLogger(__name__) -BEGIN_DOC = r''' -\begin{document} -%(shorthandoff)s -%(maketitle)s -%(tableofcontents)s -''' - SHORTHANDOFF = r''' \ifdefined\shorthandoff \ifnum\catcode`\=\string=\active\shorthandoff{=}\fi @@ -901,7 +894,6 @@ class LaTeXTranslator(nodes.NodeVisitor): self.curfilestack.append(node.get('docname', '')) if self.first_document == 1: # the first document is all the regular content ... - self.body.append(BEGIN_DOC % self.elements) self.first_document = 0 elif self.first_document == 0: # ... and all others are the appendices From a3bfccc11febdb2bc22c93d8850a9f379f798645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aliz=C3=A9e=20Penel?= Date: Fri, 25 May 2018 17:24:39 +0200 Subject: [PATCH 003/174] Add a test for multiple latex documents build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alizée Penel --- tests/roots/test-build-multiple-latex-docs/conf.py | 10 ++++++++++ tests/roots/test-build-multiple-latex-docs/file1.rst | 4 ++++ tests/roots/test-build-multiple-latex-docs/file2.rst | 4 ++++ tests/test_build_latex.py | 8 ++++++++ 4 files changed, 26 insertions(+) create mode 100644 tests/roots/test-build-multiple-latex-docs/conf.py create mode 100644 tests/roots/test-build-multiple-latex-docs/file1.rst create mode 100644 tests/roots/test-build-multiple-latex-docs/file2.rst diff --git a/tests/roots/test-build-multiple-latex-docs/conf.py b/tests/roots/test-build-multiple-latex-docs/conf.py new file mode 100644 index 000000000..002f791ee --- /dev/null +++ b/tests/roots/test-build-multiple-latex-docs/conf.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- + +master_doc = 'file2' + +latex_documents = [ + ('file1', 'file1.tex', 'Multiple files building test: file1', 'Sphinx', + 'article'), + ('file2', 'file2.tex', 'Multiple files building test: file2', 'Sphinx', + 'report'), +] diff --git a/tests/roots/test-build-multiple-latex-docs/file1.rst b/tests/roots/test-build-multiple-latex-docs/file1.rst new file mode 100644 index 000000000..0613d1ec6 --- /dev/null +++ b/tests/roots/test-build-multiple-latex-docs/file1.rst @@ -0,0 +1,4 @@ +Testing multiple latex documents build +====================================== + +This is the first document. diff --git a/tests/roots/test-build-multiple-latex-docs/file2.rst b/tests/roots/test-build-multiple-latex-docs/file2.rst new file mode 100644 index 000000000..a7b15a2e8 --- /dev/null +++ b/tests/roots/test-build-multiple-latex-docs/file2.rst @@ -0,0 +1,4 @@ +Testing multiple latex documents build +====================================== + +This is the second document. diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 56c1329f7..4d4d8b9de 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -122,6 +122,14 @@ def test_build_latex_doc(app, status, warning, engine, docclass): compile_latex_document(app) +@pytest.mark.sphinx('latex', testroot='build-multiple-latex-docs') +def test_build_multiple_latex_docs(app, status, warning): + app.builder.build_all() + + assert (app.outdir / 'file1.tex').isfile() + assert (app.outdir / 'file2.tex').isfile() + + @pytest.mark.sphinx('latex') def test_writer(app, status, warning): app.builder.build_all() From a8f23b1d44b0e328f1fb71f3c4bf9e18c147b309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aliz=C3=A9e=20Penel?= Date: Wed, 20 Jun 2018 00:36:13 +0200 Subject: [PATCH 004/174] test: check latex document beginning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Check some commands in latex basic test: * \begin{document} * \maketitle * \sphinxtableofcontents * Add a test on shorthandoff insertion Signed-off-by: Alizée Penel --- tests/test_build_latex.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 4d4d8b9de..06a6ce9a5 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -178,11 +178,27 @@ def test_latex_basic(app, status, warning): print(result) print(status.getvalue()) print(warning.getvalue()) + assert r'\begin{document}' in result + assert r'\maketitle' in result + assert r'\sphinxtableofcontents' in result assert r'\title{The basic Sphinx documentation for testing}' in result assert r'\release{}' in result assert r'\renewcommand{\releasename}{}' in result +@pytest.mark.sphinx('latex', testroot='basic', confoverrides={'language':'de'}) +def test_latex_shorthandoff(app, status, warning): + app.builder.build_all() + result = (app.outdir / 'test.tex').text(encoding='utf8') + print(result) + print(status.getvalue()) + print(warning.getvalue()) + assert ('\\ifdefined\\shorthandoff\n' + ' \\ifnum\\catcode`\\=\\string=\\active\\shorthandoff{=}\\fi\n' + ' \\ifnum\\catcode`\\"=\\active\\shorthandoff{"}\\fi\n' + '\\fi\n' in result) + + @pytest.mark.sphinx('latex', testroot='latex-title') def test_latex_title_after_admonitions(app, status, warning): app.builder.build_all() From 4cd90a644a30e14ba4a9138f634f90b448c05cff Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 25 Jun 2018 08:03:05 +0200 Subject: [PATCH 005/174] BuildDoc: add and pass through nitpicky option This allows for using e.g. `tox -e docs -- -n` with Sphinx's own `build_sphinx` distutils command. --- sphinx/setup_command.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sphinx/setup_command.py b/sphinx/setup_command.py index c54179227..c3957fefc 100644 --- a/sphinx/setup_command.py +++ b/sphinx/setup_command.py @@ -87,9 +87,10 @@ class BuildDoc(Command): ('link-index', 'i', 'Link index.html to the master doc'), ('copyright', None, 'The copyright string'), ('pdb', None, 'Start pdb on exception'), + ('nitpicky', 'n', 'nit-picky mode, warn about all missing references'), ] boolean_options = ['fresh-env', 'all-files', 'warning-is-error', - 'link-index'] + 'link-index', 'nitpicky'] def initialize_options(self): # type: () -> None @@ -107,6 +108,7 @@ class BuildDoc(Command): self.copyright = '' self.verbosity = 0 self.traceback = False + self.nitpicky = False def _guess_source_dir(self): # type: () -> unicode @@ -174,6 +176,8 @@ class BuildDoc(Command): confoverrides['today'] = self.today if self.copyright: confoverrides['copyright'] = self.copyright + if self.nitpicky: + confoverrides['nitpicky'] = self.nitpicky for builder, builder_target_dir in self.builder_target_dirs: app = None From 94b467dbc89d2057c5435dabc6861b34b219429f Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Sun, 1 Jul 2018 16:10:51 +0200 Subject: [PATCH 006/174] #4255 clarify documentation of ``startdocname`` parameters. * Relative path from source directory * Similar to ``master_doc`` in functionality --- doc/usage/configuration.rst | 58 +++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index a0fbe641a..98cc4ab8d 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -1765,20 +1765,30 @@ information. It must be a list of tuples ``(startdocname, targetname, title, author, documentclass, toctree_only)``, where the items are: - * *startdocname*: document name that is the "root" of the LaTeX file. All - documents referenced by it in TOC trees will be included in the LaTeX file - too. (If you want only one LaTeX file, use your :confval:`master_doc` - here.) - * *targetname*: file name of the LaTeX file in the output directory. - * *title*: LaTeX document title. Can be empty to use the title of the - *startdoc*. This is inserted as LaTeX markup, so special characters like a - backslash or ampersand must be represented by the proper LaTeX commands if - they are to be inserted literally. - * *author*: Author for the LaTeX document. The same LaTeX markup caveat as + *startdocname* + String that specifies the relative path (without file suffix) from the + source directory to the document that is the master document of the LaTeX + file. All documents referenced by the *startdoc* document in TOC trees + will be included in the LaTeX file. (If you want to use the default master + document for your LaTeX build, provide your :confval:`master_doc` here.) + + *targetname* + File name of the LaTeX file in the output directory. + + *title* + LaTeX document title. Can be empty to use the title of the + *startdoc* document. This is inserted as LaTeX markup, so special + characters like a backslash or ampersand must be represented by the proper + LaTeX commands if they are to be inserted literally. + + * *author* + Author for the LaTeX document. The same LaTeX markup caveat as for *title* applies. Use ``\\and`` to separate multiple authors, as in: ``'John \\and Sarah'`` (backslashes must be Python-escaped to reach LaTeX). - * *documentclass*: Normally, one of ``'manual'`` or ``'howto'`` (provided + + *documentclass* + Normally, one of ``'manual'`` or ``'howto'`` (provided by Sphinx and based on ``'report'``, resp. ``'article'``; Japanese documents use ``'jsbook'``, resp. ``'jreport'``.) "howto" (non-Japanese) documents will not get appendices. Also they have a simpler title page. @@ -1786,7 +1796,8 @@ information. the "sphinx" package is always loaded in order to define Sphinx's custom LaTeX commands. - * *toctree_only*: Must be ``True`` or ``False``. If true, the *startdoc* + *toctree_only* + Must be ``True`` or ``False``. If true, the *startdoc* document itself is not included in the output, only the documents referenced by it via TOC trees. With this option, you can put extra stuff in the master document that shows up in the HTML, but not the LaTeX @@ -2227,9 +2238,11 @@ These options influence manual page output. section)``, where the items are: *startdocname* - Document name that is the "root" of the manual page. All documents - referenced by it in TOC trees will be included in the manual file too. - (If you want one master manual page, use your :confval:`master_doc` here.) + String that specifies the relative path (without file suffix) from the + source directory to the document that is the master of the manual page. + All documents referenced by the *startdoc* document in TOC trees will be + included in the manual file. (If you want to use the default master + document for your manual pages build, use your :confval:`master_doc` here.) *name* Name of the manual page. This should be a short string without spaces or @@ -2272,17 +2285,20 @@ These options influence Texinfo output. are: *startdocname* - Document name that is the "root" of the Texinfo file. All documents - referenced by it in TOC trees will be included in the Texinfo file too. - (If you want only one Texinfo file, use your :confval:`master_doc` here.) + String that specifies the relative path (without file suffix) from the + source directory to the document that is the master document of the Texinfo + file. All documents referenced by the *startdoc* document in TOC trees + will be included in the Texinfo file. (If you want to use the default + master document for your Texinfo build, provide your :confval:`master_doc` + here.) *targetname* File name (no extension) of the Texinfo file in the output directory. *title* - Texinfo document title. Can be empty to use the title of the *startdoc*. - Inserted as Texinfo markup, so special characters like ``@`` and ``{}`` - will need to be escaped to be inserted literally. + Texinfo document title. Can be empty to use the title of the *startdoc* + document. Inserted as Texinfo markup, so special characters like ``@`` and + ``{}`` will need to be escaped to be inserted literally. *author* Author for the Texinfo document. Inserted as Texinfo markup. Use ``@*`` From 6fe8835037fac473265b856822c82d1bc9de7c76 Mon Sep 17 00:00:00 2001 From: Honza Javorek Date: Tue, 3 Jul 2018 14:00:33 +0200 Subject: [PATCH 007/174] add default Accept header There are situations where requested server replies with a different content (in my particular case HTTP 404) when there is no accept header, possibly because it evaluates the content negotiation to an API request instead of a browser request. This change adds a default Accept header, which equals to what my Firefox sets out of the box to its requests. I stumbled upon this when checking a link to https://crates.io/crates/dredd-hooks. While curl -i https://crates.io/crates/dredd-hooks returns HTTP 404, following results in an expected HTTP 200 response with HTML body: curl -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -i https://crates.io/crates/dredd-hooks --- sphinx/builders/linkcheck.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index 22e7f01ad..b43849022 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -120,12 +120,13 @@ class CheckExternalLinksBuilder(Builder): def check_thread(self): # type: () -> None - kwargs = {} + kwargs = { + 'allow_redirects': True, + 'headers': {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}, + } if self.app.config.linkcheck_timeout: kwargs['timeout'] = self.app.config.linkcheck_timeout - kwargs['allow_redirects'] = True - def check_uri(): # type: () -> Tuple[unicode, unicode, int] # split off anchor From 271e1d1340d669c890d6832f256304464702ff10 Mon Sep 17 00:00:00 2001 From: Honza Javorek Date: Tue, 3 Jul 2018 14:13:46 +0200 Subject: [PATCH 008/174] make linter happy --- sphinx/builders/linkcheck.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index b43849022..8079b680a 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -122,7 +122,10 @@ class CheckExternalLinksBuilder(Builder): # type: () -> None kwargs = { 'allow_redirects': True, - 'headers': {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}, + 'headers': { + 'Accept': ('text/html,application/xhtml+xml,' + 'application/xml;q=0.9,*/*;q=0.8') + }, } if self.app.config.linkcheck_timeout: kwargs['timeout'] = self.app.config.linkcheck_timeout From 9b2aac68ead15067205470ec28c94af909c080c0 Mon Sep 17 00:00:00 2001 From: jfbu Date: Sun, 15 Jul 2018 13:43:13 +0200 Subject: [PATCH 009/174] LaTeX: extend to all projects the #3742 fix for PDF builds at RTD Refs: https://github.com/rtfd/readthedocs.org/issues/2857 --- CHANGES | 5 +++++ doc/conf.py | 7 +------ doc/latex.rst | 20 ++++++++++++++++++-- doc/usage/configuration.rst | 17 ++++++++++------- sphinx/texinputs/sphinx.sty | 8 ++++++++ sphinx/writers/latex.py | 2 +- 6 files changed, 43 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index d7761f542..9f9a7b9ee 100644 --- a/CHANGES +++ b/CHANGES @@ -143,6 +143,11 @@ Features added for mathjax * #4362: latex: Don't overwrite .tex file if document not changed * #1431: latex: Add alphanumeric enumerated list support +* Extend to all projects not using the Sphinx LaTeX Makefile a workaround for + `issue rtfd/readthedocs.org#2857`__ about insufficient number of + ``pdflatex`` runs for index to show up in PDF bookmarks (refs: #3742) + + __ https://github.com/rtfd/readthedocs.org/issues/2857 Bugs fixed ---------- diff --git a/doc/conf.py b/doc/conf.py index 732c4d4a0..31cb8e478 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -64,12 +64,7 @@ latex_elements = { 'passoptionstopackages': '\\PassOptionsToPackage{svgnames}{xcolor}', 'preamble': '\\DeclareUnicodeCharacter{229E}{\\ensuremath{\\boxplus}}', 'fvset': '\\fvset{fontsize=auto}', - # fix missing index entry due to RTD doing only once pdflatex after makeindex - 'printindex': r''' -\IfFileExists{\jobname.ind} - {\footnotesize\raggedright\printindex} - {\begin{sphinxtheindex}\end{sphinxtheindex}} -''', + 'printindex': '\\footnotesize\\raggedright\\sphinxprintindex', } latex_show_urls = 'footnote' diff --git a/doc/latex.rst b/doc/latex.rst index cfd6f7d8b..ef0827957 100644 --- a/doc/latex.rst +++ b/doc/latex.rst @@ -55,7 +55,7 @@ example:: \setlength{\cftsecnumwidth}{1.25cm} ''', 'fncychap': r'\usepackage[Bjornstrup]{fncychap}', - 'printindex': r'\footnotesize\raggedright\printindex', + 'printindex': r'\footnotesize\raggedright\sphinxprintindex', } latex_show_urls = 'footnote' @@ -399,6 +399,21 @@ Macros :file:`sphinxmanual.cls` and :file:`sphinxhowto.cls`. - the citation reference is typeset via ``\sphinxcite`` which is a wrapper of standard ``\cite``. +- regarding the general index, the :confval:`latex_elements` dictionary has a + ``'printindex'`` key which defaults to ``'\\sphinxprintindex'``. It often + proves advantageous to use:: + + 'printindex': '\\footnotesize\\raggedright\\sphinxprintindex', + + especially if the index contains long entries. The LaTeX class for Japanese + ``'manual'``-type documents already does the font size and text + justification change, so the above is not needed then. + + .. tip:: + + Advanced LaTeX users can also, via :confval:`latex_additional_files`, use + a custom :file:`python.ist` style file for :program:`makeindex` to modify + the looks of the general index. Environments ~~~~~~~~~~~~ @@ -453,7 +468,8 @@ Environments - the bibliography uses ``sphinxthebibliography`` and the Python Module index as well as the general index both use ``sphinxtheindex``; these environments are wrappers of the ``thebibliography`` and respectively ``theindex`` - environments as provided by the document class (or packages). + environments, needed mainly to insert a corresponding entry in the PDF + bookmarks and table of contents. .. versionchanged:: 1.5 formerly, the original environments were modified by Sphinx. diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index a0fbe641a..01b67c498 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -1727,8 +1727,8 @@ the `Dublin Core metadata `_. Options for LaTeX output ------------------------ -These options influence LaTeX output. Refer to :doc:`/latex` for more -information. +These options influence LaTeX output. For customization of LaTeX +macros and environments, see also :doc:`/latex`. .. confval:: latex_engine @@ -2108,11 +2108,14 @@ information. Remove unneeded ``{}`` after ``\\hrule``. ``'printindex'`` - "printindex" call, the last thing in the file, default - ``'\\printindex'``. Override if you want to generate the index - differently or append some content after the index. For example - ``'\\footnotesize\\raggedright\\printindex'`` is advisable when the - index is full of long entries. + "printindex" call, the last thing in the file. + + .. versionchanged:: 1.8 + Former default ``'\\printindex'`` now ``'\\sphinxprintindex'``. + This macro works around an issue__ with PDF builds at RTD doing too + few ``pdflatex`` runs. + + __ https://github.com/rtfd/readthedocs.org/issues/2857 ``'fvset'`` Customization of ``fancyvrb`` LaTeX package. Defaults to diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 96be30338..bd8a26a30 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -459,6 +459,14 @@ } \fi +% provide \sphinxprintindex as variant of \printindex designed to workaround +% rtfd/readthedocs.org#2857 regarding "Index" entry in PDF bookmarks +\newcommand*{\sphinxprintindex}{% + \IfFileExists{\jobname.ind} + {\printindex} + {\begin{sphinxtheindex}\end{sphinxtheindex}}% +}% + % make commands known to non-Sphinx document classes \providecommand*{\sphinxtableofcontents}{\tableofcontents} \ltx@ifundefined{sphinxthebibliography} diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 55d37da79..9c184dc5f 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -124,7 +124,7 @@ DEFAULT_SETTINGS = { 'maketitle': '\\maketitle', 'tableofcontents': '\\sphinxtableofcontents', 'atendofbody': '', - 'printindex': '\\printindex', + 'printindex': '\\sphinxprintindex', 'transition': '\n\n\\bigskip\\hrule\\bigskip\n\n', 'figure_align': 'htbp', 'tocdepth': '', From 99e696415290900cc174defd8fa74ec8645dd0aa Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 21 Jun 2018 23:56:29 +0900 Subject: [PATCH 010/174] Handle errors on scanning documents (refs: #5114) --- CHANGES | 1 + sphinx/environment/__init__.py | 65 ++++++++++++++++++---------------- sphinx/errors.py | 5 +++ 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/CHANGES b/CHANGES index ca7bef359..c2a7b1c53 100644 --- a/CHANGES +++ b/CHANGES @@ -152,6 +152,7 @@ Bugs fixed * #4945: i18n: fix lang_COUNTRY not fallback correctly for IndexBuilder. Thanks to Shengjing Zhu. * #4983: productionlist directive generates invalid IDs for the tokens +* #5114: sphinx-build: Handle errors on scanning documents Testing -------- diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index e9f3338aa..fcc99b7cd 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -25,7 +25,7 @@ from sphinx import addnodes from sphinx.deprecation import RemovedInSphinx20Warning, RemovedInSphinx30Warning from sphinx.environment.adapters.indexentries import IndexEntries from sphinx.environment.adapters.toctree import TocTree -from sphinx.errors import SphinxError, BuildEnvironmentError, ExtensionError +from sphinx.errors import SphinxError, BuildEnvironmentError, DocumentError, ExtensionError from sphinx.locale import __ from sphinx.transforms import SphinxTransformer from sphinx.util import get_matching_docs, FilenameUniqDict @@ -416,37 +416,40 @@ class BuildEnvironment(object): """Find all source files in the source dir and put them in self.found_docs. """ - matchers = compile_matchers( - config.exclude_patterns[:] + - config.templates_path + - builder.get_asset_paths() + - ['**/_sources', '.#*', '**/.#*', '*.lproj/**'] - ) - self.found_docs = set() - for docname in get_matching_docs(self.srcdir, config.source_suffix, # type: ignore - exclude_matchers=matchers): - if os.access(self.doc2path(docname), os.R_OK): - self.found_docs.add(docname) - else: - logger.warning(__("document not readable. Ignored."), location=docname) + try: + matchers = compile_matchers( + config.exclude_patterns[:] + + config.templates_path + + builder.get_asset_paths() + + ['**/_sources', '.#*', '**/.#*', '*.lproj/**'] + ) + self.found_docs = set() + for docname in get_matching_docs(self.srcdir, config.source_suffix, # type: ignore + exclude_matchers=matchers): + if os.access(self.doc2path(docname), os.R_OK): + self.found_docs.add(docname) + else: + logger.warning(__("document not readable. Ignored."), location=docname) - # Current implementation is applying translated messages in the reading - # phase.Therefore, in order to apply the updated message catalog, it is - # necessary to re-process from the reading phase. Here, if dependency - # is set for the doc source and the mo file, it is processed again from - # the reading phase when mo is updated. In the future, we would like to - # move i18n process into the writing phase, and remove these lines. - if builder.use_message_catalog: - # add catalog mo file dependency - for docname in self.found_docs: - catalog_files = find_catalog_files( - docname, - self.srcdir, - self.config.locale_dirs, - self.config.language, - self.config.gettext_compact) - for filename in catalog_files: - self.dependencies[docname].add(filename) + # Current implementation is applying translated messages in the reading + # phase.Therefore, in order to apply the updated message catalog, it is + # necessary to re-process from the reading phase. Here, if dependency + # is set for the doc source and the mo file, it is processed again from + # the reading phase when mo is updated. In the future, we would like to + # move i18n process into the writing phase, and remove these lines. + if builder.use_message_catalog: + # add catalog mo file dependency + for docname in self.found_docs: + catalog_files = find_catalog_files( + docname, + self.srcdir, + self.config.locale_dirs, + self.config.language, + self.config.gettext_compact) + for filename in catalog_files: + self.dependencies[docname].add(filename) + except EnvironmentError as exc: + raise DocumentError(__('Failed to scan documents in %s: %r') % (self.srcdir, exc)) def get_outdated_files(self, config_changed): # type: (bool) -> Tuple[Set[unicode], Set[unicode], Set[unicode]] diff --git a/sphinx/errors.py b/sphinx/errors.py index 83c1bd9da..e97447e86 100644 --- a/sphinx/errors.py +++ b/sphinx/errors.py @@ -82,6 +82,11 @@ class ConfigError(SphinxError): category = 'Configuration error' +class DocumentError(SphinxError): + """Document error.""" + category = 'Document error' + + class ThemeError(SphinxError): """Theme error.""" category = 'Theme error' From 82f9c69b3c865c5b437e623f3bafb5bd6fc3ef45 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 16 Jul 2018 15:27:59 +0900 Subject: [PATCH 011/174] Fix #5163: html: hlist items are now aligned to top --- CHANGES | 1 + sphinx/themes/basic/static/basic.css_t | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGES b/CHANGES index ca7bef359..dafd09eb6 100644 --- a/CHANGES +++ b/CHANGES @@ -39,6 +39,7 @@ Incompatible changes Please use ``app.add_js_file()`` instead. * #5072: Save environment object also with only new documents * #5035: qthelp builder allows dashes in :confval:`qthelp_namespace` +* #5163: html: hlist items are now aligned to top Deprecated ---------- diff --git a/sphinx/themes/basic/static/basic.css_t b/sphinx/themes/basic/static/basic.css_t index d25c5af9d..cab3a342b 100644 --- a/sphinx/themes/basic/static/basic.css_t +++ b/sphinx/themes/basic/static/basic.css_t @@ -427,6 +427,13 @@ table.field-list td, table.field-list th { hyphens: manual; } +/* -- hlist styles ---------------------------------------------------------- */ + +table.hlist td { + vertical-align: top; +} + + /* -- other body styles ----------------------------------------------------- */ ol.arabic { From 02bccb67e17ab241d858b2c8f952acb8c8c73514 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 15 Jul 2018 22:23:26 +0900 Subject: [PATCH 012/174] Fix #5164: incremental build has broken with external source_parser --- sphinx/registry.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sphinx/registry.py b/sphinx/registry.py index f95a8fe7d..2c73dbbd3 100644 --- a/sphinx/registry.py +++ b/sphinx/registry.py @@ -39,6 +39,7 @@ if False: from docutils.transforms import Transform # NOQA from sphinx.application import Sphinx # NOQA from sphinx.builders import Builder # NOQA + from sphinx.config import Config # NOQA from sphinx.domains import Domain, Index # NOQA from sphinx.environment import BuildEnvironment # NOQA from sphinx.ext.autodoc import Documenter # NOQA @@ -270,7 +271,7 @@ class SphinxComponentRegistry(object): # type: (unicode, unicode, bool) -> None logger.debug('[app] adding source_suffix: %r, %r', suffix, filetype) if suffix in self.source_suffix and not override: - raise ExtensionError(__('source_parser for %r is already registered') % suffix) + raise ExtensionError(__('source_suffix %r is already registered') % suffix) else: self.source_suffix[suffix] = filetype @@ -290,7 +291,7 @@ class SphinxComponentRegistry(object): parser = args[1] if suffix: - self.add_source_suffix(suffix, suffix) + self.add_source_suffix(suffix, suffix, override=True) if len(parser.supported) == 0: warnings.warn('Old source_parser has been detected. Please fill Parser.supported ' @@ -493,8 +494,8 @@ class SphinxComponentRegistry(object): return envversion -def merge_source_suffix(app): - # type: (Sphinx) -> None +def merge_source_suffix(app, config): + # type: (Sphinx, Config) -> None """Merge source_suffix which specified by user and added by extensions.""" for suffix, filetype in iteritems(app.registry.source_suffix): if suffix not in app.config.source_suffix: @@ -510,7 +511,7 @@ def merge_source_suffix(app): def setup(app): # type: (Sphinx) -> Dict[unicode, Any] - app.connect('builder-inited', merge_source_suffix) + app.connect('config-inited', merge_source_suffix) return { 'version': 'builtin', From c126067f4ea1c70d37f4e04979c4afa9f508058b Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Mon, 16 Jul 2018 23:17:44 +0200 Subject: [PATCH 013/174] #4886 add tests to better cover the current link check ignore configuration behavior --- tests/roots/test-linkcheck/links.txt | 2 ++ tests/test_build_linkcheck.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/roots/test-linkcheck/links.txt b/tests/roots/test-linkcheck/links.txt index 36376bef4..d5057e08e 100644 --- a/tests/roots/test-linkcheck/links.txt +++ b/tests/roots/test-linkcheck/links.txt @@ -9,3 +9,5 @@ Some additional anchors to exercise ignore code * `Example Bar invalid `_ * `Example Bar invalid `_ tests that default ignore anchor of #! does not need to be prefixed with / * `Example Bar invalid `_ +* `Example anchor invalid `_ +* `Complete nonsense `_ diff --git a/tests/test_build_linkcheck.py b/tests/test_build_linkcheck.py index 839a15628..560eb2499 100644 --- a/tests/test_build_linkcheck.py +++ b/tests/test_build_linkcheck.py @@ -21,14 +21,21 @@ def test_defaults(app, status, warning): content = (app.outdir / 'output.txt').text() print(content) - # looking for #top should fail + # looking for '#top' and 'does-not-exist' not found should fail assert "Anchor 'top' not found" in content - assert len(content.splitlines()) == 1 + assert "Anchor 'does-not-exist' not found" in content + # looking for non-existent URL should fail + assert " Max retries exceeded with url: /doesnotexist" in content + assert len(content.splitlines()) == 3 @pytest.mark.sphinx( 'linkcheck', testroot='linkcheck', freshenv=True, - confoverrides={'linkcheck_anchors_ignore': ["^!", "^top$"]}) + confoverrides={'linkcheck_anchors_ignore': ["^!", "^top$"], + 'linkcheck_ignore': [ + 'https://localhost:7777/doesnotexist', + 'http://www.sphinx-doc.org/en/1.7/intro.html#*'] + }) def test_anchors_ignored(app, status, warning): app.builder.build_all() From 537a69e5180f3380490592204022ff30f4a7556e Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Mon, 16 Jul 2018 23:22:26 +0200 Subject: [PATCH 014/174] #4886 adjust documentation to match actual link check behavior --- doc/usage/configuration.rst | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 8db606515..288290a27 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -2485,12 +2485,20 @@ Options for the linkcheck builder .. confval:: linkcheck_anchors_ignore - A list of regular expressions that match URIs that should skip checking - the validity of anchors in links. This allows skipping entire sites, where - anchors are used to control dynamic pages, or just specific anchors within - a page, where JavaScript is used to add anchors dynamically, or use the - fragment as part of to trigger an internal REST request. Default is - ``["/#!"]``. + A list of regular expressions that match anchors Sphinx should skip when + checking the validity of anchors in links. This allows skipping anchors that + a website's JavaScript adds to control dynamic pages or when triggering an + internal REST request. Default is ``["^!"]``. + + .. note:: + + If you want to ignore anchors of a specific page or of pages that match a + specific pattern, use :confval:`linkcheck_ignore` instead, for example as + follows:: + + linkcheck_ignore = [ + 'http://www.sphinx-doc.org/en/1.7/intro.html#*' + ] .. versionadded:: 1.5 From e1772bafda88cac5e37142f67ef5cd4c8cc3c504 Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Tue, 17 Jul 2018 10:00:05 +0200 Subject: [PATCH 015/174] DOC: Fix typo: add_source_parsers() -> add_source_parser() --- doc/extdev/parserapi.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/extdev/parserapi.rst b/doc/extdev/parserapi.rst index 11a690387..0beb51711 100644 --- a/doc/extdev/parserapi.rst +++ b/doc/extdev/parserapi.rst @@ -12,7 +12,7 @@ __ http://docutils.sourceforge.net/docs/dev/hacking.html#parsing-the-document In Sphinx, the parser modules works as same as docutils. The parsers are registered to Sphinx by extensions using Application APIs; -:meth:`.Sphinx.add_source_suffix()` and :meth:`.Sphinx.add_source_parsers()`. +:meth:`.Sphinx.add_source_suffix()` and :meth:`.Sphinx.add_source_parser()`. The *source suffix* is a mapping from file suffix to file type. For example, ``.rst`` file is mapped to ``'restructuredtext'`` type. Sphinx uses the From fd3e7a56c3e48a0ef28f37cb234783e32df280c8 Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 17 Jul 2018 11:19:31 +0200 Subject: [PATCH 016/174] LaTeX: Fix #5134 Lisp syntax for some xindy merge-rule patterns --- sphinx/texinputs/sphinx.xdy | 47 +++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/sphinx/texinputs/sphinx.xdy b/sphinx/texinputs/sphinx.xdy index f0c8b8a65..5f1fa3aaf 100644 --- a/sphinx/texinputs/sphinx.xdy +++ b/sphinx/texinputs/sphinx.xdy @@ -91,26 +91,33 @@ ;; from non-ascii letters which end up (with pdflatex) as \IeC macros in .idx ;; file, with a blank. -(merge-rule "\\sphinxleftcurlybrace\{\}" "{") -(merge-rule "\\sphinxrightcurlybrace\{\}" "}") -(merge-rule "\\_" "_") -(merge-rule "\{\[\}" "[") -(merge-rule "\{\]\}" "]") -(merge-rule "\{\}`" "`") -(merge-rule "\\textbackslash\{\}" "\\") -(merge-rule "\\textasciitilde\{\}" "~~") -(merge-rule "\\textless\{\}" "<") -(merge-rule "\\textgreater\{\}" ">") -(merge-rule "\\textasciicircum\{\}" "^") -(merge-rule "\\P\{\}" "¶") -(merge-rule "\\S\{\}" "§") -(merge-rule "\\texteuro\{\}" "€") -(merge-rule "\\\(\\infty\\\)" "∞") -(merge-rule "\\\(\\pm\\\)" "±") -(merge-rule "\\\(\\rightarrow\\\)" "→") -(merge-rule "\\\(\\checkmark\\\)" "✓") -(merge-rule "\\textendash\{\}" "–") -(merge-rule "\\textbar\{\}" "|") +;; Details of the syntax are explained at +;; http://xindy.sourceforge.net/doc/manual-3.html +;; In absence of :string, "xindy uses an auto-detection mechanism to decide, +;; if the pattern is a regular expression or not". But it is not obvious to +;; guess, for example "\\_" is not detected as RE but "\\P\{\}" is, so for +;; being sure we apply the :string switch everywhere and do not use \\ etc... + +(merge-rule "\sphinxleftcurlybrace{}" "{" :string) +(merge-rule "\sphinxrightcurlybrace{}" "}" :string) +(merge-rule "\_" "_" :string) +(merge-rule "{[}" "[" :string) +(merge-rule "{]}" "]" :string) +(merge-rule "{}`" "`" :string) +(merge-rule "\textbackslash{}" "\" :string) ; " for Emacs syntax highlighting +(merge-rule "\textasciitilde{}" "~~" :string); the ~~ escape is needed here +(merge-rule "\textless{}" "<" :string) +(merge-rule "\textgreater{}" ">" :string) +(merge-rule "\textasciicircum{}" "^" :string) +(merge-rule "\P{}" "¶" :string) +(merge-rule "\S{}" "§" :string) +(merge-rule "\texteuro{}" "€" :string) +(merge-rule "\(\infty\)" "∞" :string) +(merge-rule "\(\pm\)" "±" :string) +(merge-rule "\(\rightarrow\)" "→" :string) +(merge-rule "\(\checkmark\)" "✓" :string) +(merge-rule "\textendash{}" "–" :string) +(merge-rule "\textbar{}" "|" :string) ;; This xindy module provides some basic support for "see" (require "makeindex.xdy") From e584b8e1db531be350c2f6fcf64a416803206738 Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 17 Jul 2018 15:45:30 +0200 Subject: [PATCH 017/174] Update LaTeX docs --- doc/latex.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/latex.rst b/doc/latex.rst index ef0827957..6118fdee6 100644 --- a/doc/latex.rst +++ b/doc/latex.rst @@ -412,8 +412,10 @@ Macros .. tip:: Advanced LaTeX users can also, via :confval:`latex_additional_files`, use - a custom :file:`python.ist` style file for :program:`makeindex` to modify - the looks of the general index. + a custom :program:`makeindex` style file :file:`python.ist`, or a custom + :program:`xindy` style file :file:`sphinx.xdy` (see + :confval:`latex_use_xindy`) in order to modify how the general index is + typeset. Environments ~~~~~~~~~~~~ From f605012617d4e1005cab02393fb0cf4ea9cd435f Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Tue, 17 Jul 2018 20:40:49 +0200 Subject: [PATCH 018/174] #4886 remove obsolete `*` --- doc/usage/configuration.rst | 2 +- tests/test_build_linkcheck.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 288290a27..288b95ae4 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -2497,7 +2497,7 @@ Options for the linkcheck builder follows:: linkcheck_ignore = [ - 'http://www.sphinx-doc.org/en/1.7/intro.html#*' + 'http://www.sphinx-doc.org/en/1.7/intro.html#' ] .. versionadded:: 1.5 diff --git a/tests/test_build_linkcheck.py b/tests/test_build_linkcheck.py index 560eb2499..1716a0c42 100644 --- a/tests/test_build_linkcheck.py +++ b/tests/test_build_linkcheck.py @@ -34,7 +34,7 @@ def test_defaults(app, status, warning): confoverrides={'linkcheck_anchors_ignore': ["^!", "^top$"], 'linkcheck_ignore': [ 'https://localhost:7777/doesnotexist', - 'http://www.sphinx-doc.org/en/1.7/intro.html#*'] + 'http://www.sphinx-doc.org/en/1.7/intro.html#'] }) def test_anchors_ignored(app, status, warning): app.builder.build_all() From c2a396c776bf4dbc6c92e47808ab553ad262ec48 Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 17 Jul 2018 23:54:53 +0200 Subject: [PATCH 019/174] LaTeX: for Cyrillic and with xindy, get Latin letter groups too Refs: #5134 --- sphinx/texinputs/Makefile_t | 3 ++ sphinx/texinputs/sphinx-basiclatin.xdy | 42 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 sphinx/texinputs/sphinx-basiclatin.xdy diff --git a/sphinx/texinputs/Makefile_t b/sphinx/texinputs/Makefile_t index 1ce4b1324..97054def0 100644 --- a/sphinx/texinputs/Makefile_t +++ b/sphinx/texinputs/Makefile_t @@ -27,6 +27,9 @@ export XINDYOPTS = {{ xindy_lang_option }} -M sphinx.xdy {% if latex_engine == 'pdflatex' and xindy_cyrillic -%} XINDYOPTS += -M cyrLICRutf8.xdy {% endif -%} +{% if xindy_cyrillic -%} +XINDYOPTS += -M sphinx-basiclatin.xdy +{% endif -%} {% if latex_engine == 'xelatex' or latex_engine == 'lualatex' -%} XINDYOPTS += -I xelatex {% endif -%} diff --git a/sphinx/texinputs/sphinx-basiclatin.xdy b/sphinx/texinputs/sphinx-basiclatin.xdy new file mode 100644 index 000000000..f611ac5ca --- /dev/null +++ b/sphinx/texinputs/sphinx-basiclatin.xdy @@ -0,0 +1,42 @@ +;; xindy style file to provide indexing of (ascii) Latin names +;; in an otherwise non-Latin (i.e. Cyrillic) context. +;; TODO: should we support also iso-latin-1 ? +;; Contributed by the Sphinx team, July 2018. + +(define-letter-groups + ("A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" + "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z")) + +(define-rule-set "latin-toupper" + + :rules (("a" "A" :string :again) + ("b" "B" :string :again) + ("c" "C" :string :again) + ("d" "D" :string :again) + ("e" "E" :string :again) + ("f" "F" :string :again) + ("g" "G" :string :again) + ("h" "H" :string :again) + ("i" "I" :string :again) + ("j" "J" :string :again) + ("k" "K" :string :again) + ("l" "L" :string :again) + ("m" "M" :string :again) + ("n" "N" :string :again) + ("o" "O" :string :again) + ("p" "P" :string :again) + ("q" "Q" :string :again) + ("r" "R" :string :again) + ("s" "S" :string :again) + ("t" "T" :string :again) + ("u" "U" :string :again) + ("v" "V" :string :again) + ("w" "W" :string :again) + ("x" "X" :string :again) + ("y" "Y" :string :again) + ("z" "Z" :string :again) + )) + +(use-rule-set + :run 0 + :rule-set ("latin-toupper")) From c62aefd71f24dbf6b40f4f1624523b9b2eae4bf4 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 19 Jul 2018 01:18:39 +0900 Subject: [PATCH 020/174] Fix mypy violation --- sphinx/setup_command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx/setup_command.py b/sphinx/setup_command.py index c3957fefc..ca3256c19 100644 --- a/sphinx/setup_command.py +++ b/sphinx/setup_command.py @@ -28,7 +28,7 @@ from sphinx.util.osutil import abspath if False: # For type annotation - from typing import Any, List, Tuple # NOQA + from typing import Any, Dict, List, Tuple # NOQA class BuildDoc(Command): @@ -165,7 +165,7 @@ class BuildDoc(Command): status_stream = StringIO() else: status_stream = sys.stdout # type: ignore - confoverrides = {} + confoverrides = {} # type: Dict[unicode, Any] if self.project: confoverrides['project'] = self.project if self.version: From f72a53f5bd46bfb100e56a1a07fa177f459c2fd3 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 19 Jul 2018 01:22:20 +0900 Subject: [PATCH 021/174] Update docs for #5122 (nitpicky option) --- CHANGES | 1 + doc/setuptools.rst | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGES b/CHANGES index bad46f5f8..e57a0dad6 100644 --- a/CHANGES +++ b/CHANGES @@ -161,6 +161,7 @@ Features added * Add :confval:`latex_use_xindy` for UTF-8 savvy indexing, defaults to ``True`` if :confval:`latex_engine` is ``'xelatex'`` or ``'lualatex'``. * #4976: ``SphinxLoggerAdapter.info()`` now supports ``location`` parameter +* #5122: setuptools: support nitpicky option Bugs fixed ---------- diff --git a/doc/setuptools.rst b/doc/setuptools.rst index 10f732559..10cc6a77d 100644 --- a/doc/setuptools.rst +++ b/doc/setuptools.rst @@ -181,6 +181,14 @@ Options for setuptools integration .. versionadded:: 1.3 +.. confval:: nitpicky + + Run in nit-picky mode. Currently, this generates warnings for all missing + references. See the config value :confval:`nitpick_ignore` for a way to + exclude some references as "known missing". + + .. versionadded:: 1.8 + .. confval:: pdb A boolean to configure ``pdb`` on exception. Default is false. From 8066d36e3cba5eabc09ed95dc2f9055d4badc2ca Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Wed, 18 Jul 2018 19:40:22 +0200 Subject: [PATCH 022/174] #4886 clarify example/note --- doc/usage/configuration.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 288b95ae4..22d0966b4 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -2493,8 +2493,9 @@ Options for the linkcheck builder .. note:: If you want to ignore anchors of a specific page or of pages that match a - specific pattern, use :confval:`linkcheck_ignore` instead, for example as - follows:: + specific pattern (but still check occurrences of the same page(s) that + don't have anchors), use :confval:`linkcheck_ignore` instead, for example + as follows:: linkcheck_ignore = [ 'http://www.sphinx-doc.org/en/1.7/intro.html#' From f272d6876cb499ac25f779e606593e3459e565b7 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 20 Jul 2018 01:28:38 +0900 Subject: [PATCH 023/174] Remove unused code Now sphinx depends on pygments-2.0 or higher. So this code is not passed. --- sphinx/highlighting.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index 7d5956570..dd248107c 100644 --- a/sphinx/highlighting.py +++ b/sphinx/highlighting.py @@ -161,8 +161,6 @@ class PygmentsBridge(object): if self.dest == 'html': return hlsource else: - if not isinstance(hlsource, text_type): # Py2 / Pygments < 1.6 - hlsource = hlsource.decode() return hlsource.translate(tex_hl_escape_map_new) def get_stylesheet(self): From 395d60d49e982a5113afb0ab0118ae1250d9c23a Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Thu, 19 Jul 2018 21:10:16 +0200 Subject: [PATCH 024/174] #4255 improve conciseness --- doc/usage/configuration.rst | 65 +++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 98cc4ab8d..b4d4a4f84 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -1766,9 +1766,8 @@ information. documentclass, toctree_only)``, where the items are: *startdocname* - String that specifies the relative path (without file suffix) from the - source directory to the document that is the master document of the LaTeX - file. All documents referenced by the *startdoc* document in TOC trees + String that specifies the :term:`document name` of the LaTeX file's master + document. All documents referenced by the *startdoc* document in TOC trees will be included in the LaTeX file. (If you want to use the default master document for your LaTeX build, provide your :confval:`master_doc` here.) @@ -1776,32 +1775,29 @@ information. File name of the LaTeX file in the output directory. *title* - LaTeX document title. Can be empty to use the title of the - *startdoc* document. This is inserted as LaTeX markup, so special - characters like a backslash or ampersand must be represented by the proper - LaTeX commands if they are to be inserted literally. + LaTeX document title. Can be empty to use the title of the *startdoc* + document. This is inserted as LaTeX markup, so special characters like a + backslash or ampersand must be represented by the proper LaTeX commands if + they are to be inserted literally. - * *author* - Author for the LaTeX document. The same LaTeX markup caveat as - for *title* applies. Use ``\\and`` to separate multiple authors, as in: - ``'John \\and Sarah'`` (backslashes must be Python-escaped to reach - LaTeX). + *author* + Author for the LaTeX document. The same LaTeX markup caveat as for *title* + applies. Use ``\\and`` to separate multiple authors, as in: + ``'John \\and Sarah'`` (backslashes must be Python-escaped to reach LaTeX). *documentclass* - Normally, one of ``'manual'`` or ``'howto'`` (provided - by Sphinx and based on ``'report'``, resp. ``'article'``; Japanese - documents use ``'jsbook'``, resp. ``'jreport'``.) "howto" (non-Japanese) - documents will not get appendices. Also they have a simpler title page. - Other document classes can be given. Independently of the document class, - the "sphinx" package is always loaded in order to define Sphinx's custom - LaTeX commands. + Normally, one of ``'manual'`` or ``'howto'`` (provided by Sphinx and based + on ``'report'``, resp. ``'article'``; Japanese documents use ``'jsbook'``, + resp. ``'jreport'``.) "howto" (non-Japanese) documents will not get + appendices. Also they have a simpler title page. Other document classes + can be given. Independently of the document class, the "sphinx" package is + always loaded in order to define Sphinx's custom LaTeX commands. *toctree_only* - Must be ``True`` or ``False``. If true, the *startdoc* - document itself is not included in the output, only the documents - referenced by it via TOC trees. With this option, you can put extra stuff - in the master document that shows up in the HTML, but not the LaTeX - output. + Must be ``True`` or ``False``. If true, the *startdoc* document itself is + not included in the output, only the documents referenced by it via TOC + trees. With this option, you can put extra stuff in the master document + that shows up in the HTML, but not the LaTeX output. .. versionadded:: 1.2 In the past including your own document class required you to prepend the @@ -2238,11 +2234,11 @@ These options influence manual page output. section)``, where the items are: *startdocname* - String that specifies the relative path (without file suffix) from the - source directory to the document that is the master of the manual page. - All documents referenced by the *startdoc* document in TOC trees will be - included in the manual file. (If you want to use the default master - document for your manual pages build, use your :confval:`master_doc` here.) + String that specifies the :term:`document name` of the manual page's master + document. All documents referenced by the *startdoc* document in TOC trees + will be included in the manual file. (If you want to use the default + master document for your manual pages build, use your :confval:`master_doc` + here.) *name* Name of the manual page. This should be a short string without spaces or @@ -2285,12 +2281,11 @@ These options influence Texinfo output. are: *startdocname* - String that specifies the relative path (without file suffix) from the - source directory to the document that is the master document of the Texinfo - file. All documents referenced by the *startdoc* document in TOC trees - will be included in the Texinfo file. (If you want to use the default - master document for your Texinfo build, provide your :confval:`master_doc` - here.) + String that specifies the :term:`document name` of the the Texinfo file's + master document. All documents referenced by the *startdoc* document in + TOC trees will be included in the Texinfo file. (If you want to use the + default master document for your Texinfo build, provide your + :confval:`master_doc` here.) *targetname* File name (no extension) of the Texinfo file in the output directory. From 0c277f3ff007a464d7769c9561c449428d38dabc Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 20 Jul 2018 01:37:31 +0900 Subject: [PATCH 025/174] ``sphinx.highlighting.PygmentsBridge.unhighlight()`` is deprecated --- CHANGES | 1 + doc/extdev/index.rst | 5 +++++ sphinx/highlighting.py | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/CHANGES b/CHANGES index e57a0dad6..e1aa4e5f8 100644 --- a/CHANGES +++ b/CHANGES @@ -102,6 +102,7 @@ Deprecated * ``sphinx.ext.mathbase.eqref`` node is deprecated * ``sphinx.ext.mathbase.is_in_section_title()`` is deprecated * ``sphinx.ext.mathbase.MathDomain`` is deprecated +* ``sphinx.highlighting.PygmentsBridge.unhighlight()`` is deprecated For more details, see `deprecation APIs list `_ diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst index 7aa6a7948..98824f7ed 100644 --- a/doc/extdev/index.rst +++ b/doc/extdev/index.rst @@ -131,6 +131,11 @@ The following is a list of deprecated interface. - 4.0 - :meth:`~sphinx.application.Sphinx.add_js_file()` + * - ``sphinx.highlighting.PygmentsBridge.unhighlight()`` + - 1.8 + - 3.0 + - N/A + * - ``sphinx.ext.mathbase.MathDomain`` - 1.8 - 3.0 diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index dd248107c..f31ff88cc 100644 --- a/sphinx/highlighting.py +++ b/sphinx/highlighting.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +import warnings + from pygments import highlight from pygments.filters import ErrorToken from pygments.formatters import HtmlFormatter, LatexFormatter @@ -20,6 +22,7 @@ from pygments.styles import get_style_by_name from pygments.util import ClassNotFound from six import text_type +from sphinx.deprecation import RemovedInSphinx30Warning from sphinx.ext import doctest from sphinx.locale import __ from sphinx.pygments_styles import SphinxStyle, NoneStyle @@ -93,6 +96,8 @@ class PygmentsBridge(object): def unhighlighted(self, source): # type: (unicode) -> unicode + warnings.warn('PygmentsBridge.unhighlighted() is now deprecated.', + RemovedInSphinx30Warning) if self.dest == 'html': return '
' + htmlescape(source) + '
\n' else: From 2bafb531795258223ed3d81a005b19338f8b1a5e Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 20 Jul 2018 18:44:01 +0900 Subject: [PATCH 026/174] Add testcase for trim_doctest_flags --- tests/roots/test-trim_doctest_flags/conf.py | 9 ++++++ tests/roots/test-trim_doctest_flags/index.rst | 23 +++++++++++++ tests/test_config_trim_doctest_flags.py | 32 +++++++++++++++++++ tests/test_highlighting.py | 10 ------ 4 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 tests/roots/test-trim_doctest_flags/conf.py create mode 100644 tests/roots/test-trim_doctest_flags/index.rst create mode 100644 tests/test_config_trim_doctest_flags.py diff --git a/tests/roots/test-trim_doctest_flags/conf.py b/tests/roots/test-trim_doctest_flags/conf.py new file mode 100644 index 000000000..693c7c371 --- /dev/null +++ b/tests/roots/test-trim_doctest_flags/conf.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- + +master_doc = 'index' + +extensions = ['sphinx.ext.doctest'] + +latex_documents = [ + (master_doc, 'test.tex', 'The basic Sphinx documentation for testing', 'Sphinx', 'report') +] diff --git a/tests/roots/test-trim_doctest_flags/index.rst b/tests/roots/test-trim_doctest_flags/index.rst new file mode 100644 index 000000000..1934d617b --- /dev/null +++ b/tests/roots/test-trim_doctest_flags/index.rst @@ -0,0 +1,23 @@ +test-trim_doctest_flags +======================= + +.. code-block:: pycon + + >>> datetime.date.now() # doctest: +FOO + datetime.date(2008, 1, 1) + +.. code-block:: none + + >>> datetime.date.now() # doctest: +BAR + datetime.date(2008, 1, 1) + +.. code-block:: guess + + # vim: set filetype=pycon + >>> datetime.date.now() # doctest: +BAZ + datetime.date(2008, 1, 1) + +.. testcode:: + + >>> datetime.date.now() # doctest: +QUX + datetime.date(2008, 1, 1) diff --git a/tests/test_config_trim_doctest_flags.py b/tests/test_config_trim_doctest_flags.py new file mode 100644 index 000000000..3be1b27a2 --- /dev/null +++ b/tests/test_config_trim_doctest_flags.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +""" + test_config_trim_doctest_flags + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import pytest + + +@pytest.mark.sphinx('html', testroot='trim_doctest_flags') +def test_trim_doctest_flags_html(app, status, warning): + app.build() + + result = (app.outdir / 'index.html').text(encoding='utf8') + assert 'FOO' not in result + assert 'BAR' in result + assert 'BAZ' not in result + assert 'QUX' not in result + + +@pytest.mark.sphinx('latex', testroot='trim_doctest_flags') +def test_trim_doctest_flags_latex(app, status, warning): + app.build() + + result = (app.outdir / 'test.tex').text(encoding='utf8') + assert 'FOO' not in result + assert 'BAR' in result + assert 'BAZ' not in result + assert 'QUX' not in result diff --git a/tests/test_highlighting.py b/tests/test_highlighting.py index 6b11926c9..29a4c043a 100644 --- a/tests/test_highlighting.py +++ b/tests/test_highlighting.py @@ -76,16 +76,6 @@ def test_set_formatter(): PygmentsBridge.html_formatter = HtmlFormatter -def test_trim_doctest_flags(): - PygmentsBridge.html_formatter = MyFormatter - try: - bridge = PygmentsBridge('html', trim_doctest_flags=True) - ret = bridge.highlight_block('>>> 1+2 # doctest: SKIP\n3\n', 'pycon') - assert ret == '>>> 1+2 \n3\n' - finally: - PygmentsBridge.html_formatter = HtmlFormatter - - @mock.patch('sphinx.highlighting.logger') def test_default_highlight(logger): bridge = PygmentsBridge('html') From 4f296c5e6789292bbacd0558c2d671fa5025d580 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 21 Jul 2018 00:13:31 +0900 Subject: [PATCH 027/174] Refactor: Run highlightlang on resolving phase --- CHANGES | 10 ++ doc/extdev/index.rst | 45 +++++++++ sphinx/application.py | 1 + sphinx/transforms/post_transforms/code.py | 106 ++++++++++++++++++++++ sphinx/writers/html.py | 62 ++++++++----- sphinx/writers/html5.py | 62 ++++++++----- sphinx/writers/latex.py | 42 +++------ sphinx/writers/manpage.py | 8 -- sphinx/writers/texinfo.py | 8 -- sphinx/writers/text.py | 4 - 10 files changed, 253 insertions(+), 95 deletions(-) create mode 100644 sphinx/transforms/post_transforms/code.py diff --git a/CHANGES b/CHANGES index e1aa4e5f8..e5d143104 100644 --- a/CHANGES +++ b/CHANGES @@ -49,6 +49,7 @@ Incompatible changes upgrading Sphinx, please clean latex build repertory of existing project before new build. * #5163: html: hlist items are now aligned to top +* ``highlightlang`` directive is processed on resolving phase Deprecated ---------- @@ -96,7 +97,16 @@ Deprecated * ``sphinx.writers.latex.LaTeXTranslator.push_hyperlink_ids()`` is deprecated * ``sphinx.writers.latex.LaTeXTranslator.pop_hyperlink_ids()`` is deprecated * ``sphinx.writers.latex.LaTeXTranslator.bibitems`` is deprecated +* ``sphinx.writers.latex.LaTeXTranslator.hlsettingstack`` is deprecated * ``sphinx.writers.latex.ExtBabel.get_shorthandoff()`` is deprecated +* ``sphinx.writers.html.HTMLTranslator.highlightlang`` is deprecated +* ``sphinx.writers.html.HTMLTranslator.highlightlang_base`` is deprecated +* ``sphinx.writers.html.HTMLTranslator.highlightlangopts`` is deprecated +* ``sphinx.writers.html.HTMLTranslator.highlightlinenothreshold`` is deprecated +* ``sphinx.writers.html5.HTMLTranslator.highlightlang`` is deprecated +* ``sphinx.writers.html5.HTMLTranslator.highlightlang_base`` is deprecated +* ``sphinx.writers.html5.HTMLTranslator.highlightlangopts`` is deprecated +* ``sphinx.writers.html5.HTMLTranslator.highlightlinenothreshold`` is deprecated * ``sphinx.ext.mathbase.math`` node is deprecated * ``sphinx.ext.mathbase.displaymath`` node is deprecated * ``sphinx.ext.mathbase.eqref`` node is deprecated diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst index 98824f7ed..fe0d1b97e 100644 --- a/doc/extdev/index.rst +++ b/doc/extdev/index.rst @@ -221,11 +221,56 @@ The following is a list of deprecated interface. - 3.0 - N/A + * - ``sphinx.writers.latex.LaTeXTranslator.hlsettingstack`` + - 1.8 + - 3.0 + - N/A + * - ``sphinx.writers.latex.ExtBabel.get_shorthandoff()`` - 1.8 - 3.0 - N/A + * - ``sphinx.writers.html.HTMLTranslator.highlightlang()`` + - 1.8 + - 3.0 + - N/A + + * - ``sphinx.writers.html.HTMLTranslator.highlightlang_base()`` + - 1.8 + - 3.0 + - N/A + + * - ``sphinx.writers.html.HTMLTranslator.highlightlangopts()`` + - 1.8 + - 3.0 + - N/A + + * - ``sphinx.writers.html.HTMLTranslator.highlightlinenothreshold()`` + - 1.8 + - 3.0 + - N/A + + * - ``sphinx.writers.html5.HTMLTranslator.highlightlang()`` + - 1.8 + - 3.0 + - N/A + + * - ``sphinx.writers.html5.HTMLTranslator.highlightlang_base()`` + - 1.8 + - 3.0 + - N/A + + * - ``sphinx.writers.html5.HTMLTranslator.highlightlangopts()`` + - 1.8 + - 3.0 + - N/A + + * - ``sphinx.writers.html5.HTMLTranslator.highlightlinenothreshold()`` + - 1.8 + - 3.0 + - N/A + * - ``sphinx.application.CONFIG_FILENAME`` - 1.8 - 3.0 diff --git a/sphinx/application.py b/sphinx/application.py index 2bf40e115..0f887b2a5 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -96,6 +96,7 @@ builtin_extensions = ( 'sphinx.registry', 'sphinx.roles', 'sphinx.transforms.post_transforms', + 'sphinx.transforms.post_transforms.code', 'sphinx.transforms.post_transforms.images', 'sphinx.transforms.post_transforms.compat', 'sphinx.util.compat', diff --git a/sphinx/transforms/post_transforms/code.py b/sphinx/transforms/post_transforms/code.py new file mode 100644 index 000000000..f0c1d0097 --- /dev/null +++ b/sphinx/transforms/post_transforms/code.py @@ -0,0 +1,106 @@ +# -*- coding: utf-8 -*- +""" + sphinx.transforms.post_transforms.code + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + transforms for code-blocks. + + :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import sys +from typing import NamedTuple + +from docutils import nodes +from six import text_type + +from sphinx import addnodes +from sphinx.transforms import SphinxTransform + +if False: + # For type annotation + from typing import Any, Dict, List # NOQA + from sphinx.application import Sphinx # NOQA + + +HighlightSetting = NamedTuple('HighlightSetting', [('language', text_type), + ('lineno_threshold', int)]) + + +class HighlightLanguageTransform(SphinxTransform): + """ + Apply highlight_language to all literal_block nodes. + + This refers both :confval:`highlight_language` setting and + :rst:dir:`highlightlang` directive. After processing, this transform + removes ``highlightlang`` node from doctree. + """ + default_priority = 400 + + def apply(self): + visitor = HighlightLanguageVisitor(self.document, + self.config.highlight_language) + self.document.walkabout(visitor) + + for node in self.document.traverse(addnodes.highlightlang): + node.parent.remove(node) + + +class HighlightLanguageVisitor(nodes.NodeVisitor): + def __init__(self, document, default_language): + # type: (nodes.document, unicode) -> None + self.default_setting = HighlightSetting(default_language, sys.maxsize) + self.settings = [] # type: List[HighlightSetting] + nodes.NodeVisitor.__init__(self, document) + + def unknown_visit(self, node): + # type: (nodes.Node) -> None + pass + + def unknown_departure(self, node): + # type: (nodes.Node) -> None + pass + + def visit_document(self, node): + # type: (nodes.Node) -> None + self.settings.append(self.default_setting) + + def depart_document(self, node): + # type: (nodes.Node) -> None + self.settings.pop() + + def visit_start_of_file(self, node): + # type: (nodes.Node) -> None + self.settings.append(self.default_setting) + + def depart_start_of_file(self, node): + # type: (nodes.Node) -> None + self.settings.pop() + + def visit_highlightlang(self, node): + # type: (addnodes.highlightlang) -> None + self.settings[-1] = HighlightSetting(node['lang'], node['linenothreshold']) + + def visit_literal_block(self, node): + # type: (nodes.literal_block) -> None + setting = self.settings[-1] + if 'language' not in node: + node['language'] = setting.language + node['force_highlighting'] = False + else: + node['force_highlighting'] = True + if 'linenos' not in node: + lines = node.astext().count('\n') + node['linenos'] = (lines >= setting.lineno_threshold - 1) + + +def setup(app): + # type: (Sphinx) -> Dict[unicode, Any] + app.add_post_transform(HighlightLanguageTransform) + + return { + 'version': 'builtin', + 'parallel_read_safe': True, + 'parallel_write_safe': True, + } diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index 0586636df..1a2da99d2 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -13,12 +13,14 @@ import copy import os import posixpath import sys +import warnings from docutils import nodes from docutils.writers.html4css1 import Writer, HTMLTranslator as BaseTranslator from six import string_types from sphinx import addnodes +from sphinx.deprecation import RemovedInSphinx30Warning from sphinx.locale import admonitionlabels, _, __ from sphinx.util import logging from sphinx.util.images import get_image_size @@ -74,10 +76,6 @@ class HTMLTranslator(BaseTranslator): BaseTranslator.__init__(self, *args, **kwds) self.highlighter = builder.highlighter self.builder = builder - self.highlightlang = self.highlightlang_base = \ - builder.config.highlight_language - self.highlightopts = builder.config.highlight_options - self.highlightlinenothreshold = sys.maxsize self.docnames = [builder.current_docname] # for singlehtml builder self.manpages_url = builder.config.manpages_url self.protect_literal_text = 0 @@ -423,19 +421,14 @@ class HTMLTranslator(BaseTranslator): if node.rawsource != node.astext(): # most probably a parsed-literal block -- don't highlight return BaseTranslator.visit_literal_block(self, node) - lang = self.highlightlang - linenos = node.rawsource.count('\n') >= \ - self.highlightlinenothreshold - 1 + + lang = node.get('language', 'default') + linenos = node.get('linenos', False) highlight_args = node.get('highlight_args', {}) - if 'language' in node: - # code-block directives - lang = node['language'] - highlight_args['force'] = True - if 'linenos' in node: - linenos = node['linenos'] - if lang is self.highlightlang_base: + highlight_args['force'] = node.get('force_highlighting', False) + if lang is self.builder.config.highlight_language: # only pass highlighter options for original language - opts = self.highlightopts + opts = self.builder.config.highlight_options else: opts = {} @@ -569,15 +562,6 @@ class HTMLTranslator(BaseTranslator): # type: (nodes.Node) -> None pass - def visit_highlightlang(self, node): - # type: (nodes.Node) -> None - self.highlightlang = node['lang'] - self.highlightlinenothreshold = node['linenothreshold'] - - def depart_highlightlang(self, node): - # type: (nodes.Node) -> None - pass - def visit_download_reference(self, node): # type: (nodes.Node) -> None if self.builder.download_support and node.hasattr('filename'): @@ -883,3 +867,33 @@ class HTMLTranslator(BaseTranslator): def unknown_visit(self, node): # type: (nodes.Node) -> None raise NotImplementedError('Unknown node: ' + node.__class__.__name__) + + # --------- METHODS FOR COMPATIBILITY -------------------------------------- + + @property + def highlightlang(self): + # type: () -> unicode + warnings.warn('HTMLTranslator.highlightlang is deprecated.', + RemovedInSphinx30Warning) + return self.builder.config.highlight_language + + @property + def highlightlang_base(self): + # type: () -> unicode + warnings.warn('HTMLTranslator.highlightlang_base is deprecated.', + RemovedInSphinx30Warning) + return self.builder.config.highlight_language + + @property + def highlightopts(self): + # type: () -> unicode + warnings.warn('HTMLTranslator.highlightopts is deprecated.', + RemovedInSphinx30Warning) + return self.builder.config.highlight_options + + @property + def highlightlinenothreshold(self): + # type: () -> int + warnings.warn('HTMLTranslator.highlightlinenothreshold is deprecated.', + RemovedInSphinx30Warning) + return sys.maxsize diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py index 85a7ef7c2..de2591985 100644 --- a/sphinx/writers/html5.py +++ b/sphinx/writers/html5.py @@ -12,12 +12,14 @@ import os import posixpath import sys +import warnings from docutils import nodes from docutils.writers.html5_polyglot import HTMLTranslator as BaseTranslator from six import string_types from sphinx import addnodes +from sphinx.deprecation import RemovedInSphinx30Warning from sphinx.locale import admonitionlabels, _, __ from sphinx.util import logging from sphinx.util.images import get_image_size @@ -44,10 +46,6 @@ class HTML5Translator(BaseTranslator): BaseTranslator.__init__(self, *args, **kwds) self.highlighter = builder.highlighter self.builder = builder - self.highlightlang = self.highlightlang_base = \ - builder.config.highlight_language - self.highlightopts = builder.config.highlight_options - self.highlightlinenothreshold = sys.maxsize self.docnames = [builder.current_docname] # for singlehtml builder self.manpages_url = builder.config.manpages_url self.protect_literal_text = 0 @@ -369,19 +367,14 @@ class HTML5Translator(BaseTranslator): if node.rawsource != node.astext(): # most probably a parsed-literal block -- don't highlight return BaseTranslator.visit_literal_block(self, node) - lang = self.highlightlang - linenos = node.rawsource.count('\n') >= \ - self.highlightlinenothreshold - 1 + + lang = node.get('language', 'default') + linenos = node.get('linenos', False) highlight_args = node.get('highlight_args', {}) - if 'language' in node: - # code-block directives - lang = node['language'] - highlight_args['force'] = True - if 'linenos' in node: - linenos = node['linenos'] - if lang is self.highlightlang_base: + highlight_args['force'] = node.get('force_highlighting', False) + if lang is self.builder.config.highlight_language: # only pass highlighter options for original language - opts = self.highlightopts + opts = self.builder.config.highlight_options else: opts = {} @@ -515,15 +508,6 @@ class HTML5Translator(BaseTranslator): # type: (nodes.Node) -> None pass - def visit_highlightlang(self, node): - # type: (nodes.Node) -> None - self.highlightlang = node['lang'] - self.highlightlinenothreshold = node['linenothreshold'] - - def depart_highlightlang(self, node): - # type: (nodes.Node) -> None - pass - def visit_download_reference(self, node): # type: (nodes.Node) -> None if self.builder.download_support and node.hasattr('filename'): @@ -834,3 +818,33 @@ class HTML5Translator(BaseTranslator): def unknown_visit(self, node): # type: (nodes.Node) -> None raise NotImplementedError('Unknown node: ' + node.__class__.__name__) + + # --------- METHODS FOR COMPATIBILITY -------------------------------------- + + @property + def highlightlang(self): + # type: () -> unicode + warnings.warn('HTMLTranslator.highlightlang is deprecated.', + RemovedInSphinx30Warning) + return self.builder.config.highlight_language + + @property + def highlightlang_base(self): + # type: () -> unicode + warnings.warn('HTMLTranslator.highlightlang_base is deprecated.', + RemovedInSphinx30Warning) + return self.builder.config.highlight_language + + @property + def highlightopts(self): + # type: () -> unicode + warnings.warn('HTMLTranslator.highlightopts is deprecated.', + RemovedInSphinx30Warning) + return self.builder.config.highlight_options + + @property + def highlightlinenothreshold(self): + # type: () -> int + warnings.warn('HTMLTranslator.highlightlinenothreshold is deprecated.', + RemovedInSphinx30Warning) + return sys.maxsize diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 9a7d58116..c657664af 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -704,12 +704,6 @@ class LaTeXTranslator(nodes.NodeVisitor): self.descstack = [] # type: List[unicode] self.table = None # type: Table self.next_table_colspec = None # type: unicode - # stack of [language, linenothreshold] settings per file - # the first item here is the default and must not be changed - # the second item is the default for the master file and can be changed - # by .. highlight:: directive in the master file - self.hlsettingstack = 2 * [[builder.config.highlight_language, - sys.maxsize]] self.bodystack = [] # type: List[List[unicode]] self.footnote_restricted = False self.pending_footnotes = [] # type: List[nodes.footnote_reference] @@ -945,8 +939,6 @@ class LaTeXTranslator(nodes.NodeVisitor): def visit_start_of_file(self, node): # type: (nodes.Node) -> None self.curfilestack.append(node['docname']) - # use default highlight settings for new file - self.hlsettingstack.append(self.hlsettingstack[0]) def collect_footnotes(self, node): # type: (nodes.Node) -> Dict[unicode, List[Union[collected_footnote, bool]]] @@ -971,12 +963,6 @@ class LaTeXTranslator(nodes.NodeVisitor): def depart_start_of_file(self, node): # type: (nodes.Node) -> None self.curfilestack.pop() - self.hlsettingstack.pop() - - def visit_highlightlang(self, node): - # type: (nodes.Node) -> None - self.hlsettingstack[-1] = [node['lang'], node['linenothreshold']] - raise nodes.SkipNode def visit_section(self, node): # type: (nodes.Node) -> None @@ -2246,26 +2232,18 @@ class LaTeXTranslator(nodes.NodeVisitor): if labels and not self.in_footnote: self.body.append('\n\\def\\sphinxLiteralBlockLabel{' + labels + '}') - code = node.astext() - lang = self.hlsettingstack[-1][0] - linenos = code.count('\n') >= self.hlsettingstack[-1][1] - 1 + lang = node.get('language', 'default') + linenos = node.get('linenos', False) highlight_args = node.get('highlight_args', {}) - hllines = '\\fvset{hllines={, %s,}}%%' %\ - str(highlight_args.get('hl_lines', []))[1:-1] - if 'language' in node: - # code-block directives - lang = node['language'] - highlight_args['force'] = True - if 'linenos' in node: - linenos = node['linenos'] - if lang is self.hlsettingstack[0][0]: + highlight_args['force'] = node.get('force_highlighting', False) + if lang is self.builder.config.highlight_language: # only pass highlighter options for original language opts = self.builder.config.highlight_options else: opts = {} hlcode = self.highlighter.highlight_block( - code, lang, opts=opts, linenos=linenos, + node.rawsource, lang, opts=opts, linenos=linenos, location=(self.curfilestack[-1], node.line), **highlight_args ) # workaround for Unicode issue @@ -2290,6 +2268,9 @@ class LaTeXTranslator(nodes.NodeVisitor): hlcode += '\\end{sphinxVerbatimintable}' else: hlcode += '\\end{sphinxVerbatim}' + + hllines = '\\fvset{hllines={, %s,}}%%' %\ + str(highlight_args.get('hl_lines', []))[1:-1] self.body.append('\n' + hllines + '\n' + hlcode + '\n') raise nodes.SkipNode @@ -2639,6 +2620,13 @@ class LaTeXTranslator(nodes.NodeVisitor): RemovedInSphinx30Warning) return set() + @property + def hlsettingstack(self): + # type: () -> List[List[Union[unicode, int]]] + warnings.warn('LaTeXTranslator.hlsettingstack is deprecated.', + RemovedInSphinx30Warning) + return [[self.builder.config.highlight_language, sys.maxsize]] + # Import old modules here for compatibility # They should be imported after `LaTeXTranslator` to avoid recursive import. diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py index 02540a53d..45a800533 100644 --- a/sphinx/writers/manpage.py +++ b/sphinx/writers/manpage.py @@ -378,14 +378,6 @@ class ManualPageTranslator(BaseTranslator): # type: (nodes.Node) -> None pass - def visit_highlightlang(self, node): - # type: (nodes.Node) -> None - pass - - def depart_highlightlang(self, node): - # type: (nodes.Node) -> None - pass - def visit_download_reference(self, node): # type: (nodes.Node) -> None pass diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index 4f76c6cf9..6b7ec5932 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -1533,14 +1533,6 @@ class TexinfoTranslator(nodes.NodeVisitor): self.body.append('\n\n') raise nodes.SkipNode - def visit_highlightlang(self, node): - # type: (nodes.Node) -> None - pass - - def depart_highlightlang(self, node): - # type: (nodes.Node) -> None - pass - # -- Desc def visit_desc(self, node): diff --git a/sphinx/writers/text.py b/sphinx/writers/text.py index 0f9b45fbe..912d87399 100644 --- a/sphinx/writers/text.py +++ b/sphinx/writers/text.py @@ -251,10 +251,6 @@ class TextTranslator(nodes.NodeVisitor): for line in lines) # XXX header/footer? - def visit_highlightlang(self, node): - # type: (nodes.Node) -> None - raise nodes.SkipNode - def visit_section(self, node): # type: (nodes.Node) -> None self._title_char = self.sectionchars[self.sectionlevel] From f3019ee1974fda0722a71c8159ab97c4e78779dd Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 21 Jul 2018 11:25:54 +0900 Subject: [PATCH 028/174] Apply :confval:`trim_doctest_flags` to all builders (cf. text, manpages) --- CHANGES | 3 ++ doc/extdev/index.rst | 6 +++ sphinx/builders/html.py | 3 +- sphinx/builders/latex/__init__.py | 3 +- sphinx/highlighting.py | 8 +++- sphinx/transforms/post_transforms/code.py | 44 +++++++++++++++++++ sphinx/writers/latex.py | 4 +- ...> test_transforms_post_transforms_code.py} | 4 +- 8 files changed, 64 insertions(+), 11 deletions(-) rename tests/{test_config_trim_doctest_flags.py => test_transforms_post_transforms_code.py} (90%) diff --git a/CHANGES b/CHANGES index e5d143104..1efe974fb 100644 --- a/CHANGES +++ b/CHANGES @@ -113,6 +113,8 @@ Deprecated * ``sphinx.ext.mathbase.is_in_section_title()`` is deprecated * ``sphinx.ext.mathbase.MathDomain`` is deprecated * ``sphinx.highlighting.PygmentsBridge.unhighlight()`` is deprecated +* The ``trim_doctest_flags`` argument of ``sphinx.highlighting.PygmentsBridge`` + is deprecated For more details, see `deprecation APIs list `_ @@ -173,6 +175,7 @@ Features added if :confval:`latex_engine` is ``'xelatex'`` or ``'lualatex'``. * #4976: ``SphinxLoggerAdapter.info()`` now supports ``location`` parameter * #5122: setuptools: support nitpicky option +* Apply :confval:`trim_doctest_flags` to all builders (cf. text, manpages) Bugs fixed ---------- diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst index fe0d1b97e..a18534714 100644 --- a/doc/extdev/index.rst +++ b/doc/extdev/index.rst @@ -136,6 +136,12 @@ The following is a list of deprecated interface. - 3.0 - N/A + * - ``trim_doctest_flags`` arguments of + ``sphinx.highlighting.PygmentsBridge`` + - 1.8 + - 3.0 + - N/A + * - ``sphinx.ext.mathbase.MathDomain`` - 1.8 - 3.0 diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 16587fd18..67107ba0a 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -386,8 +386,7 @@ class StandaloneHTMLBuilder(Builder): style = self.theme.get_config('theme', 'pygments_style', 'none') else: style = 'sphinx' - self.highlighter = PygmentsBridge('html', style, - self.config.trim_doctest_flags) + self.highlighter = PygmentsBridge('html', style) def init_css_files(self): # type: () -> None diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py index c17ead5c2..c4e92ae5b 100644 --- a/sphinx/builders/latex/__init__.py +++ b/sphinx/builders/latex/__init__.py @@ -169,8 +169,7 @@ class LaTeXBuilder(Builder): def write_stylesheet(self): # type: () -> None - highlighter = highlighting.PygmentsBridge( - 'latex', self.config.pygments_style, self.config.trim_doctest_flags) + highlighter = highlighting.PygmentsBridge('latex', self.config.pygments_style) stylesheet = path.join(self.outdir, 'sphinxhighlight.sty') with open(stylesheet, 'w') as f: f.write('\\NeedsTeXFormat{LaTeX2e}[1995/12/01]\n') diff --git a/sphinx/highlighting.py b/sphinx/highlighting.py index f31ff88cc..b344dc16b 100644 --- a/sphinx/highlighting.py +++ b/sphinx/highlighting.py @@ -68,7 +68,7 @@ class PygmentsBridge(object): html_formatter = HtmlFormatter latex_formatter = LatexFormatter - def __init__(self, dest='html', stylename='sphinx', trim_doctest_flags=False): + def __init__(self, dest='html', stylename='sphinx', trim_doctest_flags=None): # type: (unicode, unicode, bool) -> None self.dest = dest if stylename is None or stylename == 'sphinx': @@ -81,7 +81,6 @@ class PygmentsBridge(object): stylename) else: style = get_style_by_name(stylename) - self.trim_doctest_flags = trim_doctest_flags self.formatter_args = {'style': style} # type: Dict[unicode, Any] if dest == 'html': self.formatter = self.html_formatter @@ -89,6 +88,11 @@ class PygmentsBridge(object): self.formatter = self.latex_formatter self.formatter_args['commandprefix'] = 'PYG' + self.trim_doctest_flags = trim_doctest_flags + if trim_doctest_flags is not None: + warnings.warn('trim_doctest_flags option for PygmentsBridge is now deprecated.', + RemovedInSphinx30Warning) + def get_formatter(self, **kwargs): # type: (Any) -> Formatter kwargs.update(self.formatter_args) # type: ignore diff --git a/sphinx/transforms/post_transforms/code.py b/sphinx/transforms/post_transforms/code.py index f0c1d0097..86143ffb4 100644 --- a/sphinx/transforms/post_transforms/code.py +++ b/sphinx/transforms/post_transforms/code.py @@ -13,9 +13,11 @@ import sys from typing import NamedTuple from docutils import nodes +from pygments.lexers import PythonConsoleLexer, guess_lexer from six import text_type from sphinx import addnodes +from sphinx.ext import doctest from sphinx.transforms import SphinxTransform if False: @@ -95,9 +97,51 @@ class HighlightLanguageVisitor(nodes.NodeVisitor): node['linenos'] = (lines >= setting.lineno_threshold - 1) +class TrimDoctestFlagsTransform(SphinxTransform): + """ + Trim doctest flags like ``# doctest: +FLAG`` from python code-blocks. + + see :confval:`trim_doctest_flags` for more information. + """ + default_priority = HighlightLanguageTransform.default_priority + 1 + + def apply(self): + if not self.config.trim_doctest_flags: + return + + for node in self.document.traverse(nodes.literal_block): + if self.is_pyconsole(node): + source = node.rawsource + source = doctest.blankline_re.sub('', source) + source = doctest.doctestopt_re.sub('', source) + node.rawsource = source + node[:] = [nodes.Text(source)] + + @staticmethod + def is_pyconsole(node): + # type: (nodes.literal_block) -> bool + if node.rawsource != node.astext(): + return False # skip parsed-literal node + + language = node.get('language') + if language in ('pycon', 'pycon3'): + return True + elif language in ('py', 'py3', 'python', 'python3', 'default'): + return node.rawsource.startswith('>>>') + elif language == 'guess': + try: + lexer = guess_lexer(node.rawsource) + return isinstance(lexer, PythonConsoleLexer) + except Exception: + pass + + return False + + def setup(app): # type: (Sphinx) -> Dict[unicode, Any] app.add_post_transform(HighlightLanguageTransform) + app.add_post_transform(TrimDoctestFlagsTransform) return { 'version': 'builtin', diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index c657664af..b7d80860b 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -697,9 +697,7 @@ class LaTeXTranslator(nodes.NodeVisitor): self.babel_defmacro('\\pageautorefname', self.encode(_('page'))) self.elements['numfig_format'] = self.generate_numfig_format(builder) - self.highlighter = highlighting.PygmentsBridge( - 'latex', - builder.config.pygments_style, builder.config.trim_doctest_flags) + self.highlighter = highlighting.PygmentsBridge('latex', builder.config.pygments_style) self.context = [] # type: List[Any] self.descstack = [] # type: List[unicode] self.table = None # type: Table diff --git a/tests/test_config_trim_doctest_flags.py b/tests/test_transforms_post_transforms_code.py similarity index 90% rename from tests/test_config_trim_doctest_flags.py rename to tests/test_transforms_post_transforms_code.py index 3be1b27a2..e1c45ce65 100644 --- a/tests/test_config_trim_doctest_flags.py +++ b/tests/test_transforms_post_transforms_code.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ - test_config_trim_doctest_flags - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + test_transforms_post_transforms_code + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. From c0ba51902f943c6f5cae56429fb0c73652ce1d21 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 21 Jul 2018 14:35:31 +0900 Subject: [PATCH 029/174] Fix #5198: document not in toctree warning when including files only for parallel builds --- CHANGES | 3 +++ sphinx/environment/__init__.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/CHANGES b/CHANGES index f0133ff94..778df02e0 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,9 @@ Features added Bugs fixed ---------- +* #5198: document not in toctree warning when including files only for parallel + builds + Testing -------- diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index 86d69cc3a..4d3935faf 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -310,6 +310,7 @@ class BuildEnvironment(object): if docname in self.all_docs: self.all_docs.pop(docname, None) self.reread_always.discard(docname) + self.included.discard(docname) for version, changes in self.versionchanges.items(): new = [change for change in changes if change[1] != docname] @@ -330,6 +331,8 @@ class BuildEnvironment(object): self.all_docs[docname] = other.all_docs[docname] if docname in other.reread_always: self.reread_always.add(docname) + if docname in other.included: + self.included.add(docname) for version, changes in other.versionchanges.items(): self.versionchanges.setdefault(version, []).extend( From fe3d4ddc20828207ea6b1d0cdc387108a167d3c9 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 22 Jul 2018 00:03:17 +0900 Subject: [PATCH 030/174] Fix classic theme: collapsiblesidebar is always enabled --- sphinx/themes/classic/layout.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx/themes/classic/layout.html b/sphinx/themes/classic/layout.html index 8042e3f7e..bee2ffd1e 100644 --- a/sphinx/themes/classic/layout.html +++ b/sphinx/themes/classic/layout.html @@ -9,9 +9,9 @@ #} {%- extends "basic/layout.html" %} -{% if theme_collapsiblesidebar|tobool %} {%- block scripts %} {{ super() }} + {% if theme_collapsiblesidebar|tobool %} + {% endif %} {%- endblock %} -{% endif %} From d0900001afab78dc9d8cb2356e82be8eae161863 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 22 Jul 2018 00:09:11 +0900 Subject: [PATCH 031/174] doc: collapsiblesidebar works well with stickysidebar --- doc/theming.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/theming.rst b/doc/theming.rst index fccc2362e..3308fe632 100644 --- a/doc/theming.rst +++ b/doc/theming.rst @@ -150,7 +150,7 @@ These themes are: - **collapsiblesidebar** (true or false): Add an *experimental* JavaScript snippet that makes the sidebar collapsible via a button on its side. - *Doesn't work with "stickysidebar".* Defaults to ``False``. + Defaults to ``False``. - **externalrefs** (true or false): Display external links differently from internal links. Defaults to ``False``. From 8c29801f271eb7c258924fef02609d1b8d9d1d25 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 22 Jul 2018 01:06:17 +0900 Subject: [PATCH 032/174] Close #2820: autoclass directive supports nested class --- CHANGES | 1 + sphinx/ext/autodoc/importer.py | 17 +++++++++++++++-- tests/test_autodoc.py | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index e57a0dad6..114c34cf5 100644 --- a/CHANGES +++ b/CHANGES @@ -162,6 +162,7 @@ Features added if :confval:`latex_engine` is ``'xelatex'`` or ``'lualatex'``. * #4976: ``SphinxLoggerAdapter.info()`` now supports ``location`` parameter * #5122: setuptools: support nitpicky option +* #2820: autoclass directive supports nested class Bugs fixed ---------- diff --git a/sphinx/ext/autodoc/importer.py b/sphinx/ext/autodoc/importer.py index 20d448506..4b92a7b59 100644 --- a/sphinx/ext/autodoc/importer.py +++ b/sphinx/ext/autodoc/importer.py @@ -167,8 +167,21 @@ def import_object(modname, objpath, objtype='', attrgetter=safe_getattr, warning logger.debug('[autodoc] import %s', modname) try: - module = import_module(modname, warningiserror=warningiserror) - logger.debug('[autodoc] => %r', module) + module = None + objpath = list(objpath) + while module is None: + try: + module = import_module(modname, warningiserror=warningiserror) + logger.debug('[autodoc] import %s => %r', modname, module) + except ImportError: + logger.debug('[autodoc] import %s => failed', modname) + if '.' in modname: + # retry with parent module + modname, name = modname.rsplit('.', 1) + objpath.insert(0, name) + else: + raise + obj = module parent = None object_name = None diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index 53d8a1e14..a42210a4c 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -771,6 +771,9 @@ def test_generate(): ('class', 'target.Outer.Inner'), ('method', 'target.Outer.Inner.meth')], 'class', 'Outer', all_members=True) + assert_processes([('class', 'target.Outer.Inner'), + ('method', 'target.Outer.Inner.meth')], + 'class', 'target.Outer.Inner', all_members=True) # test descriptor docstrings assert_result_contains(' Descriptor instance docstring.', From cfc56329d4453c37bc3d0b8e7ea8813c10e1a7c6 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 22 Jul 2018 01:50:09 +0900 Subject: [PATCH 033/174] Fix #344: autosummary does not understand docstring of module level attributes --- CHANGES | 1 + sphinx/ext/autodoc/__init__.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGES b/CHANGES index e57a0dad6..92475536c 100644 --- a/CHANGES +++ b/CHANGES @@ -174,6 +174,7 @@ Bugs fixed * #5132: (lualatex) PDF build fails if indexed word starts with Unicode character * #5133: latex: index headings "Symbols" and "Numbers" not internationalized * #5114: sphinx-build: Handle errors on scanning documents +* #344: autosummary does not understand docstring of module level attributes Testing -------- diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 62143fda4..4a9b59537 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1265,6 +1265,11 @@ class DataDocumenter(ModuleLevelDocumenter): # type: (bool) -> None pass + def get_real_modname(self): + # type: () -> str + return self.get_attr(self.parent or self.object, '__module__', None) \ + or self.modname + class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter): # type: ignore """ From d2a15f403525f65f96b7efa40c12c73dabfa877e Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Sat, 21 Jul 2018 20:17:00 +0200 Subject: [PATCH 034/174] #5186 clean up JavaScript templates: doctools move templating from `doctools` to `documentation_options` --- sphinx/themes/basic/static/{doctools.js_t => doctools.js} | 6 +++--- sphinx/themes/basic/static/documentation_options.js_t | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) rename sphinx/themes/basic/static/{doctools.js_t => doctools.js} (98%) diff --git a/sphinx/themes/basic/static/doctools.js_t b/sphinx/themes/basic/static/doctools.js similarity index 98% rename from sphinx/themes/basic/static/doctools.js_t rename to sphinx/themes/basic/static/doctools.js index 1dca47404..ffadbec11 100644 --- a/sphinx/themes/basic/static/doctools.js_t +++ b/sphinx/themes/basic/static/doctools.js @@ -150,9 +150,9 @@ var Documentation = { this.fixFirefoxAnchorBug(); this.highlightSearchWords(); this.initIndexTable(); - {% if theme_navigation_with_keys|tobool %} - this.initOnKeyListeners(); - {% endif %} + if (DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) { + this.initOnKeyListeners(); + } }, /** diff --git a/sphinx/themes/basic/static/documentation_options.js_t b/sphinx/themes/basic/static/documentation_options.js_t index 9da9801a1..66d4bab88 100644 --- a/sphinx/themes/basic/static/documentation_options.js_t +++ b/sphinx/themes/basic/static/documentation_options.js_t @@ -5,5 +5,6 @@ var DOCUMENTATION_OPTIONS = { COLLAPSE_INDEX: false, FILE_SUFFIX: '{{ '' if no_search_suffix else file_suffix }}', HAS_SOURCE: {{ has_source|lower }}, - SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}' + SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}', + NAVIGATION_WITH_KEYS: {{ 'true' if theme_navigation_with_keys|tobool else 'false'}} }; From 67cb316ba2ceb4459ca7fd06129c3b6e3b83c8fc Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Sun, 22 Jul 2018 11:01:28 +0200 Subject: [PATCH 035/174] move templating from `searchtools` to `documentation_options` --- .../basic/static/documentation_options.js_t | 16 +++- .../{searchtools.js_t => searchtools.js} | 78 +++++++++---------- 2 files changed, 50 insertions(+), 44 deletions(-) rename sphinx/themes/basic/static/{searchtools.js_t => searchtools.js} (91%) diff --git a/sphinx/themes/basic/static/documentation_options.js_t b/sphinx/themes/basic/static/documentation_options.js_t index 66d4bab88..bd32e356b 100644 --- a/sphinx/themes/basic/static/documentation_options.js_t +++ b/sphinx/themes/basic/static/documentation_options.js_t @@ -6,5 +6,19 @@ var DOCUMENTATION_OPTIONS = { FILE_SUFFIX: '{{ '' if no_search_suffix else file_suffix }}', HAS_SOURCE: {{ has_source|lower }}, SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}', - NAVIGATION_WITH_KEYS: {{ 'true' if theme_navigation_with_keys|tobool else 'false'}} + NAVIGATION_WITH_KEYS: {{ 'true' if theme_navigation_with_keys|tobool else 'false'}}, + SEARCH_LANGUAGE_STOP_WORDS: {{ search_language_stop_words }} }; + + +{% if search_language_stemming_code %} +/* Non-minified version JS is _stemmer.js if file is provided */ {% endif -%} +{{ search_language_stemming_code|safe }} + +{% if search_scorer_tool %} +{{ search_scorer_tool|safe }} +{% endif -%} + +{% if search_word_splitter_code %} +{{ search_word_splitter_code }} +{% endif -%} diff --git a/sphinx/themes/basic/static/searchtools.js_t b/sphinx/themes/basic/static/searchtools.js similarity index 91% rename from sphinx/themes/basic/static/searchtools.js_t rename to sphinx/themes/basic/static/searchtools.js index e707bb1ea..34d7db2e3 100644 --- a/sphinx/themes/basic/static/searchtools.js_t +++ b/sphinx/themes/basic/static/searchtools.js @@ -9,51 +9,43 @@ * */ -{% if search_language_stemming_code %} -/* Non-minified version JS is _stemmer.js if file is provided */ {% endif -%} -{{ search_language_stemming_code|safe }} +if (!Scorer) { + /** + * Simple result scoring code. + */ + var Scorer = { + // Implement the following function to further tweak the score for each result + // The function takes a result array [filename, title, anchor, descr, score] + // and returns the new score. + /* + score: function(result) { + return result[4]; + }, + */ -{% if search_scorer_tool %} -{{ search_scorer_tool|safe }} -{% else %} -/** - * Simple result scoring code. - */ -var Scorer = { - // Implement the following function to further tweak the score for each result - // The function takes a result array [filename, title, anchor, descr, score] - // and returns the new score. - /* - score: function(result) { - return result[4]; - }, - */ + // query matches the full name of an object + objNameMatch: 11, + // or matches in the last dotted part of the object name + objPartialMatch: 6, + // Additive scores depending on the priority of the object + objPrio: {0: 15, // used to be importantResults + 1: 5, // used to be objectResults + 2: -5}, // used to be unimportantResults + // Used when the priority is not in the mapping. + objPrioDefault: 0, - // query matches the full name of an object - objNameMatch: 11, - // or matches in the last dotted part of the object name - objPartialMatch: 6, - // Additive scores depending on the priority of the object - objPrio: {0: 15, // used to be importantResults - 1: 5, // used to be objectResults - 2: -5}, // used to be unimportantResults - // Used when the priority is not in the mapping. - objPrioDefault: 0, - - // query found in title - title: 15, - // query found in terms - term: 5 -}; -{% endif %} - -{% if search_word_splitter_code %} -{{ search_word_splitter_code }} -{% else %} -function splitQuery(query) { - return query.split(/\s+/); + // query found in title + title: 15, + // query found in terms + term: 5 + }; +} + +if (!splitQuery) { + function splitQuery(query) { + return query.split(/\s+/); + } } -{% endif %} /** * Search Module @@ -146,7 +138,7 @@ var Search = { */ query : function(query) { var i; - var stopwords = {{ search_language_stop_words }}; + var stopwords = DOCUMENTATION_OPTIONS.SEARCH_LANGUAGE_STOP_WORDS; // stem the searchterms and add them to the correct list var stemmer = new Stemmer(); From 732ebb5d1e5a2114870525a8a789ec39df19bcfb Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 21 Jul 2018 23:13:16 +0200 Subject: [PATCH 036/174] Capitalization: "Table Of Contents" -> "Table of Contents". This is consistent with "Complete Table of Contents" (which is already in the database), as well as e.g. "Indices and Tables" where "and" is not capitalized. This is also fairly standard title-case practice. --- sphinx/themes/agogo/layout.html | 2 +- sphinx/themes/basic/globaltoc.html | 2 +- sphinx/themes/basic/localtoc.html | 2 +- sphinx/themes/haiku/layout.html | 2 +- sphinx/themes/scrolls/layout.html | 2 +- tests/test_theming.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sphinx/themes/agogo/layout.html b/sphinx/themes/agogo/layout.html index 8bd476cad..f2c880537 100644 --- a/sphinx/themes/agogo/layout.html +++ b/sphinx/themes/agogo/layout.html @@ -43,7 +43,7 @@