Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export as script #950

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open

Export as script #950

wants to merge 55 commits into from

Conversation

remram44
Copy link
Member

Translating a pipeline to a Python script.

Several things here.

architecture

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, modules have code in functions outside of their compute() method, so this gets tricky. They can also be generated dynamically with weird closures and hidden state that we can't deal with automatically.

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).

rexissimus and others added 17 commits June 15, 2015 16:29
Only works for PythonSources right now

core/modules/basic_modules.py:
  - PythonSource.to_python_script:
    Returns value of source parameter as string

core/vistrail/controller.py:
  - write_workflow_to_python: *new
    Creates python script from workflow

gui/vistrail_view.py:
  - export_python: *new
    Exports current workflow as python script

gui/vistrails_window.py:
  New menu option Export Workflow as Python script
* Don't summon modules for nothing
* 'indent' spelling
An unconnected port might be in the connected_input_ports dictionary,
with associated value 0; check for that.
Remove the re-export from core.scripting, import directly from
core.scripting.export.
Instead of taking a filename to write to, return an iterable of unicode
lines.
@remram44 remram44 self-assigned this Feb 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants