human
I wrote the below code

    pwd = str(os.getcwd())
    old_sys_path = list(sys.path)
    if (setup.config.wf_working_directory is not None):
        try:
            os.chdir(setup.config.wf_working_directory)
        except OSError as err:
            raise OSError((str(err) + u'\n`wf_working_directory`    option    inSphinx    configuration    file    must    be    a    valid    directory    path'))
        except TypeError as err:
            raise TypeError((str(err) + u'\n`wf_working_directory`    option    in    Sphinx    configuration    file    must    be    a    string    or    None'))
        sys.path.insert(0, setup.config.wf_working_directory)
    elif (code_path is not None):
        dirname = os.path.abspath(os.path.dirname(code_path))
        os.chdir(dirname)
        sys.path.insert(0, dirname)
    old_sys_argv = sys.argv
    sys.argv = [code_path]
    stdout = sys.stdout
    if PY3:
        sys.stdout = io.StringIO()
    else:
        from cStringIO import StringIO
        sys.stdout = StringIO()
    def _dummy_print(*arg, **kwarg):
        pass
    try:
        code = unescape_doctest(code)
        if (ns is None):
            ns = {}
        if (not ns):
            if (setup.config.wf_pre_code is not None):
                exec str(setup.config.wf_pre_code) in ns
        ns[u'print'] = _dummy_print
        if (u'__main__' in code):
            exec u"__name__    =    '__main__'" in ns
        code = remove_coding(code)
        exec code in ns
        if (function_name is not None):
            exec (function_name + u'()') in ns
    except (Exception, SystemExit) as err:
        raise GraphError(traceback.format_exc())
    finally:
        os.chdir(pwd)
        sys.argv = old_sys_argv
        sys.path[:] = old_sys_path
        sys.stdout = stdout
    return ns

What's a good function header?
 ... Here's a good function header?
assistant
#Here's a good function header.

def run_code(code, code_path, ns=None, function_name=None):