On Wednesday 18 February à 08:57, David Goodger wrote:
> Sylvain Thénault wrote:
> > I've the following code to check the syntax of ReST files :
> I assume that you're not using one of the front-ends -- either
> tools/quicktest.py (parsing only) or tools/publish.py (also does
> reference resolution etc.) -- because you need to do this
> programmatically. Correct?
> > My problem is that when checking files which are not in the current
> > working directory, it's unable to process ".. include" directives
> > with files relative to the parsed file. I can't find a way to
> > specify the path of the source to the document. Any idea ?
> That's what the "_source" setting is for:
> <http://docutils.sf.net/docs/config.html#source>. It's normally set
> by the command-line processing mechanism.
> But rather than using all that code, why not use one of the
> convenience functions, such as docutils.core.publish_string()? The
> only issue I see is:
> > where MyReporter is a custom class with the usual reporter interface
> > to display messages and count errors.
> What does your MyReporter class do that's different? If it's
> important, we could parameterize the Reporter class in the Publisher
> class and in the publish_* convenience functions so that you could
> override the default. The only reason it's not a parameter already is
> because nobody has expressed the need for it yet.
MyReporter is actually an adapter to another reporting class. I want to
check the syntax of ReST files from within a big test framework which
test a lot of other things (python code, page templates...). This test
framework defines its own kind of reporter object, so I've to give
messages raised by the ReST parser to my own reporter. Having a custom
reporter is the only way I'v found to do that.
Note I only want to check the syntax, I don't want to actually transform
the file. Is there any convenience method doing so ?
Anyway, I've found the way to doing it by reading quicktest.py (I wasn't
aware of this tool, it's installed in a weird place by the debian
package : /usr/share/python-doctutils...), by replacing the line below
doc = nodes.document(options, reporter, source=source)
doc = nodes.document(options, reporter, source=filepath)
If you've another way to do so using a more "public" api, please tell
me... Thank you very much for your attention.
Sylvain Thénault LOGILAB, Paris (France).
http://www.logilab.com http://www.logilab.fr http://www.logilab.org