Show More
@@ -8,34 +8,60 b' but the basic idea is to do:' | |||
|
8 | 8 | ip.set_hook('complete_command', svn_completer, str_key = 'svn') |
|
9 | 9 | |
|
10 | 10 | """ |
|
11 | ||
|
12 | 11 | import IPython.ipapi |
|
13 | 12 | import glob,os,shlex,sys |
|
14 | 13 | import inspect |
|
14 | from time import time | |
|
15 | 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 | 20 | def getRootModules(): |
|
18 | 21 | """ |
|
19 | 22 | Returns a list containing the names of all the modules available in the |
|
20 | 23 | folders of the pythonpath. |
|
21 | 24 | """ |
|
22 | 25 | modules = [] |
|
26 | if ip.db.has_key('rootmodules'): | |
|
27 | return ip.db['rootmodules'] | |
|
28 | t = time() | |
|
29 | store = False | |
|
23 | 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 | ||
|
38 | if time() - t > TIMEOUT_GIVEUP: | |
|
39 | print "This is taking too long, we give up." | |
|
40 | ||
|
41 | ip.db['rootmodules'] = [] | |
|
42 | return [] | |
|
43 | ||
|
25 | 44 | modules += sys.builtin_module_names |
|
26 | 45 | modules = list(set(modules)) |
|
27 | 46 | if '__init__' in modules: |
|
28 | 47 | modules.remove('__init__') |
|
29 |
|
|
|
48 | modules = list(set(modules)) | |
|
49 | if store: | |
|
50 | ip.db['rootmodules'] = modules | |
|
51 | return modules | |
|
30 | 52 | |
|
31 | 53 | def moduleList(path): |
|
32 | 54 | """ |
|
33 | 55 | Return the list containing the names of the modules available in the given |
|
34 | 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 | 63 | folder_list = [path for path in folder_list \ |
|
38 |
if |
|
|
64 | if os.path.exists(os.path.join(path,'__init__.py'))\ | |
|
39 | 65 | or path[-3:] in ('.py','.so')\ |
|
40 | 66 | or path[-4:] in ('.pyc','.pyo')] |
|
41 | 67 | folder_list += folder_list |
@@ -1,7 +1,7 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """Magic functions for InteractiveShell. |
|
3 | 3 | |
|
4 |
$Id: Magic.py 22 |
|
|
4 | $Id: Magic.py 2276 2007-04-26 16:35:02Z vivainio $""" | |
|
5 | 5 | |
|
6 | 6 | #***************************************************************************** |
|
7 | 7 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
@@ -2533,7 +2533,17 b' Defaulting color scheme to \'NoColor\'"""' | |||
|
2533 | 2533 | |
|
2534 | 2534 | Under Windows, it checks executability as a match agains a |
|
2535 | 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 | 2548 | path = [os.path.abspath(os.path.expanduser(p)) for p in |
|
2539 | 2549 | os.environ['PATH'].split(os.pathsep)] |
@@ -2583,7 +2593,7 b' Defaulting color scheme to \'NoColor\'"""' | |||
|
2583 | 2593 | # Call again init_auto_alias() so we get 'rm -i' and other |
|
2584 | 2594 | # modified aliases since %rehashx will probably clobber them |
|
2585 | 2595 | self.shell.init_auto_alias() |
|
2586 |
db = |
|
|
2596 | db = ip.db | |
|
2587 | 2597 | db['syscmdlist'] = syscmdlist |
|
2588 | 2598 | finally: |
|
2589 | 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 | 9 | 2007-04-26 Fernando Perez <Fernando.Perez@colorado.edu> |
|
2 | 10 | |
|
3 | 11 | * ipython.el: fix incorrect color scheme, reported by Stefan. |
@@ -21,8 +29,8 b'' | |||
|
21 | 29 | |
|
22 | 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 |
|
|
25 | which raised a IndexError. | |
|
32 | * Fix bug in iplib.py/safe_execfile when launching ipython with a script | |
|
33 | like ipython.py foo.py which raised a IndexError. | |
|
26 | 34 | |
|
27 | 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