views:

780

answers:

4

I've been playing with various ways of doing literate programming in Python. I like noweb, but I have two main problems with it: first, it is hard to build on Windows, where I spend about half my development time; and second, it requires me to indent each chunk of code as it will be in the final program --- which I don't necessarily know when I write it. I don't want to use Leo, because I'm very attached to Emacs.

Is there a good literate programming tool that:

  1. Runs on Windows
  2. Allows me to set the indentation of the chunks when they're used, not when they're written
  3. Still lets me work in Emacs

Thanks!


Correction: noweb does allow me to indent later --- I misread the paper I found on it.

By default, notangle preserves whitespace and maintains indentation when expanding chunks. It can therefore be used with languages like Miranda and Haskell, in which indentation is significant

That leaves me with only the "Runs on Windows" problem.

A: 

I'd suggest maybe trying PyDev for eclipse. Eclipse is a really great platform, and this is an absolutely excellent plugin. While I understand your love for emacs (being a vi person myself), I'd still suggest giving eclipse a try on its own.

You can play with the indentation setting, so in theory, you could mess with the indentation all you want until you get it perfect.

ReaperUnreal
I don't understand the relation between PyDev and literate programming. Can you expand on that a bit?
JasonFruit
I had to look up "literate programming". http://en.wikipedia.org/wiki/Literate_programming
Fred Larson
+1  A: 

I did this:

http://sourceforge.net/projects/pywebtool/

You can get any number of web/weave products that will help you construct a document and code in one swoop.

You can -- pretty easily -- write your own. It's not rocket science to yank the Python code blocks out of RST source and assemble it. Indeed, I suggest you write your own Docutils directives to assemble the Python code from an RST source document.

You run the RST through docutils rst2html (or Sphinx) to produce your final HTML report.

You run your own utility on the same RST source to extract the Python code blocks and produce the final modules.

S.Lott
I'm looking through your approach --- it looks pretty close to what I'd like to have. I'd much rather adapt myself to someone else's tool than write one of my own; look what's happened with web frameworks!
JasonFruit
Everything about this looks good, except that when I generate LaTeX, there's a bunch of nuweb markup that MiKTeX and TeTeX don't seem to understand; I can't find a way to remedy that. Can you explain how it works? I read your excellent documents, but I'm not sure what you mean when you say, "The biggest gap in the LATEX support is a complete lack of understanding of the original markup in nuweb, and the very real damage done to that markup when creating pyWeb."
JasonFruit
@JsonFruit: Without understanding any LaTeX, I converted some parts of nuweb. Since I didn't take the time to understand any of the LaTeX, I suspected it was wrong. You've found out for a fact that I converted it wrong. Since the LaTeX markup is relatively easy to isolate, you might want to consider fixing the Markup. Or use nuweb (or noweb) directly -- they might be better.
S.Lott
I'll play with the LaTeX a bit - the parsing code is simple and easy to read. If I come up with a satisfying solution, I'll send you some patches.
JasonFruit
+2  A: 

You might find noweb 3 easier to build on Windows. It was designed to be more portable than standard noweb.

Norman Ramsey
I'll check it out once the site is responding again.
JasonFruit
I gave it a look --- it seems much more likely to work for me than the previous version. I quite likely would have gone with this had I realized it was available before I settled on another tool.
JasonFruit
A: 

I have written Pweave http://mpastell.com/pweave, that is aimed for dynamic report generation and uses noweb syntax. It is a pure python script so it also runs on Windows. It doesn't fix your indent problem, but maybe you can modify it for that, the code is really quite simple.

Matti Pastell