From 166ac0d5ca870a355b290ceaee2ff80703c8d8f5 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Fri, 10 Jan 2014 21:44:59 +0100 Subject: [PATCH 1/3] fix target confusion --- doc/intl.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/intl.rst b/doc/intl.rst index 3f9580acb..6f74deb0e 100644 --- a/doc/intl.rst +++ b/doc/intl.rst @@ -165,9 +165,9 @@ use the :command:`sphinx-intl update` command. Using Transifex service for team translation -------------------------------------------- -`Transifex `_ is one of several services that allow -collaborative translation via a web interface. It has a nifty Python-based -command line client that makes it easy to fetch and push translations. +Transifex_ is one of several services that allow collaborative translation via a +web interface. It has a nifty Python-based command line client that makes it +easy to fetch and push translations. .. TODO: why use transifex? From 38d73fb056bef6dec97e88be7e8383a1242a885a Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Fri, 10 Jan 2014 21:51:51 +0100 Subject: [PATCH 2/3] Closes #932: autodoc: Do not crash if ``__doc__`` is not a string. --- CHANGES | 2 ++ sphinx/ext/autodoc.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 6959cb9d7..b5b5d1ee8 100644 --- a/CHANGES +++ b/CHANGES @@ -28,6 +28,8 @@ Bugs fixed * #814: autodoc: Guard against strange type objects that don't have ``__bases__``. +* #932: autodoc: Do not crash if ``__doc__`` is not a string. + Documentation ------------- diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index e26a6b85d..05996f9e5 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -450,9 +450,10 @@ class Documenter(object): # into lines if isinstance(docstring, unicode): return [prepare_docstring(docstring, ignore)] - elif docstring: + elif isinstance(docstring, str): # this will not trigger on Py3 return [prepare_docstring(force_decode(docstring, encoding), ignore)] + # ... else it is something strange, let's ignore it return [] def process_doc(self, docstrings): From 195050c6c4bafb7025076a2a190f52e9022337df Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Fri, 10 Jan 2014 22:04:03 +0100 Subject: [PATCH 3/3] Closes #933: Do not crash if an ``:option:`` value is malformed (contains spaces but no option name). --- CHANGES | 3 +++ sphinx/domains/std.py | 17 +++++++++++++---- tests/root/markup.txt | 1 + tests/test_build_html.py | 2 ++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index b5b5d1ee8..e8d72d06d 100644 --- a/CHANGES +++ b/CHANGES @@ -30,6 +30,9 @@ Bugs fixed * #932: autodoc: Do not crash if ``__doc__`` is not a string. +* #933: Do not crash if an ``:option:`` value is malformed (contains spaces + but no option name). + Documentation ------------- diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index ae67bf0e6..50e519fab 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -190,17 +190,26 @@ class Program(Directive): class OptionXRefRole(XRefRole): innernodeclass = addnodes.literal_emphasis + def _split(self, text, refnode, env): + try: + program, target = re.split(' (?=-|--|/)', text, 1) + except ValueError: + env.warn_node('Malformed :option: %r, does not contain option ' + 'marker - or -- or /' % text, refnode) + return None, text + else: + program = ws_re.sub('-', program) + return program, target + def process_link(self, env, refnode, has_explicit_title, title, target): program = env.temp_data.get('std:program') if not has_explicit_title: if ' ' in title and not (title.startswith('/') or title.startswith('-')): - program, target = re.split(' (?=-|--|/)', title, 1) - program = ws_re.sub('-', program) + program, target = self._split(title, refnode, env) target = target.strip() elif ' ' in target: - program, target = re.split(' (?=-|--|/)', target, 1) - program = ws_re.sub('-', program) + program, target = self._split(target, refnode, env) refnode['refprogram'] = program return title, target diff --git a/tests/root/markup.txt b/tests/root/markup.txt index 1fb20cf09..39a8ebc07 100644 --- a/tests/root/markup.txt +++ b/tests/root/markup.txt @@ -139,6 +139,7 @@ Adding \n to test unescaping. * :doc:`subdir/includes` * ``:download:`` is tested in includes.txt * :option:`Python -c option ` +* This used to crash: :option:`Python c option` Test :abbr:`abbr (abbreviation)` and another :abbr:`abbr (abbreviation)`. diff --git a/tests/test_build_html.py b/tests/test_build_html.py index d5b59e42f..bd8c0730a 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -42,6 +42,8 @@ http://www.python.org/logo.png reading included file u'.*?wrongenc.inc' seems to be wrong, try giving an \ :encoding: option\\n? %(root)s/includes.txt:4: WARNING: download file not readable: .*?nonexisting.png +%(root)s/markup.txt:142: WARNING: Malformed :option: u'Python c option', does \ +not contain option marker - or -- or / %(root)s/objects.txt:\\d*: WARNING: using old C markup; please migrate to \ new-style markup \(e.g. c:function instead of cfunction\), see \ http://sphinx-doc.org/domains.html