Returns a list containing the completion possibilities for an import line. The line looks like this : 'import xml.d' 'from xml.dom import'
(line)
| 236 | get_ipython().set_hook('complete_command',do_complete, str_key = cmd) |
| 237 | |
| 238 | def module_completion(line): |
| 239 | """ |
| 240 | Returns a list containing the completion possibilities for an import line. |
| 241 | |
| 242 | The line looks like this : |
| 243 | 'import xml.d' |
| 244 | 'from xml.dom import' |
| 245 | """ |
| 246 | |
| 247 | words = line.split(' ') |
| 248 | nwords = len(words) |
| 249 | |
| 250 | # from whatever <tab> -> 'import ' |
| 251 | if nwords == 3 and words[0] == 'from': |
| 252 | return ['import '] |
| 253 | |
| 254 | # 'from xy<tab>' or 'import xy<tab>' |
| 255 | if nwords < 3 and (words[0] in {'%aimport', 'import', 'from'}) : |
| 256 | if nwords == 1: |
| 257 | return get_root_modules() |
| 258 | mod = words[1].split('.') |
| 259 | if len(mod) < 2: |
| 260 | return get_root_modules() |
| 261 | completion_list = try_import('.'.join(mod[:-1]), True) |
| 262 | return ['.'.join(mod[:-1] + [el]) for el in completion_list] |
| 263 | |
| 264 | # 'from xyz import abc<tab>' |
| 265 | if nwords >= 3 and words[0] == 'from': |
| 266 | mod = words[1] |
| 267 | return try_import(mod) |
| 268 | |
| 269 | #----------------------------------------------------------------------------- |
| 270 | # Completers |
searching dependent graphs…