Improve %ilaw ipython magic.
@@ -13,7 +13,7 @@ import logging
import six
import law.cli
-from law.util import law_run, quote_cmd, patch_object
+from law.util import law_run, quote_cmd
from law.logger import get_logger
@@ -22,7 +22,6 @@ logger = get_logger(__name__)
def create_magics(init_cmd=None, init_fn=None, line_cmd=None, line_fn=None, log_level=None):
import IPython.core as ipc
- from luigi.cmdline_parser import CmdlineParser
# prepare commands
if init_cmd:
@@ -71,7 +70,7 @@ def create_magics(init_cmd=None, init_fn=None, line_cmd=None, line_fn=None, log_
logger.debug("running law command '{}'".format(cmd))
# run it
- self._run_bash(cmd)
+ return self._run_bash(cmd)
@ipc.magic.line_magic
def ilaw(self, line):
@@ -101,19 +100,11 @@ def create_magics(init_cmd=None, init_fn=None, line_cmd=None, line_fn=None, log_
line_fn(line)
if prog == "run":
- # perform run calls interactively, with a patch to the ArgumentParser to replace
- # the ipython default (usually "ipykernel_launcher.py") with "law"
- _build_parser_orig = CmdlineParser._build_parser
- def _build_parser(*args, **kwargs):
- parser = _build_parser_orig(*args, **kwargs)
- parser.prog = "law"
- return parser
-
- with patch_object(CmdlineParser, "_build_parser", staticmethod(_build_parser)):
- law_run(argv)
+ # perform the run call interactively
+ return law_run(argv)
else:
# forward all other progs to the cli interface
- law.cli.cli.run([prog] + argv)
+ return law.cli.cli.run([prog] + argv)
except SystemExit as e:
# reraise when the exit code is non-zero
if e.code:
@@ -126,7 +117,7 @@ def create_magics(init_cmd=None, init_fn=None, line_cmd=None, line_fn=None, log_
cmd = quote_cmd(["bash", "-c", cmd])
# run it
- self.shell.system_piped(cmd)
+ return self.shell.system_piped(cmd)
return LawMagics
