def get_input(self, more=False): """Prompts for code input.""" try: return self.prompt.input(more) except KeyboardInterrupt: printerr("\nKeyboardInterrupt") except EOFError: print() self.exit_runner() return None
def mypy_run(args): """Runs mypy with given arguments and shows the result.""" try: stdout, stderr, exit_code = run(args) except BaseException: printerr(traceback.format_exc()) else: for line in stdout.splitlines(): yield line, False for line in stderr.splitlines(): yield line, True
def start_prompt(self): """Start the interpreter.""" logger.show("Coconut Interpreter:") logger.show("(type 'exit()' or press Ctrl-D to end)") self.start_running() while self.running: try: code = self.get_input() if code: compiled = self.handle_input(code) if compiled: self.execute(compiled, use_eval=None) except KeyboardInterrupt: printerr("\nKeyboardInterrupt")
def handling_exceptions(self): """Perform proper exception handling.""" try: with handling_broken_process_pool(): yield except SystemExit as err: self.register_error(err.code) except BaseException as err: if isinstance(err, CoconutException): logger.display_exc() elif not isinstance(err, KeyboardInterrupt): traceback.print_exc() printerr(report_this_text) self.register_error(errmsg=err.__class__.__name__)
def run_mypy(self, paths=(), code=None): """Run MyPy with arguments.""" if self.mypy: set_mypy_path(stub_dir) from coconut.command.mypy import mypy_run args = list(paths) + self.mypy_args if code is not None: args += ["-c", code] for line, is_err in mypy_run(args): if code is None or line not in self.mypy_errs: printerr(line) if line not in self.mypy_errs: self.mypy_errs.append(line) self.register_error(errmsg="MyPy error")
def get_input(self, more=False): """Prompts for code input.""" received = None try: received = self.prompt.input(more) except KeyboardInterrupt: printerr("\nKeyboardInterrupt") except EOFError: print() self.exit_runner() else: if received.startswith(exit_chars): self.exit_runner() received = None return received
def run_mypy(self, paths=[], code=None): """Run MyPy with arguments.""" set_mypy_path(stub_dir) if self.mypy: from coconut.command.mypy import mypy_run args = paths + self.mypy_args if code is not None: args += ["-c", code] for line, is_err in mypy_run(args): if code is None or line not in self.mypy_errs: if is_err: printerr(line) else: print(line) if line not in self.mypy_errs: self.mypy_errs.append(line)
def get_input(self, more=False): """Prompt for code input.""" received = None try: received = self.prompt.input(more) except KeyboardInterrupt: print() printerr("KeyboardInterrupt") except EOFError: print() self.exit_runner() else: if received.startswith(exit_chars): self.exit_runner() received = None return received
def handling_exceptions(self): """Perform proper exception handling.""" try: if self.using_jobs: with handling_broken_process_pool(): yield else: yield except SystemExit as err: self.register_error(err.code) except BaseException as err: if isinstance(err, CoconutException): logger.display_exc() elif not isinstance(err, KeyboardInterrupt): traceback.print_exc() printerr(report_this_text) self.register_error(errmsg=err.__class__.__name__)