From 96560b70303cbec98619ef8850294eb18455d7c0 Mon Sep 17 00:00:00 2001 From: roy reznik Date: Sat, 30 Dec 2023 15:36:32 +0200 Subject: [PATCH] Remove needs for get_ipython (#10) --- greps/greps.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/greps/greps.py b/greps/greps.py index c3c1c05..b7389ad 100644 --- a/greps/greps.py +++ b/greps/greps.py @@ -1,7 +1,6 @@ import argparse import subprocess -from IPython.core.getipython import get_ipython from IPython.core.magic import ( Magics, magics_class, @@ -29,23 +28,23 @@ def get_args_parser() -> argparse.ArgumentParser: @line_magic # type: ignore[misc] def greps(self, params: str = "") -> str: parser = self.get_args_parser() - ipython = get_ipython() # type: ignore[no-untyped-call] args = parser.parse_args(params.split()) grep_args = " ".join(args.grep_args) line = args.line + assert self.shell, "Shell isn't Initialized" if line is None: - if len(ipython.history_manager.output_hist_reprs) < 1: + if len(self.shell.history_manager.output_hist_reprs) < 1: raise ValueError("Output history is empty") output_line = list( - sorted(ipython.history_manager.output_hist_reprs.keys()) + sorted(self.shell.history_manager.output_hist_reprs.keys()) )[-1] else: - if line not in ipython.history_manager.output_hist_reprs: + if line not in self.shell.history_manager.output_hist_reprs: raise ValueError(f"There is no output for line: {line}") output_line = line - last_output = ipython.history_manager.output_hist_reprs[output_line] + last_output = self.shell.history_manager.output_hist_reprs[output_line] output = subprocess.run( f'echo "{last_output}" | grep {grep_args}', shell=True,