retitle 637604 ikiwiki: warns during --setup if python-docutils is missing
tags 637604 + patch
thanks

On Mon, 05 Sep 2011 at 13:27:56 -0400, Joey Hess wrote:
> What needs to be done here is find a way to make the rst plugin quiet
> when it's initially loaded and docutils is not abailable. Then it should
> only fail hard if it actually is used in that situation. Since it's written
> in python, this is beyond my expertise to fix.

Here, have a patch (and a trivial regression test for the plugin itself,
while I was there). Also in my git repository as
smcv/docutils-graceful-error-637604.

    S
From 1e81affead1bf9a960daeb1990a028ac0f1810a5 Mon Sep 17 00:00:00 2001
From: Simon McVittie <[email protected]>
Date: Sat, 22 Oct 2011 19:46:02 +0100
Subject: [PATCH 1/2] rst: import docutils lazily, to avoid errors during
 ikiwiki --setup

Bug-Debian: http://bugs.debian.org/637604
Signed-off-by: Simon McVittie <[email protected]>
---
 plugins/rst |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/plugins/rst b/plugins/rst
index fb36245..0fe91c5 100755
--- a/plugins/rst
+++ b/plugins/rst
@@ -36,10 +36,22 @@ __author__ = 'martin f. krafft <[email protected]>'
 __copyright__ = 'Copyright © ' + __author__
 __licence__ = 'BSD-2-clause'
 
-from docutils.core import publish_parts;
 from proxy import IkiWikiProcedureProxy
 
+publish_parts = None
+
 def rst2html(proxy, *args):
+    # delayed import so docutils is only needed if you *use* rst -
+    # http://bugs.debian.org/637604
+    global publish_parts
+    if publish_parts is None:
+        try:
+            from docutils.core import publish_parts
+        except ImportError, e:
+            proxy.error('cannot import docutils.core: %s: %s' %
+                        (e.__class__.__name__, e))
+            raise
+
     kwargs = _to_dict(args)
     parts = publish_parts(kwargs["content"],
                           writer_name="html",
-- 
1.7.7

From bc6bef9c562f91032f38f65be61406cc498203b0 Mon Sep 17 00:00:00 2001
From: Simon McVittie <[email protected]>
Date: Sat, 22 Oct 2011 19:46:42 +0100
Subject: [PATCH 2/2] Add a trivial test for the rst plugin

Signed-off-by: Simon McVittie <[email protected]>
---
 t/rst.t |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100755 t/rst.t

diff --git a/t/rst.t b/t/rst.t
new file mode 100755
index 0000000..4e0c4b7
--- /dev/null
+++ b/t/rst.t
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+BEGIN {
+	if (system("python -c 'import docutils.core'") != 0) {
+		eval 'use Test::More skip_all => "docutils not available"';
+	}
+}
+
+use Test::More tests => 2;
+
+BEGIN { use_ok("IkiWiki"); }
+
+%config=IkiWiki::defaultconfig();
+$config{srcdir}=$config{destdir}="/dev/null";
+$config{libdir}=".";
+$config{add_plugins}=[qw(rst)];
+IkiWiki::loadplugins();
+IkiWiki::checkconfig();
+
+ok(IkiWiki::htmlize("foo", "foo", "rst", "foo\n") =~ m{\s*<p>foo</p>\s*});
-- 
1.7.7

Attachment: signature.asc
Description: Digital signature

Reply via email to