def run_setup(script_name, script_args=None, stop_after="<STR_LIT>"):
if stop_after not in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>" % stop_after)<EOL><DEDENT>core._setup_stop_after = stop_after<EOL>save_argv = sys.argv<EOL>glocals = copy(globals())<EOL>glocals['<STR_LIT>'] = script_name<EOL>glocals['<STR_LIT>'] = "<STR_LIT:__main__>"<EOL>try:<EOL><INDENT>try:<EOL><INDENT>sys.argv[<NUM_LIT:0>] = script_name<EOL>if script_args is not None:<EOL><INDENT>sys.argv[<NUM_LIT:1>:] = script_args<EOL><DEDENT>f = open(script_name)<EOL>try:<EOL><INDENT>exec(f.read(), glocals, glocals)<EOL><DEDENT>finally:<EOL><INDENT>f.close()<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>sys.argv = save_argv<EOL>core._setup_stop_after = None<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>logging.warn("<STR_LIT>", exc_info=True)<EOL><DEDENT>if core._setup_distribution is None:<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" %<EOL>script_name)<EOL><DEDENT>return core._setup_distribution<EOL>
Run a setup script in a somewhat controlled environment, and
    return the Distribution instance that drives things.  This is useful
    if you need to find out the distribution meta-data (passed as
    keyword args from 'script' to 'setup()', or the contents of the
    config files or command-line.

    'script_name' is a file that will be run with 'execfile()';
    'sys.argv[0]' will be replaced with 'script' for the duration of the
    call.  'script_args' is a list of strings; if supplied,
    'sys.argv[1:]' will be replaced by 'script_args' for the duration of
    the call.

    'stop_after' tells 'setup()' when to stop processing; possible
    values:
      init
        stop after the Distribution instance has been created and
        populated with the keyword arguments to 'setup()'
      config
        stop after config files have been parsed (and their data
        stored in the Distribution instance)
      commandline
        stop after the command-line ('sys.argv[1:]' or 'script_args')
        have been parsed (and the data stored in the Distribution)
      run [default]
        stop after all commands have been run (the same as if 'setup()'
        had been called in the usual way

    Returns the Distribution instance, which provides all information
    used to drive the Distutils.