Пример #1
0
 def start_runner(self, path=None, isolate=False):
     """Starts the runner."""
     sys.path.insert(0, os.getcwd())
     if isolate:
         comp = None
     else:
         comp = self.comp
     self.runner = Runner(comp, self.exit_runner, path)
Пример #2
0
 def check_runner(self):
     """Make sure there is a runner."""
     if os.getcwd() not in sys.path:
         sys.path.append(os.getcwd())
     if self.runner is None:
         self.runner = Runner(self.comp,
                              exit=self.exit_runner,
                              store=self.mypy)
Пример #3
0
    def check_runner(self, set_sys_vars=True, argv_source_path=""):
        """Make sure there is a runner."""
        if set_sys_vars:
            # set sys.path
            if os.getcwd() not in sys.path:
                sys.path.append(os.getcwd())

            # set sys.argv
            if self.argv_args is not None:
                sys.argv = [argv_source_path] + self.argv_args

        # set up runner
        if self.runner is None:
            self.runner = Runner(self.comp, exit=self.exit_runner, store=self.mypy)
Пример #4
0
            extra="run 'pip install coconut[jupyter]' to fix",
        )
else:
    LOAD_MODULE = True

# -----------------------------------------------------------------------------------------------------------------------
# GLOBALS:
# -----------------------------------------------------------------------------------------------------------------------

COMPILER = Compiler(
    target="sys",
    line_numbers=True,
    keep_lines=True,
)

RUNNER = Runner(COMPILER)

parse_block_memo = {}


def memoized_parse_block(code):
    """Memoized version of parse_block."""
    internal_assert(lambda: code not in parse_block_memo.values(),
                    "attempted recompilation of", code)
    success, result = parse_block_memo.get(code, (None, None))
    if success is None:
        try:
            parsed = COMPILER.parse_block(code)
        except Exception as err:
            success, result = False, err
        else: