def magic_run_completer(self, event): """Complete files that end in .py or .ipy or .ipynb for the %run command. """ comps = arg_split(event.line, strict=False) # relpath should be the current token that we need to complete. if (len(comps) > 1) and (not event.line.endswith(' ')): relpath = comps[-1].strip("'\"") else: relpath = '' #print("\nev=", event) # dbg #print("rp=", relpath) # dbg #print('comps=', comps) # dbg lglob = glob.glob isdir = os.path.isdir relpath, tilde_expand, tilde_val = expand_user(relpath) # Find if the user has already typed the first filename, after which we # should complete on all files, since after the first one other files may # be arguments to the input script. if any(magic_run_re.match(c) for c in comps): matches = [f.replace('\\','/') + ('/' if isdir(f) else '') for f in lglob(relpath+'*')] else: dirs = [f.replace('\\','/') + "/" for f in lglob(relpath+'*') if isdir(f)] pys = [f.replace('\\','/') for f in lglob(relpath+'*.py') + lglob(relpath+'*.ipy') + lglob(relpath+'*.ipynb') + lglob(relpath + '*.pyw')] matches = dirs + pys #print('run comp:', dirs+pys) # dbg return [compress_user(p, tilde_expand, tilde_val) for p in matches]
def magic_run_completer(self, event): """Complete files that end in .py or .ipy for the %run command. """ comps = arg_split(event.line, strict=False) relpath = (len(comps) > 1 and comps[-1] or '').strip("'\"") #print("\nev=", event) # dbg #print("rp=", relpath) # dbg #print('comps=', comps) # dbg lglob = glob.glob isdir = os.path.isdir relpath, tilde_expand, tilde_val = expand_user(relpath) dirs = [f.replace('\\','/') + "/" for f in lglob(relpath+'*') if isdir(f)] # Find if the user has already typed the first filename, after which we # should complete on all files, since after the first one other files may # be arguments to the input script. if filter(magic_run_re.match, comps): pys = [f.replace('\\','/') for f in lglob('*')] else: pys = [f.replace('\\','/') for f in lglob(relpath+'*.py') + lglob(relpath+'*.ipy') + lglob(relpath + '*.pyw')] #print('run comp:', dirs+pys) # dbg return [compress_user(p, tilde_expand, tilde_val) for p in dirs+pys]
def magic_run_completer(self, event): """Complete files that end in .py or .ipy for the %run command. """ comps = arg_split(event.line, strict=False) relpath = (len(comps) > 1 and comps[-1] or '').strip("'\"") #print("\nev=", event) # dbg #print("rp=", relpath) # dbg #print('comps=', comps) # dbg lglob = glob.glob isdir = os.path.isdir relpath, tilde_expand, tilde_val = expand_user(relpath) dirs = [ f.replace('\\', '/') + "/" for f in lglob(relpath + '*') if isdir(f) ] # Find if the user has already typed the first filename, after which we # should complete on all files, since after the first one other files may # be arguments to the input script. if list(filter(magic_run_re.match, comps)): pys = [f.replace('\\', '/') for f in lglob('*')] else: pys = [ f.replace('\\', '/') for f in lglob(relpath + '*.py') + lglob(relpath + '*.ipy') + lglob(relpath + '*.pyw') ] #print('run comp:', dirs+pys) # dbg return [compress_user(p, tilde_expand, tilde_val) for p in dirs + pys]
def capture_handler(magic): string_of_magic_args = magic.python x, _ = _capture_arg_parser.parse_known_args( arg_split(string_of_magic_args)) if x.output: return '%s = "dummy captured output"' % x.output else: return 'pass # was capture cell magic with no output arg'
def _script_handler(magic, script_name, script_arg_s): x, _ = _script_arg_parser.parse_known_args(arg_split(script_arg_s)) # this is sneaky magic.additional_lines = ["pass # script content omitted"] if x.out: return '%s = "dummy output from %s script run in subprocess"' % ( x.out, script_name) else: return 'pass # was %s script cell magic with no --out' % script_name