##// END OF EJS Templates
module completer caches the root module list if it was too slow (3 secs)...
vivainio -
Show More
@@ -8,34 +8,60 b' but the basic idea is to do:'
8 ip.set_hook('complete_command', svn_completer, str_key = 'svn')
8 ip.set_hook('complete_command', svn_completer, str_key = 'svn')
9
9
10 """
10 """
11
12 import IPython.ipapi
11 import IPython.ipapi
13 import glob,os,shlex,sys
12 import glob,os,shlex,sys
14 import inspect
13 import inspect
14 from time import time
15 ip = IPython.ipapi.get()
15 ip = IPython.ipapi.get()
16
16
17 TIMEOUT_STORAGE = 3 #Time in seconds after which the rootmodules will be stored
18 TIMEOUT_GIVEUP = 20 #Time in seconds after which we give up
19
17 def getRootModules():
20 def getRootModules():
18 """
21 """
19 Returns a list containing the names of all the modules available in the
22 Returns a list containing the names of all the modules available in the
20 folders of the pythonpath.
23 folders of the pythonpath.
21 """
24 """
22 modules = []
25 modules = []
26 if ip.db.has_key('rootmodules'):
27 return ip.db['rootmodules']
28 t = time()
29 store = False
23 for path in sys.path:
30 for path in sys.path:
24 modules += moduleList(path)
31 modules += moduleList(path)
32 if time() - t >= TIMEOUT_STORAGE and not store:
33 store = True
34 print "\nCaching the list of root modules, please wait!"
35 print "(This will only be done once - type '%rehashx' to " + \
36 "reset cache!)"
37 print
38 if time() - t > TIMEOUT_GIVEUP:
39 print "This is taking too long, we give up."
40 print
41 ip.db['rootmodules'] = []
42 return []
43
25 modules += sys.builtin_module_names
44 modules += sys.builtin_module_names
26 modules = list(set(modules))
45 modules = list(set(modules))
27 if '__init__' in modules:
46 if '__init__' in modules:
28 modules.remove('__init__')
47 modules.remove('__init__')
29 return list(set(modules))
48 modules = list(set(modules))
49 if store:
50 ip.db['rootmodules'] = modules
51 return modules
30
52
31 def moduleList(path):
53 def moduleList(path):
32 """
54 """
33 Return the list containing the names of the modules available in the given
55 Return the list containing the names of the modules available in the given
34 folder.
56 folder.
35 """
57 """
36 folder_list = glob.glob(os.path.join(path,'*'))
58 if os.path.isdir(path):
59 folder_list = os.listdir(path)
60 else:
61 folder_list = []
62 #folder_list = glob.glob(os.path.join(path,'*'))
37 folder_list = [path for path in folder_list \
63 folder_list = [path for path in folder_list \
38 if (os.path.isdir(path) and os.path.exists(os.path.join(path,'__init__.py')))\
64 if os.path.exists(os.path.join(path,'__init__.py'))\
39 or path[-3:] in ('.py','.so')\
65 or path[-3:] in ('.py','.so')\
40 or path[-4:] in ('.pyc','.pyo')]
66 or path[-4:] in ('.pyc','.pyo')]
41 folder_list += folder_list
67 folder_list += folder_list
@@ -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 2225 2007-04-08 02:48:16Z jdh2358 $"""
4 $Id: Magic.py 2276 2007-04-26 16:35:02Z 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
@@ -2533,7 +2533,17 b' Defaulting color scheme to \'NoColor\'"""'
2533
2533
2534 Under Windows, it checks executability as a match agains a
2534 Under Windows, it checks executability as a match agains a
2535 '|'-separated string of extensions, stored in the IPython config
2535 '|'-separated string of extensions, stored in the IPython config
2536 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2536 variable win_exec_ext. This defaults to 'exe|com|bat'.
2537
2538 This function also resets the root module cache of module completer,
2539 used on slow filesystems.
2540 """
2541
2542
2543 ip = self.api
2544
2545 # for the benefit of module completer in ipy_completers.py
2546 del ip.db['rootmodules']
2537
2547
2538 path = [os.path.abspath(os.path.expanduser(p)) for p in
2548 path = [os.path.abspath(os.path.expanduser(p)) for p in
2539 os.environ['PATH'].split(os.pathsep)]
2549 os.environ['PATH'].split(os.pathsep)]
@@ -2583,7 +2593,7 b' Defaulting color scheme to \'NoColor\'"""'
2583 # Call again init_auto_alias() so we get 'rm -i' and other
2593 # Call again init_auto_alias() so we get 'rm -i' and other
2584 # modified aliases since %rehashx will probably clobber them
2594 # modified aliases since %rehashx will probably clobber them
2585 self.shell.init_auto_alias()
2595 self.shell.init_auto_alias()
2586 db = self.getapi().db
2596 db = ip.db
2587 db['syscmdlist'] = syscmdlist
2597 db['syscmdlist'] = syscmdlist
2588 finally:
2598 finally:
2589 os.chdir(savedir)
2599 os.chdir(savedir)
@@ -1,3 +1,11 b''
1 2007-04-26 Ville Vainio <vivainio@gmail.com>
2
3 * Extensions/ipy_completers.py: Olivier's module completer now
4 saves the list of root modules if it takes > 4 secs on the first run.
5
6 * Magic.py (%rehashx): %rehashx now clears the completer cache
7
8
1 2007-04-26 Fernando Perez <Fernando.Perez@colorado.edu>
9 2007-04-26 Fernando Perez <Fernando.Perez@colorado.edu>
2
10
3 * ipython.el: fix incorrect color scheme, reported by Stefan.
11 * ipython.el: fix incorrect color scheme, reported by Stefan.
@@ -21,8 +29,8 b''
21
29
22 2007-04-22 J�rgen Stenarson <jorgen.stenarson@bostream.nu>
30 2007-04-22 J�rgen Stenarson <jorgen.stenarson@bostream.nu>
23
31
24 * Fix bug in iplib.py/safe_execfile when launching ipython with a script like ipython.py foo.py
32 * Fix bug in iplib.py/safe_execfile when launching ipython with a script
25 which raised a IndexError.
33 like ipython.py foo.py which raised a IndexError.
26
34
27 2007-04-21 Ville Vainio <vivainio@gmail.com>
35 2007-04-21 Ville Vainio <vivainio@gmail.com>
28
36
General Comments 0
You need to be logged in to leave comments. Login now