def run(self, tool, stdin=None, stdout=None):
        log.debug("Block: run python block for: %s", tool)
        #tmpl = self.render(tool)
        content = self.content
        if isinstance(content, (list, tuple)):
            content = "\n".join(content)
        local_env = locals()
        utils = PythonBlockUtils(tool, local_env)
        profile = jip.profiles.Profile()
        if hasattr(tool, '_job'):
            profile = tool._job

        env = {
            "tool": tool,
            "args": tool.options.to_dict(),
            "opts": tool.options,
            "options": tool.options,
            "check_file": utils.check_file,
            "ensure": tool.ensure,
            "run": utils.run,
            "validation_error": utils.validation_error,
            "bash": utils.bash,
            "job": utils.job,
            "name": utils.name,
            "add_output": tool.options.add_output,
            "add_input": tool.options.add_input,
            "add_option": tool.options.add_option,
            "set": utils.set,
            'r': render_template,
            'render_template': render_template,
            'utils': utils,
            'profile': profile,
            'basename': basename,
            'dirname': dirname,
            'abspath': abspath,
            'pwd': getcwd(),
            'exists': exists,
            '__file__': tool.path if tool.path else None
        }

        # link known tools into the context
        from jip import scanner
        from functools import partial
        scanner.scan_modules()
        for name, cls in scanner.registry.iteritems():
            if not name in env:
                env[name] = partial(utils.run, name)
        for name, path in scanner.scan_files().iteritems():
            k = name
            if k.endswith(".jip"):
                k = k[:-4]
            if not k in env:
                env[k] = partial(utils.run, name)

        # link options to context
        for o in tool.options:
            if not o.name in env:
                n = o.name.replace("-", "_").replace(" ", "_")
                env[n] = o

        utils._global_env = env
        old_global_context = jip.templates.global_context
        set_global_context(env)
        try:
            exec content in local_env, env
        except Exception as e:
            if hasattr(e, 'lineno'):
                e.lineno += self._lineno
            raise

        # auto naming for tools
        from jip.pipelines import Node
        for k, v in env.iteritems():
            if isinstance(v, Node):
                if v._job.name is None:
                    v._job.name = k
                    # reset index
        log.debug("Block: block for: %s executed", tool)
        return env
Execute this block as an embedded python script
dataset/ETHPy150Open thasso/pyjip/jip/tools.py/PythonBlock.run