示例#1
0
def load_ipython_extension(ipython: InteractiveShell) -> None:
    """
    Called when IPython load this extension.

    :param ipython:  The current IPython-console instance.
    """
    yuuno = Yuuno.instance(parent=ipython)
    yuuno.environment = YuunoIPythonEnvironment(parent=yuuno, ipython=ipython)
    yuuno.start()
    def is_supported(cls):
        try:
            import IPython
        except ImportError:
            return False

        from yuuno_ipython.ipython.environment import YuunoIPythonEnvironment
        if not isinstance(Yuuno.instance().environment, YuunoIPythonEnvironment):
            return False

        from yuuno.vs.extension import VapourSynth
        return VapourSynth.is_supported()
def execute_code(expr, file, fail_on_error=True, ns=None):
    ipy = Yuuno.instance().environment.ipython
    expr = ipy.input_transformer_manager.transform_cell(expr)
    expr_ast = ipy.compile.ast_parse(expr)
    expr_ast = ipy.transform_ast(expr_ast)


    if len(expr_ast.body) == 0:
        # There is no code to execute.
        # Take the fast path and skip executing.
        return None

    elif isinstance(expr_ast.body[-1], ast.Expr):
        last_expr = expr_ast.body[-1]
        assign = ast.Assign(                                # _yuuno_exec_last_ = <LAST_EXPR>
            targets=[ast.Name(
                id=RESULT_VAR,
                ctx=ast.Store()
            )],
            value=last_expr.value
        )
        expr_ast.body[-1] = assign
    else:
        assign = ast.Assign(                                # _yuuno_exec_last_ = None
            targets=[ast.Name(
                id=RESULT_VAR,
                ctx=ast.Store(),
            )],
            value=ast.NameConstant(
                value=None
            )
        )
        expr_ast.body.append(assign)
    ast.fix_missing_locations(expr_ast)

    code = compile_with_cache(ipy, expr, expr_ast, file, "exec")

    if ns is None:
        ns = ipy.user_ns

    try:
        exec(code, ipy.user_ns, ns)
        result = ipy.user_ns.get(RESULT_VAR, None)
    finally:
        ns.pop(RESULT_VAR, None)
    return result
示例#4
0
def _load_jupyter_server_extension(server_app):
    """Registers the API handler to receive HTTP requests from the frontend extension.

    Parameters
    ----------
    server_app: jupyterlab.labapp.LabApp
        JupyterLab application instance
    """
    from yuuno.yuuno import Yuuno
    from yuuno_jupyterlab.environment import YuunoJupyterLabEnvironment

    yuuno = Yuuno.instance(parent=server_app)
    yuuno.environment = YuunoJupyterLabEnvironment(parent=yuuno,
                                                   server=server_app)
    yuuno.start()

    setup_handlers(server_app.web_app)
    server_app.log.info(
        "Registered YuunoLab extension at URL path /yuuno-jupyterlab")
示例#5
0
def init_standalone(*, additional_extensions=()) -> Yuuno:
    y = Yuuno.instance(parent=None)
    y.environment = StandaloneEnvironment()
    y.environment.additional_extensions = lambda: list(additional_extensions)
    y.start()
    return y
 def _default_yuuno(self):
     return Yuuno.instance()
示例#7
0
def unload_ipython_extension(ipython) -> None:
    """
    Called when IPython unloads the extension.
    """
    yuuno = Yuuno.instance()
    yuuno.stop()