mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[Magic CLI] error starting magic shell as notebook cell script (%%mojo)

Open comods opened this issue 5 months ago • 2 comments

Issue description

Using ipython magic-action %%script to call modular's magic shell gives an error (see steps to reproduce).

Steps to reproduce

Using ipython magic-action %%script to call modular's magic shell, while offline, running a no-op comment line of #, I get the following error:

Error starting shell: Not a tty (os error 25)

---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
Cell In[2], line 1
----> 1 get_ipython().run_cell_magic('mojo', '', '#\n')

File /opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2517, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)
   2515 with self.builtin_trap:
   2516     args = (magic_arg_s, cell)
-> 2517     result = fn(*args, **kwargs)
   2519 # The code below prevents the output from being displayed
   2520 # when using magics with decorator @output_can_be_silenced
   2521 # when the last Python token in the expression is a ';'.
   2522 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File /opt/conda/lib/python3.10/site-packages/IPython/core/magic.py:755, in MagicAlias.__call__(self, *args, **kwargs)
    753         args_list[0] = self.magic_params + " " + args[0]
    754         args = tuple(args_list)
--> 755     return fn(*args, **kwargs)
    756 finally:
    757     self._in_call = False

File /opt/conda/lib/python3.10/site-packages/IPython/core/magics/script.py:314, in ScriptMagics.shebang(self, line, cell)
    309 if args.raise_error and p.returncode != 0:
    310     # If we get here and p.returncode is still None, we must have
    311     # killed it but not yet seen its return code. We don't wait for it,
    312     # in case it's stuck in uninterruptible sleep. -9 = SIGKILL
    313     rc = p.returncode or -9
--> 314     raise CalledProcessError(rc, cell)

CalledProcessError: Command 'b'#\n'' returned non-zero exit status 1.

The following works just fine: %%bash, %%python, %%script bash, %%script python.

Reproducible in notebook: https://www.kaggle.com/code/michaeldgibson/offline-mojo-template/notebook?scriptVersionId=194491514

After calling %alias_magic --cell mojo script -p 'magic shell', new notebook cells can start with %%mojo which should compile the cell for mojo once these errors are able to be fixed.

Version Info

magic --version
# magic 0.2.2

comods avatar Aug 29 '24 05:08 comods