Show More
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.' | |||
|
6 | 6 | |
|
7 | 7 | This file contains all the classes and helper functions specific to IPython. |
|
8 | 8 | |
|
9 |
$Id: iplib.py 18 |
|
|
9 | $Id: iplib.py 1885 2006-11-08 01:07:28Z fperez $ | |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | #***************************************************************************** |
@@ -1844,6 +1844,13 b' want to merge them back into the new files.""" % locals()' | |||
|
1844 | 1844 | The return value can be used to decide whether to use sys.ps1 or |
|
1845 | 1845 | sys.ps2 to prompt the next line.""" |
|
1846 | 1846 | |
|
1847 | # if the source code has leading blanks, add 'if 1:\n' to it | |
|
1848 | # this allows execution of indented pasted code. It is tempting | |
|
1849 | # to add '\n' at the end of source to run commands like ' a=1' | |
|
1850 | # directly, but this fails for more complicated scenarios | |
|
1851 | if source[:1] in [' ', '\t']: | |
|
1852 | source = 'if 1:\n%s' % source | |
|
1853 | ||
|
1847 | 1854 | try: |
|
1848 | 1855 | code = self.compile(source,filename,symbol) |
|
1849 | 1856 | except (OverflowError, SyntaxError, ValueError): |
@@ -2419,13 +2426,37 b' want to merge them back into the new files.""" % locals()' | |||
|
2419 | 2426 | self.exit_now = True |
|
2420 | 2427 | |
|
2421 | 2428 | def safe_execfile(self,fname,*where,**kw): |
|
2429 | """A safe version of the builtin execfile(). | |
|
2430 | ||
|
2431 | This version will never throw an exception, and knows how to handle | |
|
2432 | ipython logs as well.""" | |
|
2433 | ||
|
2434 | def syspath_cleanup(): | |
|
2435 | """Internal cleanup routine for sys.path.""" | |
|
2436 | if add_dname: | |
|
2437 | try: | |
|
2438 | sys.path.remove(dname) | |
|
2439 | except ValueError: | |
|
2440 | # For some reason the user has already removed it, ignore. | |
|
2441 | pass | |
|
2442 | ||
|
2422 | 2443 | fname = os.path.expanduser(fname) |
|
2423 | 2444 | |
|
2445 | # Find things also in current directory. This is needed to mimic the | |
|
2446 | # behavior of running a script from the system command line, where | |
|
2447 | # Python inserts the script's directory into sys.path | |
|
2448 | dname = os.path.dirname(os.path.abspath(fname)) | |
|
2449 | add_dname = False | |
|
2450 | if dname not in sys.path: | |
|
2451 | sys.path.insert(0,dname) | |
|
2452 | add_dname = True | |
|
2453 | ||
|
2424 | 2454 | try: |
|
2425 | 2455 | xfile = open(fname) |
|
2426 | 2456 | except: |
|
2427 | 2457 | print >> Term.cerr, \ |
|
2428 | 2458 | 'Could not open file <%s> for safe execution.' % fname |
|
2459 | syspath_cleanup() | |
|
2429 | 2460 | return None |
|
2430 | 2461 | |
|
2431 | 2462 | kw.setdefault('islog',0) |
@@ -2512,4 +2543,6 b' want to merge them back into the new files.""" % locals()' | |||
|
2512 | 2543 | self.showtraceback() |
|
2513 | 2544 | warn('Failure executing file: <%s>' % fname) |
|
2514 | 2545 | |
|
2546 | syspath_cleanup() | |
|
2547 | ||
|
2515 | 2548 | #************************* end of file <iplib.py> ***************************** |
@@ -1,3 +1,12 b'' | |||
|
1 | 2006-11-07 Fernando Perez <Fernando.Perez@colorado.edu> | |
|
2 | ||
|
3 | * IPython/iplib.py (runsource): Prepend an 'if 1:' to the user | |
|
4 | input if it starts with whitespace. This allows you to paste | |
|
5 | indented input from any editor without manually having to type in | |
|
6 | the 'if 1:', which is conveninent when working interactively. | |
|
7 | Slightly modifed version of a patch by Bo Peng | |
|
8 | <bpeng-AT-rice.edu>. | |
|
9 | ||
|
1 | 10 | 2006-11-03 Fernando Perez <Fernando.Perez@colorado.edu> |
|
2 | 11 | |
|
3 | 12 | * IPython/irunner.py (main): modified irunner so it automatically |
@@ -7,12 +7,6 b" in './scripts' directory. This file is here (ipython source root directory)" | |||
|
7 | 7 | to facilitate non-root 'zero-installation' (just copy the source tree |
|
8 | 8 | somewhere and run ipython.py) and development. """ |
|
9 | 9 | |
|
10 | # Start by cleaning up sys.path: Python automatically inserts the script's | |
|
11 | # base directory into sys.path, at the front. This can lead to unpleasant | |
|
12 | # surprises. | |
|
13 | import sys | |
|
14 | sys.path.pop(0) | |
|
15 | ||
|
16 | 10 | import IPython |
|
17 | 11 | |
|
18 | 12 | IPython.Shell.start().mainloop() |
@@ -23,11 +23,5 b' this mode, there is no way to pass IPython any command-line options, as those' | |||
|
23 | 23 | are trapped first by Python itself. |
|
24 | 24 | """ |
|
25 | 25 | |
|
26 | # Start by cleaning up sys.path: Python automatically inserts the script's | |
|
27 | # base directory into sys.path, at the front. This can lead to unpleasant | |
|
28 | # surprises. | |
|
29 | import sys | |
|
30 | sys.path.pop(0) | |
|
31 | ||
|
32 | 26 | import IPython |
|
33 | 27 | IPython.Shell.start().mainloop() |
General Comments 0
You need to be logged in to leave comments.
Login now