view scripts/vimutil.py @ 9:4ba6df1b2f97

Add built-in properties to the solution environment before resolving items.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 24 Sep 2020 22:57:50 -0700
parents 5d2c0db51914
children
line wrap: on
line source

import io
import sys


def runscript(scriptfunc, *args):
    """ Executes a given function with the given args. This is because
        the convention is that all python scripts here should have a `main`
        function that takes a custom list of args to override the default
        behaviour of using `sys.args`.
    """
    prevout = sys.stdout
    captured = io.StringIO()
    sys.stdout = captured
    try:
        scriptfunc(args)
    finally:
        sys.stdout = prevout
    return captured.getvalue()