mpastell / Pweave

Pweave is a scientific report generator and a literate programming tool for Python. It can capture the results and plots from data analysis and works well with numpy, scipy and matplotlib.
http://mpastell.com/pweave
Other
435 stars 64 forks source link

IPython notebook formatter #11

Closed aaren closed 9 years ago

aaren commented 11 years ago

There are currently these output formats:

formats = {'tex' : {'class' : PwebTexFormatter, 'description' : 'Latex with verbatim for code and results'},
            'texminted' : {'class' : PwebMintedFormatter, 'description' : 'Latex with predefined minted environment for codeblocks'},
            'texpweave' : {'class' : PwebTexPweaveFormatter, 'description' : 'Latex output with user defined formatting using named environments (in latex header)'},
            'texpygments' : {'class' : PwebTexPygmentsFormatter, 'description' : 'Latex output with pygments highlighted output'},
            'rst' : {'class' : PwebRstFormatter, 'description' : 'reStructuredText'},
            'pandoc' : {'class' : PwebPandocFormatter, 'description' : 'Pandoc markdown'},
            'sphinx' : {'class' : PwebSphinxFormatter, 'description' : 'reStructuredText for Sphinx'},
            'html' : {'class' : PwebHTMLFormatter, 'description' : 'HTML with pygments highlighting'},
            'md2html' : {'class' : PwebMDtoHTMLFormatter, 'description' : 'Markdown to HTML using Python-Markdown'},
            'pandoc2latex' : {'class' : PwebPandoctoTexFormatter, 'description' : 'Markdown to Latex using Pandoc, requires Pandoc in path'},
            'pandoc2html' : {'class' : PwebPandocMDtoHTMLFormatter, 'description' : 'Markdown to HTML using Pandoc, requires Pandoc in path'}
            }

A really powerful addition would be an IPython notebook formatter. Then docs written in markdown could be converted to notebooks.

I don't think it would be too hard, as the IPython notebook is just a JSON.

aaren commented 11 years ago

beda4ba is a first attempt.

May need to think about what code block options mean in the context of ipython.

Also, what to do with figures? Ipython embeds figures in the .ipynb. I don't think we need to do that. My idea was more that you can switch to editing in the notebook if you want to.

mpastell commented 11 years ago

I think it would be a good idea to output text and code but not execute code blocks. That way you could import the document using IPython notebook and let IPython handle running the code.

aaren commented 11 years ago

Pweb.weave goes like this:

def weave(self, shell="python"):
    """Weave the document, equals -> parse, run, format, write"""
    if not self.isparsed:
        self.parse()
    self.run(shell)
    self.format()
    self.write()

So you'd have to disable the call to self.run somehow.

How about passing shell as None to trigger this? Wouldn't be hard to rewrite run to do this.

Then implement a command line switch to trigger the no run behaviour and make this default if the output format is a notebook.

aaren commented 11 years ago

what is tricky is that the processor and the formatter are linked

in Pweb.run:

self.executed = runner.getresults()

and in Pweb.format:

self.formatter.setexecuted(copy.deepcopy(self.executed))

The executed comes from mapping _runcode in the processor onto the list of chunks.

We can avoid this by bypassing the call to the processor.

mpastell commented 11 years ago

I think I'd rather have this functionality in Pweave-convert script, because its just converting the document to JSON and not running the code.

aaren commented 11 years ago

good point.

aaren commented 11 years ago

ignore dddfc89 and 560e105. I rebased over them. Not sure how to get github to stop referencing them.

mpastell commented 11 years ago

Can you make a pull request with the correct version? And send me an example that I can test it with?

aaren commented 11 years ago

There is a test file in the pull request.

nehalecky commented 10 years ago

Hey all. I'm really interested in this feature and was wondering what the status was for integrating this PR into master?

Thanks!

aaren commented 10 years ago

Hi :). Glad someone might find it useful.

I was a bit busy, hence the slowness in writing it up. I think there is a good deal of improvement that could be done, so I wouldn't consider this a stable interface. It is a proof of concept though.

Have you tried out my branch? This really needs documenting, but maybe you can work it out from the tests?

nehalecky commented 10 years ago

Hey you all. Thanks for the replies. I haven't been able to test out the branch, however, wanted to ask about the status of this project in general? I think we've lost momentum here, but there seems to be quite a bit of momentum, here: https://github.com/paulgb/runipy

Thoughts? :)

aaren commented 10 years ago

@nehalecky If you want to create notebooks from markdown have a look at notedown, which I made recently. I'm open to ideas on new features, but the core is taking markdown and turning it into an IPython notebook.

nehalecky commented 10 years ago

@aaren, wow, thanks for the tip. Don't know know I missed it until now. Nice library, I am going to look at it more closely when I have time. Thank you so much! :clap:!

mpastell commented 9 years ago

This is now merged to master. Sorry for the delay.