Complete files that end in .py or .ipy or .ipynb for the %run command.
(self, event)
| 259 | # completers, that is currently reimplemented in each. |
| 260 | |
| 261 | def magic_run_completer(self, event): |
| 262 | """Complete files that end in .py or .ipy or .ipynb for the %run command. |
| 263 | """ |
| 264 | comps = arg_split(event.line, strict=False) |
| 265 | # relpath should be the current token that we need to complete. |
| 266 | if (len(comps) > 1) and (not event.line.endswith(' ')): |
| 267 | relpath = comps[-1].strip("'\"") |
| 268 | else: |
| 269 | relpath = '' |
| 270 | |
| 271 | #print("\nev=", event) # dbg |
| 272 | #print("rp=", relpath) # dbg |
| 273 | #print('comps=', comps) # dbg |
| 274 | |
| 275 | lglob = glob.glob |
| 276 | isdir = os.path.isdir |
| 277 | relpath, tilde_expand, tilde_val = expand_user(relpath) |
| 278 | |
| 279 | # Find if the user has already typed the first filename, after which we |
| 280 | # should complete on all files, since after the first one other files may |
| 281 | # be arguments to the input script. |
| 282 | |
| 283 | if any(magic_run_re.match(c) for c in comps): |
| 284 | matches = [f.replace('\\','/') + ('/' if isdir(f) else '') |
| 285 | for f in lglob(relpath+'*')] |
| 286 | else: |
| 287 | dirs = [f.replace('\\','/') + "/" for f in lglob(relpath+'*') if isdir(f)] |
| 288 | pys = [f.replace('\\','/') |
| 289 | for f in lglob(relpath+'*.py') + lglob(relpath+'*.ipy') + |
| 290 | lglob(relpath+'*.ipynb') + lglob(relpath + '*.pyw')] |
| 291 | |
| 292 | matches = dirs + pys |
| 293 | |
| 294 | #print('run comp:', dirs+pys) # dbg |
| 295 | return [compress_user(p, tilde_expand, tilde_val) for p in matches] |
| 296 | |
| 297 | |
| 298 | def cd_completer(self, event): |