def run_python_file(filename, args, package=None, collector=None):
<EOL>old_main_mod = sys.modules['<STR_LIT:__main__>']<EOL>main_mod = imp.new_module('<STR_LIT:__main__>')<EOL>sys.modules['<STR_LIT:__main__>'] = main_mod<EOL>main_mod.__file__ = filename<EOL>if package:<EOL><INDENT>main_mod.__package__ = package<EOL><DEDENT>main_mod.__builtins__ = sys.modules['<STR_LIT>']<EOL>old_argv = sys.argv<EOL>old_path0 = sys.path[<NUM_LIT:0>]<EOL>sys.argv = args<EOL>if package:<EOL><INDENT>sys.path[<NUM_LIT:0>] = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>sys.path[<NUM_LIT:0>] = os.path.abspath(os.path.dirname(filename))<EOL><DEDENT>try:<EOL><INDENT>try:<EOL><INDENT>source_file = open(filename, '<STR_LIT>')<EOL><DEDENT>except IOError:<EOL><INDENT>raise NoSource("<STR_LIT>" % filename)<EOL><DEDENT>try:<EOL><INDENT>source = source_file.read()<EOL><DEDENT>finally:<EOL><INDENT>source_file.close()<EOL><DEDENT>if source[-<NUM_LIT:1>] != '<STR_LIT:\n>':<EOL><INDENT>source += '<STR_LIT:\n>'<EOL><DEDENT>code = compile(source, filename, "<STR_LIT>")<EOL>try:<EOL><INDENT>exec(code, main_mod.__dict__)<EOL><DEDENT>except SystemExit:<EOL><INDENT>raise<EOL><DEDENT>except:<EOL><INDENT>typ, err, tb = sys.exc_info()<EOL>raise ExceptionDuringRun(typ, err, tb.tb_next.tb_next)<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>sys.modules['<STR_LIT:__main__>'] = old_main_mod<EOL>sys.argv = old_argv<EOL>sys.path[<NUM_LIT:0>] = old_path0<EOL><DEDENT>
Run a python file as if it were the main program on the command line.

    `filename` is the path to the file to execute, it need not be a .py file.
    `args` is the argument array to present as sys.argv, including the first
    element naming the file being executed.  `package` is the name of the
    enclosing package, if any.