Exemplo n.º 1
0
    def _create_repl(self):
        cmd = self.executable
        if 'octave-cli' not in cmd:
            version_cmd = [self.executable, '--version']
            version = subprocess.check_output(version_cmd).decode('utf-8')
            if 'version 4' in version:
                cmd += ' --no-gui'
        # Interactive mode prevents crashing on Windows on syntax errors.
        # Delay sourcing the "~/.octaverc" file in case it displays a pager.
        cmd += ' --interactive --quiet --no-init-file '

        # Add cli options provided by the user.
        cmd += os.environ.get('OCTAVE_CLI_OPTIONS', self.cli_options)

        orig_prompt = u('octave.*>')
        change_prompt = u("PS1('{0}'); PS2('{1}')")

        repl = REPLWrapper(cmd, orig_prompt, change_prompt,
                           stdin_prompt_regex=STDIN_PROMPT_REGEX,
                           force_prompt_on_continuation=True)
        if os.name == 'nt':
            repl.child.crlf = '\n'
        repl.interrupt = self._interrupt
        # Remove the default 50ms delay before sending lines.
        repl.child.delaybeforesend = None
        return repl
Exemplo n.º 2
0
    def _create_repl(self):
        cmd = self.executable
        if 'octave-cli' not in cmd:
            version_cmd = [self.executable, '--version']
            version = subprocess.check_output(version_cmd).decode('utf-8')
            if 'version 4' in version:
                cmd += ' --no-gui'
        # Interactive mode prevents crashing on Windows on syntax errors.
        # Delay sourcing the "~/.octaverc" file in case it displays a pager.
        cmd += ' --interactive --quiet --no-init-file '

        # Add cli options provided by the user.
        cmd += os.environ.get('OCTAVE_CLI_OPTIONS', self.cli_options)

        orig_prompt = u('octave.*>')
        change_prompt = u("PS1('{0}'); PS2('{1}')")

        repl = REPLWrapper(cmd,
                           orig_prompt,
                           change_prompt,
                           stdin_prompt_regex=STDIN_PROMPT_REGEX,
                           force_prompt_on_continuation=True)
        if os.name == 'nt':
            repl.child.crlf = '\n'
        repl.interrupt = self._interrupt
        # Remove the default 50ms delay before sending lines.
        repl.child.delaybeforesend = None
        return repl
Exemplo n.º 3
0
    def _create_repl(self):
        cmd = self.executable
        # Interactive mode prevents crashing on Windows on syntax errors.
        # Delay sourcing the "~/.octaverc" file in case it displays a pager.

        repl = REPLWrapper(cmd_or_spawn=cmd,
                           prompt_regex=r'[>+] $',
                           prompt_change_cmd=None)

        if os.name == 'nt':
            repl.child.crlf = '\n'
        repl.interrupt = self._interrupt
        # Remove the default 50ms delay before sending lines.
        repl.child.delaybeforesend = None
        return repl
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
0
 def _interrupt(self, silent=False):
     if (os.name == 'nt'):
         msg = '** Warning: Cannot interrupt Octave on Windows'
         if self.stream_handler:
             self.stream_handler(msg)
         elif self.logger:
             self.logger.warn(msg)
         return self._interrupt_expect(silent)
     return REPLWrapper.interrupt(self.repl)
Exemplo n.º 7
0
    def _interrupt(self, continuation=False, silent=False):
        if os.name == 'nt':
            msg = '** Warning: Cannot interrupt Octave on Windows'
            if self.stream_handler:
                self.stream_handler(msg)
            elif self.logger:
                self.logger.warn(msg)
            return self._interrupt_expect(silent)

        return REPLWrapper.interrupt(self.repl, continuation=continuation)
Exemplo n.º 8
0
    def makeWrapper(self):
        """Start an PsySH process and return a :class:`REPLWrapper` object.
        """

        executable = self.executable

        wrapper = REPLWrapper(executable,
                              u('>>>'),
                              None,
                              continuation_prompt_regex=u('\.\.\.'),
                              echo=True)
        wrapper.child.linesep = '\n'
        return wrapper
Exemplo n.º 9
0
 def makeWrapper(self):
     """Start a Scilab process and return a :class:`REPLWrapper` object.
     """
     orig_prompt = '-->'
     prompt_cmd = None
     change_prompt = None
     continuation_prompt = '  >'
     self._first = True
     if os.name == 'nt':
         prompt_cmd = 'printf("-->")'
         echo = False
     else:
         echo = True
     executable = self.executable + ' -nw'
     wrapper = REPLWrapper(executable, orig_prompt, change_prompt,
         prompt_emit_cmd=prompt_cmd, echo=echo,
         continuation_prompt_regex=continuation_prompt)
     wrapper.child.linesep = '\r\n' if os.name == 'nt' else '\n'
     return wrapper
Exemplo n.º 10
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
Exemplo n.º 11
0
    def makeWrapper(self):
        """Start a Scilab process and return a :class:`REPLWrapper` object.
        """
        if os.name == 'nt':
            orig_prompt = u(chr(3))
            prompt_cmd = u('disp(char(3))')
            change_prompt = None
        else:
            orig_prompt = u('-->')
            prompt_cmd = None
            change_prompt = None

        self._first = True

        executable = self.executable + ' -nw'
        wrapper = REPLWrapper(executable,
                              orig_prompt,
                              change_prompt,
                              prompt_emit_cmd=prompt_cmd)
        wrapper.child.linesep = '\n'
        return wrapper
Exemplo n.º 12
0
    def makeWrapper(self):
        """Start an Octave process and return a :class:`REPLWrapper` object.
        """
        if os.name == 'nt':
            orig_prompt = u(chr(3))
            prompt_cmd = u('disp(char(3))')
            change_prompt = None
        else:
            orig_prompt = u('octave.*>')
            prompt_cmd = None
            change_prompt = u("PS1('{0}'); PS2('{1}')")

        self._first = True

        executable = self.executable
        if 'version 4' in self.banner:
            executable += ' --no-gui'

        wrapper = REPLWrapper(executable, orig_prompt, change_prompt,
                prompt_emit_cmd=prompt_cmd)
        wrapper.child.linesep = '\n'
        return wrapper
Exemplo n.º 13
0
 def makeWrapper(self):
     """Start a Scilab process and return a :class:`REPLWrapper` object.
     """
     orig_prompt = '-->'
     prompt_cmd = None
     change_prompt = None
     continuation_prompt = '  >'
     self._first = True
     if os.name == 'nt':
         prompt_cmd = 'printf("-->")'
         echo = False
     else:
         echo = True
     executable = self.executable
     with open(os.path.expanduser('~/test.log'), 'w') as fid:
         fid.write('executable: ' + executable)
     wrapper = REPLWrapper(executable,
                           orig_prompt,
                           change_prompt,
                           prompt_emit_cmd=prompt_cmd,
                           echo=echo,
                           continuation_prompt_regex=continuation_prompt)
     wrapper.child.linesep = '\r\n' if os.name == 'nt' else '\n'
     return wrapper
Exemplo n.º 14
0
# works with ``#define RB_XCODE``, i.e. no linenoise
# cmd = '/usr/local/bin/rb'

# possibly broken with the vanilla cmake version
#cmd = '/usr/local/bin/revbayes'

# problem appears to be fixed when building with cmake with `-DRB_XCODE`
# use ./build.sh -jupyter true to build the rb-jupyter binary
cmd = '/usr/local/bin/rb-jupyter'

#prompt_regex = r'[(x1b\[0K\\r\\x1b\[2C)>+] '
prompt_regex = r'[>+] '

x = REPLWrapper(cmd_or_spawn=cmd,
                prompt_regex=prompt_regex,
                prompt_change_cmd=None,
                echo=True)

# RevBayes uses u'\n\r' as CRLF
# x.child.crlf = '\n'

#x.run_command('val <- [1,')
#x.run_command('2]')
#x.run_command('for (i in 1:10) {'

#x.run_command('val')

#print(x.run_command('for (i in 1:10) z[i] ~ dnNormal(0,1)'))
#print(x.run_command('z'))

print(x.run_command('for (i in 1:10) {'))