From 4688518d8d788ce33ba07c85df1d30515bf12495 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 30 Jan 2010 18:49:42 +0100 Subject: [PATCH 1/2] Make the ``start-after`` and ``end-before`` options to the ``literalinclude`` directive work correctly if not used together. --- CHANGES | 3 +++ sphinx/directives/code.py | 4 ++-- tests/root/includes.txt | 6 ++++++ tests/test_markup.py | 1 - 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 66aee2446..2db62edb4 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ Release 0.6.5 (in development) ============================== +* Make the ``start-after`` and ``end-before`` options to the + ``literalinclude`` directive work correctly if not used together. + * #321: Fix link generation in the LaTeX builder. diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index ffb9ce4d6..f5a8f8af4 100644 --- a/sphinx/directives/code.py +++ b/sphinx/directives/code.py @@ -155,9 +155,9 @@ class LiteralInclude(Directive): use = not startafter res = [] for line in lines: - if not use and startafter in line: + if not use and startafter and startafter in line: use = True - elif use and endbefore in line: + elif use and endbefore and endbefore in line: use = False break elif use: diff --git a/tests/root/includes.txt b/tests/root/includes.txt index b58463f54..4fe13ed64 100644 --- a/tests/root/includes.txt +++ b/tests/root/includes.txt @@ -44,6 +44,12 @@ Literalinclude options :start-after: coding: utf-8 :end-before: class Foo +.. literalinclude:: literal.inc + :start-after: utf-8 + +.. literalinclude:: literal.inc + :end-before: class Foo + Test if dedenting before parsing works. .. highlight:: python diff --git a/tests/test_markup.py b/tests/test_markup.py index d29f6f914..0133a9d82 100644 --- a/tests/test_markup.py +++ b/tests/test_markup.py @@ -16,7 +16,6 @@ from util import * from docutils import frontend, utils, nodes from docutils.parsers import rst -from sphinx import addnodes from sphinx.util import texescape from sphinx.writers.html import HTMLWriter, SmartyPantsHTMLTranslator from sphinx.writers.latex import LaTeXWriter, LaTeXTranslator From 24a50977176766ab094b5ece72cc336e457351c9 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 7 Feb 2010 23:40:40 +0100 Subject: [PATCH 2/2] Allow auto-detecting "docs" as sphinx source dir. --- sphinx/setup_command.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sphinx/setup_command.py b/sphinx/setup_command.py index 1b434fa23..d569b031c 100644 --- a/sphinx/setup_command.py +++ b/sphinx/setup_command.py @@ -41,14 +41,18 @@ class BuildDoc(Command): self.conf_file_name = 'conf.py' self.builder = 'html' + def _guess_source_dir(self): + for guess in ('doc', 'docs'): + if not os.path.isdir(guess): + continue + for root, dirnames, filenames in os.walk(guess): + if 'conf.py' in filenames: + return root + def finalize_options(self): if self.source_dir is None: - if os.path.isdir('doc'): - for root, dirnames, filenames in os.walk('doc'): - if 'conf.py' in filenames: - self.source_dir = root - self.announce('Using source directory %s' % root) - break + self.source_dir = self._guess_source_dir() + self.announce('Using source directory %s' % self.source_dir) self.ensure_dirname('source_dir') self.source_dir = os.path.abspath(self.source_dir)