Complete files that end in .py or .ipy or .ipynb for the %run command.
(self, event)
| 287 | # completers, that is currently reimplemented in each. |
| 288 | |
| 289 | def magic_run_completer(self, event): |
| 290 | """Complete files that end in .py or .ipy or .ipynb for the %run command. |
| 291 | """ |
| 292 | comps = arg_split(event.line, strict=False) |
| 293 | # relpath should be the current token that we need to complete. |
| 294 | if (len(comps) > 1) and (not event.line.endswith(' ')): |
| 295 | relpath = comps[-1].strip("'\"") |
| 296 | else: |
| 297 | relpath = '' |
| 298 | |
| 299 | #print("\nev=", event) # dbg |
| 300 | #print("rp=", relpath) # dbg |
| 301 | #print('comps=', comps) # dbg |
| 302 | |
| 303 | lglob = glob.glob |
| 304 | isdir = os.path.isdir |
| 305 | relpath, tilde_expand, tilde_val = expand_user(relpath) |
| 306 | |
| 307 | # Find if the user has already typed the first filename, after which we |
| 308 | # should complete on all files, since after the first one other files may |
| 309 | # be arguments to the input script. |
| 310 | |
| 311 | if any(magic_run_re.match(c) for c in comps): |
| 312 | matches = [f.replace('\\','/') + ('/' if isdir(f) else '') |
| 313 | for f in lglob(relpath+'*')] |
| 314 | else: |
| 315 | dirs = [f.replace('\\','/') + "/" for f in lglob(relpath+'*') if isdir(f)] |
| 316 | pys = [f.replace('\\','/') |
| 317 | for f in lglob(relpath+'*.py') + lglob(relpath+'*.ipy') + |
| 318 | lglob(relpath+'*.ipynb') + lglob(relpath + '*.pyw')] |
| 319 | |
| 320 | matches = dirs + pys |
| 321 | |
| 322 | #print('run comp:', dirs+pys) # dbg |
| 323 | return [compress_user(p, tilde_expand, tilde_val) for p in matches] |
| 324 | |
| 325 | |
| 326 | def cd_completer(self, event): |
searching dependent graphs…