##// END OF EJS Templates
moved many magics to ipy_legacy.py, moved profiles to Extension from UserConfig, added ipy_profile_none.py for default profile
vivainio -
Show More
@@ -0,0 +1,251 b''
1 """ Legacy stuff
2
3 Various stuff that are there for historical / familiarity reasons.
4
5 This is automatically imported by default profile, though not other profiles
6 (e.g. 'sh' profile).
7
8 Stuff that is considered obsolete / redundant is gradually moved here.
9
10 """
11
12 import IPython.ipapi
13 ip = IPython.ipapi.get()
14
15 import os,sys
16
17 from IPython.genutils import *
18
19 # use ?
20 def magic_pdef(self, parameter_s='', namespaces=None):
21 """Print the definition header for any callable object.
22
23 If the object is a class, print the constructor information."""
24 self._inspect('pdef',parameter_s, namespaces)
25
26 ip.expose_magic("pdef", magic_pdef)
27
28 # use ?
29 def magic_pdoc(self, parameter_s='', namespaces=None):
30 """Print the docstring for an object.
31
32 If the given object is a class, it will print both the class and the
33 constructor docstrings."""
34 self._inspect('pdoc',parameter_s, namespaces)
35
36 ip.expose_magic("pdoc", magic_pdoc)
37
38 # use ??
39 def magic_psource(self, parameter_s='', namespaces=None):
40 """Print (or run through pager) the source code for an object."""
41 self._inspect('psource',parameter_s, namespaces)
42
43 ip.expose_magic("pdoc", magic_psource)
44
45 # use ?
46 def magic_pfile(self, parameter_s=''):
47 """Print (or run through pager) the file where an object is defined.
48
49 The file opens at the line where the object definition begins. IPython
50 will honor the environment variable PAGER if set, and otherwise will
51 do its best to print the file in a convenient form.
52
53 If the given argument is not an object currently defined, IPython will
54 try to interpret it as a filename (automatically adding a .py extension
55 if needed). You can thus use %pfile as a syntax highlighting code
56 viewer."""
57
58 # first interpret argument as an object name
59 out = self._inspect('pfile',parameter_s)
60 # if not, try the input as a filename
61 if out == 'not found':
62 try:
63 filename = get_py_filename(parameter_s)
64 except IOError,msg:
65 print msg
66 return
67 page(self.shell.inspector.format(file(filename).read()))
68
69 ip.expose_magic("pfile", magic_pfile)
70
71 # use rehashx
72
73 def magic_rehash(self, parameter_s = ''):
74 """Update the alias table with all entries in $PATH.
75
76 This version does no checks on execute permissions or whether the
77 contents of $PATH are truly files (instead of directories or something
78 else). For such a safer (but slower) version, use %rehashx."""
79
80 # This function (and rehashx) manipulate the alias_table directly
81 # rather than calling magic_alias, for speed reasons. A rehash on a
82 # typical Linux box involves several thousand entries, so efficiency
83 # here is a top concern.
84
85 path = filter(os.path.isdir,os.environ.get('PATH','').split(os.pathsep))
86 alias_table = self.shell.alias_table
87 for pdir in path:
88 for ff in os.listdir(pdir):
89 # each entry in the alias table must be (N,name), where
90 # N is the number of positional arguments of the alias.
91 alias_table[ff] = (0,ff)
92 # Make sure the alias table doesn't contain keywords or builtins
93 self.shell.alias_table_validate()
94 # Call again init_auto_alias() so we get 'rm -i' and other modified
95 # aliases since %rehash will probably clobber them
96 self.shell.init_auto_alias()
97
98 ip.expose_magic("rehash", magic_rehash)
99
100 #use cd -<tab>
101 def magic_dhist(self, parameter_s=''):
102 """Print your history of visited directories.
103
104 %dhist -> print full history\\
105 %dhist n -> print last n entries only\\
106 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
107
108 This history is automatically maintained by the %cd command, and
109 always available as the global list variable _dh. You can use %cd -<n>
110 to go to directory number <n>."""
111
112 dh = self.shell.user_ns['_dh']
113 if parameter_s:
114 try:
115 args = map(int,parameter_s.split())
116 except:
117 self.arg_err(Magic.magic_dhist)
118 return
119 if len(args) == 1:
120 ini,fin = max(len(dh)-(args[0]),0),len(dh)
121 elif len(args) == 2:
122 ini,fin = args
123 else:
124 self.arg_err(Magic.magic_dhist)
125 return
126 else:
127 ini,fin = 0,len(dh)
128 nlprint(dh,
129 header = 'Directory history (kept in _dh)',
130 start=ini,stop=fin)
131
132 ip.expose_magic("dhist", magic_dhist)
133
134 # Exit
135 def magic_Quit(self, parameter_s=''):
136 """Exit IPython without confirmation (like %Exit)."""
137
138 self.shell.exit_now = True
139
140 ip.expose_magic("Quit", magic_Quit)
141
142
143 # make it autocallable fn if you really need it
144 def magic_p(self, parameter_s=''):
145 """Just a short alias for Python's 'print'."""
146 exec 'print ' + parameter_s in self.shell.user_ns
147
148 ip.expose_magic("p", magic_p)
149
150 # up + enter. One char magic.
151 def magic_r(self, parameter_s=''):
152 """Repeat previous input.
153
154 If given an argument, repeats the previous command which starts with
155 the same string, otherwise it just repeats the previous input.
156
157 Shell escaped commands (with ! as first character) are not recognized
158 by this system, only pure python code and magic commands.
159 """
160
161 start = parameter_s.strip()
162 esc_magic = self.shell.ESC_MAGIC
163 # Identify magic commands even if automagic is on (which means
164 # the in-memory version is different from that typed by the user).
165 if self.shell.rc.automagic:
166 start_magic = esc_magic+start
167 else:
168 start_magic = start
169 # Look through the input history in reverse
170 for n in range(len(self.shell.input_hist)-2,0,-1):
171 input = self.shell.input_hist[n]
172 # skip plain 'r' lines so we don't recurse to infinity
173 if input != '_ip.magic("r")\n' and \
174 (input.startswith(start) or input.startswith(start_magic)):
175 #print 'match',`input` # dbg
176 print 'Executing:',input,
177 self.shell.runlines(input)
178 return
179 print 'No previous input matching `%s` found.' % start
180
181 ip.expose_magic("r", magic_r)
182
183
184 # use _ip.option.automagic
185
186 def magic_automagic(self, parameter_s = ''):
187 """Make magic functions callable without having to type the initial %.
188
189 Without argumentsl toggles on/off (when off, you must call it as
190 %automagic, of course). With arguments it sets the value, and you can
191 use any of (case insensitive):
192
193 - on,1,True: to activate
194
195 - off,0,False: to deactivate.
196
197 Note that magic functions have lowest priority, so if there's a
198 variable whose name collides with that of a magic fn, automagic won't
199 work for that function (you get the variable instead). However, if you
200 delete the variable (del var), the previously shadowed magic function
201 becomes visible to automagic again."""
202
203 rc = self.shell.rc
204 arg = parameter_s.lower()
205 if parameter_s in ('on','1','true'):
206 rc.automagic = True
207 elif parameter_s in ('off','0','false'):
208 rc.automagic = False
209 else:
210 rc.automagic = not rc.automagic
211 print '\n' + Magic.auto_status[rc.automagic]
212
213 ip.expose_magic("automagic", magic_automagic)
214
215 # use _ip.options.autocall
216 def magic_autocall(self, parameter_s = ''):
217 """Make functions callable without having to type parentheses.
218
219 Usage:
220
221 %autocall [mode]
222
223 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
224 value is toggled on and off (remembering the previous state)."""
225
226 rc = self.shell.rc
227
228 if parameter_s:
229 arg = int(parameter_s)
230 else:
231 arg = 'toggle'
232
233 if not arg in (0,1,2,'toggle'):
234 error('Valid modes: (0->Off, 1->Smart, 2->Full')
235 return
236
237 if arg in (0,1,2):
238 rc.autocall = arg
239 else: # toggle
240 if rc.autocall:
241 self._magic_state.autocall_save = rc.autocall
242 rc.autocall = 0
243 else:
244 try:
245 rc.autocall = self._magic_state.autocall_save
246 except AttributeError:
247 rc.autocall = self._magic_state.autocall_save = 1
248
249 print "Automatic calling is:",['OFF','Smart','Full'][rc.autocall]
250
251 ip.expose_magic("autocall", magic_autocall) No newline at end of file
@@ -0,0 +1,4 b''
1 """ Config file for 'default' profile """
2
3 # get various stuff that are there for historical / familiarity reasons
4 import ipy_legacy No newline at end of file
1 NO CONTENT: file renamed from IPython/UserConfig/ipy_profile_scipy.py to IPython/Extensions/ipy_profile_scipy.py
NO CONTENT: file renamed from IPython/UserConfig/ipy_profile_scipy.py to IPython/Extensions/ipy_profile_scipy.py
1 NO CONTENT: file renamed from IPython/UserConfig/ipy_profile_sh.py to IPython/Extensions/ipy_profile_sh.py
NO CONTENT: file renamed from IPython/UserConfig/ipy_profile_sh.py to IPython/Extensions/ipy_profile_sh.py
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3
3
4 $Id: Magic.py 2353 2007-05-15 19:27:14Z vivainio $"""
4 $Id: Magic.py 2380 2007-05-24 17:03:49Z vivainio $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -452,67 +452,6 b' Currently the magic system has the following functions:\\n"""'
452
452
453 page(outmsg,screen_lines=self.shell.rc.screen_length)
453 page(outmsg,screen_lines=self.shell.rc.screen_length)
454
454
455 def magic_automagic(self, parameter_s = ''):
456 """Make magic functions callable without having to type the initial %.
457
458 Without argumentsl toggles on/off (when off, you must call it as
459 %automagic, of course). With arguments it sets the value, and you can
460 use any of (case insensitive):
461
462 - on,1,True: to activate
463
464 - off,0,False: to deactivate.
465
466 Note that magic functions have lowest priority, so if there's a
467 variable whose name collides with that of a magic fn, automagic won't
468 work for that function (you get the variable instead). However, if you
469 delete the variable (del var), the previously shadowed magic function
470 becomes visible to automagic again."""
471
472 rc = self.shell.rc
473 arg = parameter_s.lower()
474 if parameter_s in ('on','1','true'):
475 rc.automagic = True
476 elif parameter_s in ('off','0','false'):
477 rc.automagic = False
478 else:
479 rc.automagic = not rc.automagic
480 print '\n' + Magic.auto_status[rc.automagic]
481
482 def magic_autocall(self, parameter_s = ''):
483 """Make functions callable without having to type parentheses.
484
485 Usage:
486
487 %autocall [mode]
488
489 The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the
490 value is toggled on and off (remembering the previous state)."""
491
492 rc = self.shell.rc
493
494 if parameter_s:
495 arg = int(parameter_s)
496 else:
497 arg = 'toggle'
498
499 if not arg in (0,1,2,'toggle'):
500 error('Valid modes: (0->Off, 1->Smart, 2->Full')
501 return
502
503 if arg in (0,1,2):
504 rc.autocall = arg
505 else: # toggle
506 if rc.autocall:
507 self._magic_state.autocall_save = rc.autocall
508 rc.autocall = 0
509 else:
510 try:
511 rc.autocall = self._magic_state.autocall_save
512 except AttributeError:
513 rc.autocall = self._magic_state.autocall_save = 1
514
515 print "Automatic calling is:",['OFF','Smart','Full'][rc.autocall]
516
455
517 def magic_autoindent(self, parameter_s = ''):
456 def magic_autoindent(self, parameter_s = ''):
518 """Toggle autoindent on/off (if available)."""
457 """Toggle autoindent on/off (if available)."""
@@ -548,18 +487,18 b' Currently the magic system has the following functions:\\n"""'
548
487
549 Options:
488 Options:
550
489
551 -n: do NOT print line numbers. This is useful if you want to get a
490 -n: do NOT print line numbers. This is useful if you want to get a
552 printout of many lines which can be directly pasted into a text
491 printout of many lines which can be directly pasted into a text
553 editor.
492 editor.
554
493
555 This feature is only available if numbered prompts are in use.
494 This feature is only available if numbered prompts are in use.
556
495
557 -r: print the 'raw' history. IPython filters your input and
496 -n: print the 'native' history, as IPython understands it. IPython
558 converts it all into valid Python source before executing it (things
497 filters your input and converts it all into valid Python source before
559 like magics or aliases are turned into function calls, for
498 executing it (things like magics or aliases are turned into function
560 example). With this option, you'll see the unfiltered history
499 calls, for example). With this option, you'll see the native history
561 instead of the filtered version: '%cd /' will be seen as '%cd /'
500 instead of the user-entered version: '%cd /' will be seen as
562 instead of '_ip.magic("%cd /")'.
501 '_ip.magic("%cd /")' instead of '%cd /'.
563 """
502 """
564
503
565 shell = self.shell
504 shell = self.shell
@@ -568,7 +507,7 b' Currently the magic system has the following functions:\\n"""'
568 return
507 return
569 opts,args = self.parse_options(parameter_s,'nr',mode='list')
508 opts,args = self.parse_options(parameter_s,'nr',mode='list')
570
509
571 if opts.has_key('r'):
510 if not opts.has_key('n'):
572 input_hist = shell.input_hist_raw
511 input_hist = shell.input_hist_raw
573 else:
512 else:
574 input_hist = shell.input_hist
513 input_hist = shell.input_hist
@@ -600,39 +539,6 b' Currently the magic system has the following functions:\\n"""'
600 """Alternate name for %history."""
539 """Alternate name for %history."""
601 return self.magic_history(parameter_s)
540 return self.magic_history(parameter_s)
602
541
603 def magic_p(self, parameter_s=''):
604 """Just a short alias for Python's 'print'."""
605 exec 'print ' + parameter_s in self.shell.user_ns
606
607 def magic_r(self, parameter_s=''):
608 """Repeat previous input.
609
610 If given an argument, repeats the previous command which starts with
611 the same string, otherwise it just repeats the previous input.
612
613 Shell escaped commands (with ! as first character) are not recognized
614 by this system, only pure python code and magic commands.
615 """
616
617 start = parameter_s.strip()
618 esc_magic = self.shell.ESC_MAGIC
619 # Identify magic commands even if automagic is on (which means
620 # the in-memory version is different from that typed by the user).
621 if self.shell.rc.automagic:
622 start_magic = esc_magic+start
623 else:
624 start_magic = start
625 # Look through the input history in reverse
626 for n in range(len(self.shell.input_hist)-2,0,-1):
627 input = self.shell.input_hist[n]
628 # skip plain 'r' lines so we don't recurse to infinity
629 if input != '_ip.magic("r")\n' and \
630 (input.startswith(start) or input.startswith(start_magic)):
631 #print 'match',`input` # dbg
632 print 'Executing:',input,
633 self.shell.runlines(input)
634 return
635 print 'No previous input matching `%s` found.' % start
636
542
637 def magic_page(self, parameter_s=''):
543 def magic_page(self, parameter_s=''):
638 """Pretty print the object and display it through a pager.
544 """Pretty print the object and display it through a pager.
@@ -665,6 +571,27 b' Currently the magic system has the following functions:\\n"""'
665 printpl('Current IPython profile: $self.shell.rc.profile.')
571 printpl('Current IPython profile: $self.shell.rc.profile.')
666 else:
572 else:
667 print 'No profile active.'
573 print 'No profile active.'
574
575 def magic_pinfo(self, parameter_s='', namespaces=None):
576 """Provide detailed information about an object.
577
578 '%pinfo object' is just a synonym for object? or ?object."""
579
580 #print 'pinfo par: <%s>' % parameter_s # dbg
581
582 # detail_level: 0 -> obj? , 1 -> obj??
583 detail_level = 0
584 # We need to detect if we got called as 'pinfo pinfo foo', which can
585 # happen if the user types 'pinfo foo?' at the cmd line.
586 pinfo,qmark1,oname,qmark2 = \
587 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
588 if pinfo or qmark1 or qmark2:
589 detail_level = 1
590 if "*" in oname:
591 self.magic_psearch(oname)
592 else:
593 self._inspect('pinfo', oname, detail_level=detail_level,
594 namespaces=namespaces)
668
595
669 def _inspect(self,meth,oname,namespaces=None,**kw):
596 def _inspect(self,meth,oname,namespaces=None,**kw):
670 """Generic interface to the inspector system.
597 """Generic interface to the inspector system.
@@ -711,67 +638,6 b' Currently the magic system has the following functions:\\n"""'
711 print 'Object `%s` not found.' % oname
638 print 'Object `%s` not found.' % oname
712 return 'not found' # so callers can take other action
639 return 'not found' # so callers can take other action
713
640
714 def magic_pdef(self, parameter_s='', namespaces=None):
715 """Print the definition header for any callable object.
716
717 If the object is a class, print the constructor information."""
718 self._inspect('pdef',parameter_s, namespaces)
719
720 def magic_pdoc(self, parameter_s='', namespaces=None):
721 """Print the docstring for an object.
722
723 If the given object is a class, it will print both the class and the
724 constructor docstrings."""
725 self._inspect('pdoc',parameter_s, namespaces)
726
727 def magic_psource(self, parameter_s='', namespaces=None):
728 """Print (or run through pager) the source code for an object."""
729 self._inspect('psource',parameter_s, namespaces)
730
731 def magic_pfile(self, parameter_s=''):
732 """Print (or run through pager) the file where an object is defined.
733
734 The file opens at the line where the object definition begins. IPython
735 will honor the environment variable PAGER if set, and otherwise will
736 do its best to print the file in a convenient form.
737
738 If the given argument is not an object currently defined, IPython will
739 try to interpret it as a filename (automatically adding a .py extension
740 if needed). You can thus use %pfile as a syntax highlighting code
741 viewer."""
742
743 # first interpret argument as an object name
744 out = self._inspect('pfile',parameter_s)
745 # if not, try the input as a filename
746 if out == 'not found':
747 try:
748 filename = get_py_filename(parameter_s)
749 except IOError,msg:
750 print msg
751 return
752 page(self.shell.inspector.format(file(filename).read()))
753
754 def magic_pinfo(self, parameter_s='', namespaces=None):
755 """Provide detailed information about an object.
756
757 '%pinfo object' is just a synonym for object? or ?object."""
758
759 #print 'pinfo par: <%s>' % parameter_s # dbg
760
761 # detail_level: 0 -> obj? , 1 -> obj??
762 detail_level = 0
763 # We need to detect if we got called as 'pinfo pinfo foo', which can
764 # happen if the user types 'pinfo foo?' at the cmd line.
765 pinfo,qmark1,oname,qmark2 = \
766 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
767 if pinfo or qmark1 or qmark2:
768 detail_level = 1
769 if "*" in oname:
770 self.magic_psearch(oname)
771 else:
772 self._inspect('pinfo', oname, detail_level=detail_level,
773 namespaces=namespaces)
774
775 def magic_psearch(self, parameter_s=''):
641 def magic_psearch(self, parameter_s=''):
776 """Search for object in namespaces by wildcard.
642 """Search for object in namespaces by wildcard.
777
643
@@ -2398,11 +2264,6 b' Defaulting color scheme to \'NoColor\'"""'
2398
2264
2399 self.shell.exit_now = True
2265 self.shell.exit_now = True
2400
2266
2401 def magic_Quit(self, parameter_s=''):
2402 """Exit IPython without confirmation (like %Exit)."""
2403
2404 self.shell.exit_now = True
2405
2406 #......................................................................
2267 #......................................................................
2407 # Functions to implement unix shell-type things
2268 # Functions to implement unix shell-type things
2408
2269
@@ -2506,30 +2367,6 b' Defaulting color scheme to \'NoColor\'"""'
2506 del stored[aname]
2367 del stored[aname]
2507 self.db['stored_aliases'] = stored
2368 self.db['stored_aliases'] = stored
2508
2369
2509 def magic_rehash(self, parameter_s = ''):
2510 """Update the alias table with all entries in $PATH.
2511
2512 This version does no checks on execute permissions or whether the
2513 contents of $PATH are truly files (instead of directories or something
2514 else). For such a safer (but slower) version, use %rehashx."""
2515
2516 # This function (and rehashx) manipulate the alias_table directly
2517 # rather than calling magic_alias, for speed reasons. A rehash on a
2518 # typical Linux box involves several thousand entries, so efficiency
2519 # here is a top concern.
2520
2521 path = filter(os.path.isdir,os.environ.get('PATH','').split(os.pathsep))
2522 alias_table = self.shell.alias_table
2523 for pdir in path:
2524 for ff in os.listdir(pdir):
2525 # each entry in the alias table must be (N,name), where
2526 # N is the number of positional arguments of the alias.
2527 alias_table[ff] = (0,ff)
2528 # Make sure the alias table doesn't contain keywords or builtins
2529 self.shell.alias_table_validate()
2530 # Call again init_auto_alias() so we get 'rm -i' and other modified
2531 # aliases since %rehash will probably clobber them
2532 self.shell.init_auto_alias()
2533
2370
2534 def magic_rehashx(self, parameter_s = ''):
2371 def magic_rehashx(self, parameter_s = ''):
2535 """Update the alias table with all executable files in $PATH.
2372 """Update the alias table with all executable files in $PATH.
@@ -2701,36 +2538,6 b' Defaulting color scheme to \'NoColor\'"""'
2701 if not 'q' in opts:
2538 if not 'q' in opts:
2702 print self.shell.user_ns['_dh'][-1]
2539 print self.shell.user_ns['_dh'][-1]
2703
2540
2704 def magic_dhist(self, parameter_s=''):
2705 """Print your history of visited directories.
2706
2707 %dhist -> print full history\\
2708 %dhist n -> print last n entries only\\
2709 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2710
2711 This history is automatically maintained by the %cd command, and
2712 always available as the global list variable _dh. You can use %cd -<n>
2713 to go to directory number <n>."""
2714
2715 dh = self.shell.user_ns['_dh']
2716 if parameter_s:
2717 try:
2718 args = map(int,parameter_s.split())
2719 except:
2720 self.arg_err(Magic.magic_dhist)
2721 return
2722 if len(args) == 1:
2723 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2724 elif len(args) == 2:
2725 ini,fin = args
2726 else:
2727 self.arg_err(Magic.magic_dhist)
2728 return
2729 else:
2730 ini,fin = 0,len(dh)
2731 nlprint(dh,
2732 header = 'Directory history (kept in _dh)',
2733 start=ini,stop=fin)
2734
2541
2735 def magic_env(self, parameter_s=''):
2542 def magic_env(self, parameter_s=''):
2736 """List environment variables."""
2543 """List environment variables."""
@@ -6,7 +6,7 b' Requires Python 2.1 or better.'
6
6
7 This file contains the main make_IPython() starter function.
7 This file contains the main make_IPython() starter function.
8
8
9 $Id: ipmaker.py 2156 2007-03-19 02:32:19Z fperez $"""
9 $Id: ipmaker.py 2380 2007-05-24 17:03:49Z vivainio $"""
10
10
11 #*****************************************************************************
11 #*****************************************************************************
12 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
12 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
@@ -637,7 +637,8 b" object? -> Details about 'object'. ?object also works, ?? prints more."
637 print "Error importing",profmodname,"- perhaps you should run %upgrade?"
637 print "Error importing",profmodname,"- perhaps you should run %upgrade?"
638 IP.InteractiveTB()
638 IP.InteractiveTB()
639 import_fail_info(profmodname)
639 import_fail_info(profmodname)
640
640 else:
641 import ipy_profile_none
641 try:
642 try:
642 import ipy_user_conf
643 import ipy_user_conf
643 except ImportError:
644 except ImportError:
General Comments 0
You need to be logged in to leave comments. Login now