File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ from IPython .core .magic import Magics , magics_class , line_cell_magic
2+ from . import Main , Base , PythonCall
3+
4+ @magics_class
5+ class JuliaMagics (Magics ):
6+
7+ @line_cell_magic
8+ def julia (self , line , cell = None ):
9+ code = line if cell is None else cell
10+ ans = Main .seval ('begin\n ' + code + '\n end' )
11+ Base .flush (Base .stdout )
12+ Base .flush (Base .stderr )
13+ if not code .strip ().endswith (';' ):
14+ return ans
15+
16+ def load_ipython_extension (ip ):
17+ # register magics
18+ ip .register_magics (JuliaMagics (ip ))
19+ # redirect stdout/stderr
20+ PythonCall .seval ("""begin
21+ const _redirected_stdout = redirect_stdout()
22+ const _redirected_stderr = redirect_stderr()
23+ const _py_stdout = PyIO(pyimport("sys" => "stdout"), buflen=1)
24+ const _py_stderr = PyIO(pyimport("sys" => "stderr"), buflen=1)
25+ const _redirect_stdout_task = @async write($_py_stdout, $_redirected_stdout)
26+ const _redirect_stderr_task = @async write($_py_stderr, $_redirected_stderr)
27+ end""" )
You can’t perform that action at this time.
0 commit comments