Show More
@@ -1491,7 +1491,7 b' Currently the magic system has the following functions:\\n"""' | |||||
1491 | return None |
|
1491 | return None | |
1492 |
|
1492 | |||
1493 | @skip_doctest |
|
1493 | @skip_doctest | |
1494 | def magic_run(self, parameter_s ='',runner=None, |
|
1494 | def magic_run(self, parameter_s ='', runner=None, | |
1495 | file_finder=get_py_filename): |
|
1495 | file_finder=get_py_filename): | |
1496 | """Run the named file inside IPython as a program. |
|
1496 | """Run the named file inside IPython as a program. | |
1497 |
|
1497 | |||
@@ -1614,8 +1614,8 b' Currently the magic system has the following functions:\\n"""' | |||||
1614 | """ |
|
1614 | """ | |
1615 |
|
1615 | |||
1616 | # get arguments and set sys.argv for program to be run. |
|
1616 | # get arguments and set sys.argv for program to be run. | |
1617 | opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:em:', |
|
1617 | opts, arg_lst = self.parse_options(parameter_s, 'nidtN:b:pD:l:rs:T:em:', | |
1618 | mode='list',list_all=1) |
|
1618 | mode='list', list_all=1) | |
1619 | if "m" in opts: |
|
1619 | if "m" in opts: | |
1620 | modulename = opts["m"][0] |
|
1620 | modulename = opts["m"][0] | |
1621 | modpath = find_mod(modulename) |
|
1621 | modpath = find_mod(modulename) | |
@@ -1627,7 +1627,7 b' Currently the magic system has the following functions:\\n"""' | |||||
1627 | filename = file_finder(arg_lst[0]) |
|
1627 | filename = file_finder(arg_lst[0]) | |
1628 | except IndexError: |
|
1628 | except IndexError: | |
1629 | warn('you must provide at least a filename.') |
|
1629 | warn('you must provide at least a filename.') | |
1630 | print '\n%run:\n',oinspect.getdoc(self.magic_run) |
|
1630 | print '\n%run:\n', oinspect.getdoc(self.magic_run) | |
1631 | return |
|
1631 | return | |
1632 | except IOError as e: |
|
1632 | except IOError as e: | |
1633 | try: |
|
1633 | try: | |
@@ -1642,7 +1642,7 b' Currently the magic system has the following functions:\\n"""' | |||||
1642 | return |
|
1642 | return | |
1643 |
|
1643 | |||
1644 | # Control the response to exit() calls made by the script being run |
|
1644 | # Control the response to exit() calls made by the script being run | |
1645 |
exit_ignore = |
|
1645 | exit_ignore = 'e' in opts | |
1646 |
|
1646 | |||
1647 | # Make sure that the running script gets a proper sys.argv as if it |
|
1647 | # Make sure that the running script gets a proper sys.argv as if it | |
1648 | # were run from a system shell. |
|
1648 | # were run from a system shell. | |
@@ -1651,9 +1651,9 b' Currently the magic system has the following functions:\\n"""' | |||||
1651 | # simulate shell expansion on arguments, at least tilde expansion |
|
1651 | # simulate shell expansion on arguments, at least tilde expansion | |
1652 | args = [ os.path.expanduser(a) for a in arg_lst[1:] ] |
|
1652 | args = [ os.path.expanduser(a) for a in arg_lst[1:] ] | |
1653 |
|
1653 | |||
1654 | sys.argv = [filename]+ args # put in the proper filename |
|
1654 | sys.argv = [filename] + args # put in the proper filename | |
1655 |
|
1655 | |||
1656 |
if |
|
1656 | if 'i' in opts: | |
1657 | # Run in user's interactive namespace |
|
1657 | # Run in user's interactive namespace | |
1658 | prog_ns = self.shell.user_ns |
|
1658 | prog_ns = self.shell.user_ns | |
1659 | __name__save = self.shell.user_ns['__name__'] |
|
1659 | __name__save = self.shell.user_ns['__name__'] | |
@@ -1661,7 +1661,7 b' Currently the magic system has the following functions:\\n"""' | |||||
1661 | main_mod = self.shell.new_main_mod(prog_ns) |
|
1661 | main_mod = self.shell.new_main_mod(prog_ns) | |
1662 | else: |
|
1662 | else: | |
1663 | # Run in a fresh, empty namespace |
|
1663 | # Run in a fresh, empty namespace | |
1664 |
if |
|
1664 | if 'n' in opts: | |
1665 | name = os.path.splitext(os.path.basename(filename))[0] |
|
1665 | name = os.path.splitext(os.path.basename(filename))[0] | |
1666 | else: |
|
1666 | else: | |
1667 | name = '__main__' |
|
1667 | name = '__main__' | |
@@ -1690,10 +1690,10 b' Currently the magic system has the following functions:\\n"""' | |||||
1690 | try: |
|
1690 | try: | |
1691 | stats = None |
|
1691 | stats = None | |
1692 | with self.readline_no_record: |
|
1692 | with self.readline_no_record: | |
1693 |
if |
|
1693 | if 'p' in opts: | |
1694 | stats = self.magic_prun('',0,opts,arg_lst,prog_ns) |
|
1694 | stats = self.magic_prun('', 0, opts, arg_lst, prog_ns) | |
1695 | else: |
|
1695 | else: | |
1696 |
if |
|
1696 | if 'd' in opts: | |
1697 | deb = debugger.Pdb(self.shell.colors) |
|
1697 | deb = debugger.Pdb(self.shell.colors) | |
1698 | # reset Breakpoint state, which is moronically kept |
|
1698 | # reset Breakpoint state, which is moronically kept | |
1699 | # in a class |
|
1699 | # in a class | |
@@ -1702,11 +1702,11 b' Currently the magic system has the following functions:\\n"""' | |||||
1702 | bdb.Breakpoint.bpbynumber = [None] |
|
1702 | bdb.Breakpoint.bpbynumber = [None] | |
1703 | # Set an initial breakpoint to stop execution |
|
1703 | # Set an initial breakpoint to stop execution | |
1704 | maxtries = 10 |
|
1704 | maxtries = 10 | |
1705 | bp = int(opts.get('b',[1])[0]) |
|
1705 | bp = int(opts.get('b', [1])[0]) | |
1706 | checkline = deb.checkline(filename,bp) |
|
1706 | checkline = deb.checkline(filename, bp) | |
1707 | if not checkline: |
|
1707 | if not checkline: | |
1708 | for bp in range(bp+1,bp+maxtries+1): |
|
1708 | for bp in range(bp + 1, bp + maxtries + 1): | |
1709 | if deb.checkline(filename,bp): |
|
1709 | if deb.checkline(filename, bp): | |
1710 | break |
|
1710 | break | |
1711 | else: |
|
1711 | else: | |
1712 | msg = ("\nI failed to find a valid line to set " |
|
1712 | msg = ("\nI failed to find a valid line to set " | |
@@ -1717,23 +1717,23 b' Currently the magic system has the following functions:\\n"""' | |||||
1717 | error(msg) |
|
1717 | error(msg) | |
1718 | return |
|
1718 | return | |
1719 | # if we find a good linenumber, set the breakpoint |
|
1719 | # if we find a good linenumber, set the breakpoint | |
1720 | deb.do_break('%s:%s' % (filename,bp)) |
|
1720 | deb.do_break('%s:%s' % (filename, bp)) | |
1721 | # Start file run |
|
1721 | # Start file run | |
1722 | print "NOTE: Enter 'c' at the", |
|
1722 | print "NOTE: Enter 'c' at the", | |
1723 | print "%s prompt to start your script." % deb.prompt |
|
1723 | print "%s prompt to start your script." % deb.prompt | |
1724 | try: |
|
1724 | try: | |
1725 | deb.run('execfile("%s")' % filename,prog_ns) |
|
1725 | deb.run('execfile("%s")' % filename, prog_ns) | |
1726 |
|
1726 | |||
1727 | except: |
|
1727 | except: | |
1728 | etype, value, tb = sys.exc_info() |
|
1728 | etype, value, tb = sys.exc_info() | |
1729 | # Skip three frames in the traceback: the %run one, |
|
1729 | # Skip three frames in the traceback: the %run one, | |
1730 | # one inside bdb.py, and the command-line typed by the |
|
1730 | # one inside bdb.py, and the command-line typed by the | |
1731 | # user (run by exec in pdb itself). |
|
1731 | # user (run by exec in pdb itself). | |
1732 | self.shell.InteractiveTB(etype,value,tb,tb_offset=3) |
|
1732 | self.shell.InteractiveTB(etype, value, tb, tb_offset=3) | |
1733 | else: |
|
1733 | else: | |
1734 | if runner is None: |
|
1734 | if runner is None: | |
1735 | runner = self.shell.safe_execfile |
|
1735 | runner = self.shell.safe_execfile | |
1736 |
if |
|
1736 | if 't' in opts: | |
1737 | # timed execution |
|
1737 | # timed execution | |
1738 | try: |
|
1738 | try: | |
1739 | nruns = int(opts['N'][0]) |
|
1739 | nruns = int(opts['N'][0]) | |
@@ -1745,11 +1745,11 b' Currently the magic system has the following functions:\\n"""' | |||||
1745 | twall0 = time.time() |
|
1745 | twall0 = time.time() | |
1746 | if nruns == 1: |
|
1746 | if nruns == 1: | |
1747 | t0 = clock2() |
|
1747 | t0 = clock2() | |
1748 | runner(filename,prog_ns,prog_ns, |
|
1748 | runner(filename, prog_ns, prog_ns, | |
1749 | exit_ignore=exit_ignore) |
|
1749 | exit_ignore=exit_ignore) | |
1750 | t1 = clock2() |
|
1750 | t1 = clock2() | |
1751 | t_usr = t1[0]-t0[0] |
|
1751 | t_usr = t1[0] - t0[0] | |
1752 | t_sys = t1[1]-t0[1] |
|
1752 | t_sys = t1[1] - t0[1] | |
1753 | print "\nIPython CPU timings (estimated):" |
|
1753 | print "\nIPython CPU timings (estimated):" | |
1754 | print " User : %10.2f s." % t_usr |
|
1754 | print " User : %10.2f s." % t_usr | |
1755 | print " System : %10.2f s." % t_sys |
|
1755 | print " System : %10.2f s." % t_sys | |
@@ -1757,30 +1757,30 b' Currently the magic system has the following functions:\\n"""' | |||||
1757 | runs = range(nruns) |
|
1757 | runs = range(nruns) | |
1758 | t0 = clock2() |
|
1758 | t0 = clock2() | |
1759 | for nr in runs: |
|
1759 | for nr in runs: | |
1760 | runner(filename,prog_ns,prog_ns, |
|
1760 | runner(filename, prog_ns, prog_ns, | |
1761 | exit_ignore=exit_ignore) |
|
1761 | exit_ignore=exit_ignore) | |
1762 | t1 = clock2() |
|
1762 | t1 = clock2() | |
1763 | t_usr = t1[0]-t0[0] |
|
1763 | t_usr = t1[0] - t0[0] | |
1764 | t_sys = t1[1]-t0[1] |
|
1764 | t_sys = t1[1] - t0[1] | |
1765 | print "\nIPython CPU timings (estimated):" |
|
1765 | print "\nIPython CPU timings (estimated):" | |
1766 | print "Total runs performed:",nruns |
|
1766 | print "Total runs performed:", nruns | |
1767 | print " Times : %10.2f %10.2f" % ('Total','Per run') |
|
1767 | print " Times : %10.2f %10.2f" % ('Total', 'Per run') | |
1768 | print " User : %10.2f s, %10.2f s." % (t_usr,t_usr/nruns) |
|
1768 | print " User : %10.2f s, %10.2f s." % (t_usr, t_usr / nruns) | |
1769 | print " System : %10.2f s, %10.2f s." % (t_sys,t_sys/nruns) |
|
1769 | print " System : %10.2f s, %10.2f s." % (t_sys, t_sys / nruns) | |
1770 | twall1 = time.time() |
|
1770 | twall1 = time.time() | |
1771 | print "Wall time: %10.2f s." % (twall1-twall0) |
|
1771 | print "Wall time: %10.2f s." % (twall1 - twall0) | |
1772 |
|
1772 | |||
1773 | else: |
|
1773 | else: | |
1774 | # regular execution |
|
1774 | # regular execution | |
1775 | runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore) |
|
1775 | runner(filename, prog_ns, prog_ns, exit_ignore=exit_ignore) | |
1776 |
|
1776 | |||
1777 |
if |
|
1777 | if 'i' in opts: | |
1778 | self.shell.user_ns['__name__'] = __name__save |
|
1778 | self.shell.user_ns['__name__'] = __name__save | |
1779 | else: |
|
1779 | else: | |
1780 | # The shell MUST hold a reference to prog_ns so after %run |
|
1780 | # The shell MUST hold a reference to prog_ns so after %run | |
1781 | # exits, the python deletion mechanism doesn't zero it out |
|
1781 | # exits, the python deletion mechanism doesn't zero it out | |
1782 | # (leaving dangling references). |
|
1782 | # (leaving dangling references). | |
1783 | self.shell.cache_main_mod(prog_ns,filename) |
|
1783 | self.shell.cache_main_mod(prog_ns, filename) | |
1784 | # update IPython interactive namespace |
|
1784 | # update IPython interactive namespace | |
1785 |
|
1785 | |||
1786 | # Some forms of read errors on the file may mean the |
|
1786 | # Some forms of read errors on the file may mean the |
General Comments 0
You need to be logged in to leave comments.
Login now