Beispiel #1
0
    def argv(self):
        """Command to start kernels"""
        # Python interpreter used to start kernels
        if CONF.get('main_interpreter', 'default'):
            pyexec = get_python_executable()
        else:
            # Avoid IPython adding the virtualenv on which Spyder is running
            # to the kernel sys.path
            os.environ.pop('VIRTUAL_ENV', None)
            pyexec = CONF.get('main_interpreter', 'executable')
            if not is_python_interpreter(pyexec):
                pyexec = get_python_executable()
                CONF.set('main_interpreter', 'executable', '')
                CONF.set('main_interpreter', 'default', True)
                CONF.set('main_interpreter', 'custom', False)

        # Fixes Issue #3427
        if os.name == 'nt':
            dir_pyexec = osp.dirname(pyexec)
            pyexec_w = osp.join(dir_pyexec, 'pythonw.exe')
            if osp.isfile(pyexec_w):
                pyexec = pyexec_w

        # Command used to start kernels
        kernel_cmd = [
            pyexec,
            '-m',
            'spyder_kernels.console',
            '-f',
            '{connection_file}'
        ]

        return kernel_cmd
Beispiel #2
0
 def validate_custom_interpreters_list(self):
     """Check that the used custom interpreters are still valid."""
     custom_list = self.get_option('custom_interpreters_list')
     valid_custom_list = []
     for value in custom_list:
         if (osp.isfile(value) and programs.is_python_interpreter(value)
                 and value != get_python_executable()):
             valid_custom_list.append(value)
     self.set_option('custom_interpreters_list', valid_custom_list)
Beispiel #3
0
 def python_executable_changed(self, pyexec):
     """Custom Python executable value has been changed"""
     if not self.cus_exec_radio.isChecked():
         return
     if not is_text_string(pyexec):
         pyexec = to_text_string(pyexec.toUtf8(), 'utf-8')
     if programs.is_python_interpreter(pyexec):
         self.warn_python_compatibility(pyexec)
     else:
         QMessageBox.warning(self, _('Warning'),
                 _("You selected an invalid Python interpreter for the "
                   "console so the previous interpreter will stay. Please "
                   "make sure to select a valid one."), QMessageBox.Ok)
         self.pyexec_edit.setText(get_python_executable())
         return
Beispiel #4
0
def test_is_invalid_interpreter():
    assert not is_python_interpreter(INVALID_INTERPRETER)
Beispiel #5
0
def test_is_valid_interpreter():
    assert is_python_interpreter(VALID_INTERPRETER)
Beispiel #6
0
def test_is_valid_w_interpreter():
    assert is_python_interpreter(VALID_W_INTERPRETER)
Beispiel #7
0
def test_is_invalid_interpreter():
    assert not is_python_interpreter(INVALID_INTERPRETER)
Beispiel #8
0
    def argv(self):
        """Command to start kernels"""
        # Python interpreter used to start kernels
        if spyder.version_info < (5, 1):
            if CONF.get('main_interpreter', 'default'):
                pyexec = get_python_executable()
            else:
                if spyder.version_info < (4, 2):
                    # Avoid IPython adding the virtualenv on which Spyder is running
                    # to the kernel sys.path
                    os.environ.pop('VIRTUAL_ENV', None)
                pyexec = CONF.get('main_interpreter', 'executable')
                if not is_python_interpreter(pyexec):
                    pyexec = get_python_executable()
                    CONF.set('main_interpreter', 'executable', '')
                    CONF.set('main_interpreter', 'default', True)
                    CONF.set('main_interpreter', 'custom', False)
        else:
            if self.get_conf('default', section='main_interpreter'):
                pyexec = get_python_executable()
            else:
                pyexec = self.get_conf('executable',
                                       section='main_interpreter')
                if not is_python_interpreter(pyexec):
                    pyexec = get_python_executable()
                    self.set_conf('executable', '', section='main_interpreter')
                    self.set_conf('default', True, section='main_interpreter')
                    self.set_conf('custom', False, section='main_interpreter')

        if spyder.version_info <= (4, 1, 1):
            # Fixes spyder-ide/spyder#3427.
            if os.name == 'nt':
                dir_pyexec = osp.dirname(pyexec)
                pyexec_w = osp.join(dir_pyexec, 'pythonw.exe')
                if osp.isfile(pyexec_w):
                    pyexec = pyexec_w

        # Command used to start kernels
        if spyder.version_info < (4, 1):  # 4.0.x
            kernel_cmd = [
                pyexec, '-m', 'spymx_kernels.start_kernel', '-f',
                '{connection_file}'
            ]
        else:
            if spyder.version_info == (4, 1, 1):
                is_different = False  # pyexec != sys.executable
            else:
                # Part of spyder-ide/spyder#11819
                is_different = is_different_interpreter(pyexec)

            if is_different and is_conda_env(pyexec=pyexec):
                # If this is a conda environment we need to call an intermediate
                # activation script to correctly activate the spyder-kernel
                # If changes are needed on this section make sure you also update
                # the activation scripts at spyder/plugins/ipythonconsole/scripts/

                if spyder.version_info < (4, 2):
                    conda_activation_script = get_conda_activation_script()
                else:
                    conda_activation_script = get_conda_activation_script(
                        pyexec)

                kernel_cmd = [
                    get_activation_script(),  # This is bundled with Spyder
                    conda_activation_script,
                    get_conda_env_path(pyexec),  # Might be external
                    pyexec,
                    '{connection_file}',
                ]
            else:
                kernel_cmd = [
                    pyexec, '-m', 'spymx_kernels.start_kernel', '-f',
                    '{connection_file}'
                ]
            logger.info('Kernel command: {}'.format(kernel_cmd))

        return kernel_cmd