Exemple #1
0
    def makeWrapper(self):
        """
        Start a math/mathics kernel and return a :class:`REPLWrapper` object.
        """
        self.js_libraries_loaded = False
        orig_prompt = u("In\[.*\]:=")
        prompt_cmd = None
        change_prompt = None
        self.check_wolfram()

        if self.kernel_type in ["wolfram"]:
            print("Wolfram Kernel or compabible found")
            self.process_response = self.process_response_wolfram
            self.open_envel = 'ToExpression["Identity['
            self.close_envel = ']"]'
            cmdline = (
                self.language_info["exec"]
                + " -rawterm -initfile '"
                + self.initfilename
                + "'"
            )

        if self.kernel_type in ["expreduce"]:
            print("Expreduce found")
            self.open_envel = ""
            self.close_envel = ""
            self.process_response = self.process_response_wolfram
            self.do_execute_direct = self.do_execute_direct_expred
            self.do_execute_direct_single_command = (
                self.do_execute_direct_single_command_expred
            )
            cmdline = (
                self.language_info["exec"]
                + " -rawterm -initfile '"
                + self.initfilename
                + "'"
            )

        elif self.kernel_type in ["mathics"]:
            print("Mathics found")
            self.process_response = self.process_response_mathics
            self.open_envel = 'ToExpression["Identity['
            self.close_envel = ']"]'
            cmdline = (
                self.language_info["exec"]
                + " --colors NOCOLOR --no-readline --persist '"
                + self.initfilename
                + "'"
            )

        self.myspawner = spawnu(cmdline, errors="ignore", echo=False)
        replwrapper = REPLWrapper(
            self.myspawner,
            orig_prompt,
            change_prompt,
            continuation_prompt_regex="Interrupt>",
            prompt_emit_cmd=None,
            echo=False,
        )
        return replwrapper
Exemple #2
0
    def makeWrapper(self):
        """
        Start a math/mathics kernel and return a :class:`REPLWrapper` object.
        """
        self.js_libraries_loaded = False
        # Maybe we can consider as prompt P:, M: and
        # Out[]:= to catch all signals in real time
        orig_prompt = u('In\[.*\]:=')
        prompt_cmd = None
        change_prompt = None
        self.check_wolfram()

        if self.kernel_type == "mathics":
            cmdline = self.language_info[
                'exec'] + " --colors NOCOLOR --persist '" + self.initfilename + "'"
        else:
            cmdline = self.language_info[
                'exec'] + " -rawterm -initfile '" + self.initfilename + "'"
        # self.log.warning("Building the process wrapper...")
        myspawner = spawnu(cmdline, errors="ignore", echo=False)
        replwrapper = REPLWrapper(myspawner,
                                  orig_prompt,
                                  change_prompt,
                                  prompt_emit_cmd=None,
                                  echo=False)
        #self.log.warning("                                ... done")
        return replwrapper
Exemple #3
0
    def test_existing_spawn(self):
        child = pexpect.spawnu("bash", timeout=5, echo=False)
        repl = replwrap.REPLWrapper(child, re.compile('[$#]'),
                                    "PS1='{0}' PS2='{1}' "
                                    "PROMPT_COMMAND=''")

        res = repl.run_command("echo $HOME")
        assert res.startswith('/'), res
Exemple #4
0
    def test_existing_spawn(self):
        child = pexpect.spawnu("bash", timeout=5, echo=False)
        repl = replwrap.REPLWrapper(child, re.compile('[$#]'),
                                    "PS1='{0}' PS2='{1}' "
                                    "PROMPT_COMMAND=''")

        res = repl.run_command("echo $HOME")
        assert res.startswith('/'), res
Exemple #5
0
    def test_no_change_prompt(self):
        if platform.python_implementation() == 'PyPy':
            raise unittest.SkipTest("This test fails on PyPy because of REPL differences")

        child = pexpect.spawnu('python', echo=False, timeout=5)
        # prompt_change=None should mean no prompt change
        py = replwrap.REPLWrapper(child, replwrap.u(">>> "), prompt_change_cmd=None, continuation_prompt_regex=replwrap.u(re.escape("... ")))
        assert py.prompt_regex == ">>> "

        res = py.run_command("for a in range(3): print(a)\n")
        assert res.strip().splitlines() == ['0', '1', '2']
Exemple #6
0
    def test_no_change_prompt(self):
        if platform.python_implementation() == 'PyPy':
            raise unittest.SkipTest(
                "This test fails on PyPy because of REPL differences")

        child = pexpect.spawnu('python', echo=False, timeout=5)
        # prompt_change=None should mean no prompt change
        py = replwrap.REPLWrapper(child,
                                  replwrap.u(">>> "),
                                  prompt_change_cmd=None,
                                  continuation_prompt_regex=replwrap.u(
                                      re.escape("... ")))
        assert py.prompt_regex == ">>> "

        res = py.run_command("for a in range(3): print(a)\n")
        assert res.strip().splitlines() == ['0', '1', '2']
Exemple #7
0
    def makeWrapper(self):
        """
        Start a math/mathics kernel and return a :class:`REPLWrapper` object.
        """
        self.js_libraries_loaded = False
        orig_prompt = u('In\[.*\]:=')
        prompt_cmd = None
        change_prompt = None
        self.check_wolfram()

        if self.kernel_type in ["wolfram"]:
            self.process_response = self.process_response_wolfram
            self.open_envel = "ToExpression[\"Identity["
            self.close_envel = "]\"]"
            cmdline = self.language_info['exec'] + " -rawterm -initfile '" + \
                      self.initfilename + "'"

        if self.kernel_type in ["expreduce"]:
            self.process_response = self.process_response_wolfram
            self.do_execute_direct = self.do_execute_direct_expred
            self.do_execute_direct_single_command = \
                                self.do_execute_direct_single_command_expred
            cmdline = self.language_info['exec'] + \
                      " -rawterm -initfile '" + self.initfilename + "'"

        elif self.kernel_type in ["mathics"]:
            self.process_response = self.process_response_mathics
            self.open_envel = "$PrePrint[ToExpression[\"Identity["
            self.close_envel = "]\"]]"
            cmdline = self.language_info['exec'] + \
                      " --colors NOCOLOR --persist '" + \
                      self.initfilename + "'"

        self.myspawner = spawnu(cmdline, errors="ignore", echo=False)
        replwrapper = REPLWrapper(self.myspawner,
                                  orig_prompt,
                                  change_prompt,
                                  continuation_prompt_regex="Interrupt>",
                                  prompt_emit_cmd=None,
                                  echo=False)
        return replwrapper