VisTrails/VisTrails — pull request #950 by remram44 (2014-11-10 18:14:55+00:00)
Title: Export as script

Translating a pipeline to a Python script.

Several things here.

#### Getting a piece of Python code from a single module

This is done through the `vistrails_module:Module#to_python_script()` function. Currently, modules need to provide that, but with a lot of magic we can probably get this from a package's code (at least in simple cases).

In the general case, module have code in functions outside of their compute() method, so this gets tricky.

#### Assembling modules as a Python script

Once the code for each module as been collected, they need to be assembled into the final script. This includes:
* Renaming variables to "connect" modules together and make sure a module doesn't change the value of a port in its internal code
* Organizing function definitions (if several modules of the same package are used, or several instances of the same module, we only want the defined functions to appear once); this is the concept of "prelude" in the code
* Organize imports (part of the prelude stuff, but completely unrelated packages/modules might still import the same thing)

#### UI

In addition to exporting a pipeline as a script, we might want to replace a module or a subpipeline with a PythonSource with the generated code (allowing the user to tweak it, at the cost of losing the tie with the package's code).

Work in progress. TODO: import back these scripts (add metadata for the importer as comments).