From 432115123ed505b4670b0779812c3dd3161b23f8 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 4 Aug 2008 22:20:44 +0000 Subject: [PATCH] Merged revisions 65529 via svnmerge from svn+ssh://pythondev@svn.python.org/doctools/branches/0.4.x ........ r65529 | georg.brandl | 2008-08-04 22:19:30 +0000 (Mon, 04 Aug 2008) | 6 lines Revert r65499 which was not well thought out. Instead, put the whole build dir in exclude_trees by default in quickstart. Also, revisit application cleanup and make it consistently use less setup time while still trying to leave to traces. ........ --- sphinx/application.py | 16 ++++------------ sphinx/environment.py | 3 ++- sphinx/quickstart.py | 4 +++- tests/root/conf.py | 1 - tests/test_build.py | 2 +- tests/test_markup.py | 2 +- tests/util.py | 29 ++++++++++++++--------------- 7 files changed, 25 insertions(+), 32 deletions(-) diff --git a/sphinx/application.py b/sphinx/application.py index 12fca8ba6..e7a3858a1 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -13,7 +13,6 @@ """ import sys -from os import path from docutils import nodes from docutils.parsers.rst import directives, roles @@ -67,10 +66,10 @@ class Sphinx(object): self.builderclasses = builtin_builders.copy() self.builder = None - self.srcdir = path.abspath(srcdir) - self.confdir = path.abspath(confdir) - self.outdir = path.abspath(outdir) - self.doctreedir = path.abspath(doctreedir) + self.srcdir = srcdir + self.confdir = confdir + self.outdir = outdir + self.doctreedir = doctreedir self._status = status self._warning = warning @@ -91,13 +90,6 @@ class Sphinx(object): # now that we know all config values, collect them from conf.py self.config.init_values() - # if the output and/or doctree dirs are within the source dir, except - # them from being searched for source files - if self.outdir.startswith(self.srcdir): - self.config.exclude_trees += [self.outdir[len(self.srcdir)+1:]] - if self.doctreedir.startswith(self.srcdir): - self.config.exclude_trees += [self.doctreedir[len(self.srcdir)+1:]] - if buildername is None: print >>status, 'No builder selected, using default: html' buildername = 'html' diff --git a/sphinx/environment.py b/sphinx/environment.py index 102ddee59..e855e89cb 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -578,7 +578,8 @@ class BuildEnvironment: for imgpath in candidates.itervalues(): self.dependencies.setdefault(docname, set()).add(imgpath) if not os.access(path.join(self.srcdir, imgpath), os.R_OK): - self.warn(docname, 'Image file not readable: %s' % imgpath, node.line) + self.warn(docname, 'Image file not readable: %s' % imgpath, + node.line) if imgpath in self.images: self.images[imgpath][0].add(docname) continue diff --git a/sphinx/quickstart.py b/sphinx/quickstart.py index fea469ce5..a62ea8a21 100644 --- a/sphinx/quickstart.py +++ b/sphinx/quickstart.py @@ -80,7 +80,7 @@ today_fmt = '%%B %%d, %%Y' # List of directories, relative to source directories, that shouldn't be searched # for source files. -#exclude_dirs = [] +exclude_trees = [%(exclude_trees)s] # The reST default role (used for this markup: `text`) to use for all documents. #default_role = None @@ -451,8 +451,10 @@ directly.''' mkdir_p(srcdir) if separate: builddir = path.join(d['path'], 'build') + d['exclude_trees'] = '' else: builddir = path.join(srcdir, d['dot'] + 'build') + d['exclude_trees'] = repr(d['dot'] + 'build') mkdir_p(builddir) mkdir_p(path.join(srcdir, d['dot'] + 'templates')) mkdir_p(path.join(srcdir, d['dot'] + 'static')) diff --git a/tests/root/conf.py b/tests/root/conf.py index 5bd659efb..fd04933b0 100644 --- a/tests/root/conf.py +++ b/tests/root/conf.py @@ -57,7 +57,6 @@ today_fmt = '%B %d, %Y' # List of directories, relative to source directories, that shouldn't be searched # for source files. -#exclude_dirs = [] exclude_trees = ['_build'] # If true, '()' will be appended to :func: etc. cross-reference text. diff --git a/tests/test_build.py b/tests/test_build.py index 9046bc898..5ce482733 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -112,6 +112,6 @@ def test_linkcheck(app): def test_text(app): app.builder.build_all() -@with_testapp(buildername='changes') +@with_testapp(buildername='changes', cleanenv=True) def test_changes(app): app.builder.build_all() diff --git a/tests/test_markup.py b/tests/test_markup.py index 23330a60c..3a3cb9d77 100644 --- a/tests/test_markup.py +++ b/tests/test_markup.py @@ -22,7 +22,7 @@ from sphinx.latexwriter import LaTeXWriter, LaTeXTranslator def setup_module(): global app, settings, parser - app = TestApp() + app = TestApp(cleanenv=True) optparser = frontend.OptionParser(components=(rst.Parser, HTMLWriter, LaTeXWriter)) settings = optparser.get_default_values() settings.env = app.builder.env diff --git a/tests/util.py b/tests/util.py index ba53c43c7..f2eb3fd58 100644 --- a/tests/util.py +++ b/tests/util.py @@ -94,32 +94,34 @@ class TestApp(application.Sphinx): def __init__(self, srcdir=None, confdir=None, outdir=None, doctreedir=None, buildername='html', confoverrides=None, status=None, warning=None, - freshenv=None, confname='conf.py'): + freshenv=None, confname='conf.py', cleanenv=False): application.CONFIG_FILENAME = confname + self.cleanup_trees = [] + if srcdir is None: srcdir = test_root if srcdir == '(temp)': - tempdir = path(tempfile.mkdtemp()) / 'root' - test_root.copytree(tempdir) - srcdir = tempdir + tempdir = path(tempfile.mkdtemp()) + self.cleanup_trees.append(tempdir) + temproot = tempdir / 'root' + test_root.copytree(temproot) + srcdir = temproot else: srcdir = path(srcdir) self.builddir = srcdir.joinpath('_build') - if not self.builddir.isdir(): - self.builddir.makedirs() - self.made_builddir = True - else: - self.made_builddir = False if confdir is None: confdir = srcdir if outdir is None: outdir = srcdir.joinpath(self.builddir, buildername) if not outdir.isdir(): outdir.makedirs() + self.cleanup_trees.insert(0, outdir) if doctreedir is None: doctreedir = srcdir.joinpath(srcdir, self.builddir, 'doctrees') + if cleanenv: + self.cleanup_trees.insert(0, doctreedir) if confoverrides is None: confoverrides = {} if status is None: @@ -127,17 +129,14 @@ class TestApp(application.Sphinx): if warning is None: warning = ListOutput('stderr') if freshenv is None: - freshenv = True + freshenv = False application.Sphinx.__init__(self, srcdir, confdir, outdir, doctreedir, buildername, confoverrides, status, warning, freshenv) - def cleanup(self): - trees = [self.outdir, self.doctreedir] - if self.made_builddir: - trees.append(self.builddir) - for tree in trees: + def cleanup(self, doctrees=False): + for tree in self.cleanup_trees: shutil.rmtree(tree, True)