예제 #1
0
파일: status.py 프로젝트: olexster/spyder
    def _process_interpreter_env_info(self):
        """Process conda environment information."""
        out, err = self._get_interpreter_env_info()
        out = out or err  # Anaconda base python prints to stderr
        out = out.split('\n')[0]
        parts = out.split()

        if len(parts) >= 2:
            out = ' '.join(parts[:2])

        if is_conda_env(pyexec=self._interpreter):
            envs_folder = os.path.sep + 'envs' + os.path.sep
            if envs_folder in self._interpreter:
                if os.name == 'nt':
                    env = os.path.dirname(self._interpreter)
                else:
                    env = os.path.dirname(os.path.dirname(self._interpreter))
                env = os.path.basename(env)
            else:
                env = 'base'
            env = 'conda: ' + env
        elif running_in_mac_app(self._interpreter):
            env = 'internal'
        else:
            env = 'venv'  # Update when additional environments are supported

        text = '{env} ({version})'.format(env=env, version=out)
        return text
예제 #2
0
def get_versions(reporev=True):
    """Get version information for components used by Spyder"""
    import sys
    import platform

    import qtpy
    import qtpy.QtCore

    from spyder.utils.conda import is_conda_env
    from spyder.config.base import is_pynsist, running_in_mac_app

    revision = branch = None
    if reporev:
        if running_in_mac_app():
            revision = os.environ.get('SPY_COMMIT', None)
            branch = os.environ.get('SPY_BRANCH', None)
        else:
            from spyder.utils import vcs
            revision, branch = vcs.get_git_revision(
                os.path.dirname(__current_directory__))

    if is_pynsist() or running_in_mac_app():
        installer = 'standalone'
    elif is_conda_env(pyexec=sys.executable):
        installer = 'conda'
    else:
        installer = 'pip'

    return {
        'spyder':
        __version__,
        'installer':
        installer,
        'python':
        platform.python_version(),  # "2.7.3"
        'bitness':
        64 if sys.maxsize > 2**32 else 32,
        'qt':
        qtpy.QtCore.__version__,
        'qt_api':
        qtpy.API_NAME,  # PyQt5
        'qt_api_ver':
        (qtpy.PYSIDE_VERSION if qtpy.API == "pyside2" else qtpy.PYQT_VERSION),
        'system':
        platform.system(),  # Linux, Windows, ...
        'release':
        platform.release(),  # XP, 10.6, 2.2.0, etc.
        'revision':
        revision,  # '9fdf926eccce',
        'branch':
        branch,  # '4.x' or master
    }
예제 #3
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)

        # Part of spyder-ide/spyder#11819
        is_different = is_different_interpreter(pyexec)

        # 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 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/
            kernel_cmd = [
                get_activation_script(),  # This is bundled with Spyder
                get_conda_activation_script(),
                get_conda_env_path(pyexec),  # Might be external
                pyexec,
                '{connection_file}',
            ]
        else:
            kernel_cmd = [
                pyexec, '-m', 'spyder_kernels.console', '-f',
                '{connection_file}'
            ]
        logger.info('Kernel command: {}'.format(kernel_cmd))

        return kernel_cmd
예제 #4
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:
            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)

        # Part of spyder-ide/spyder#11819
        is_different = is_different_interpreter(pyexec)

        # Command used to start kernels
        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/
            kernel_cmd = [
                get_activation_script(),  # This is bundled with Spyder
                get_conda_activation_script(pyexec),
                get_conda_env_path(pyexec),  # Might be external
                pyexec,
                '{connection_file}',
            ]
        else:
            kernel_cmd = [
                pyexec,
                '-m',
                'spyder_kernels.console',
                '-f',
                '{connection_file}'
            ]
        logger.info('Kernel command: {}'.format(kernel_cmd))

        return kernel_cmd
예제 #5
0
def is_python_interpreter(filename):
    """Evaluate whether a file is a python interpreter or not."""
    # Must be imported here to avoid circular import
    from spyder.utils.conda import is_conda_env

    real_filename = os.path.realpath(filename)  # To follow symlink if existent

    if (not osp.isfile(real_filename)
            or not is_python_interpreter_valid_name(real_filename)):
        return False

    # File exists and has valid name
    is_text_file = encoding.is_text_file(real_filename)

    if is_pythonw(real_filename):
        if os.name == 'nt':
            # pythonw is a binary on Windows
            if not is_text_file:
                return True
            else:
                return False
        elif sys.platform == 'darwin':
            # pythonw is a text file in Anaconda but a binary in
            # the system
            if is_conda_env(pyexec=real_filename) and is_text_file:
                return True
            elif not is_text_file:
                return True
            else:
                return False
        else:
            # There's no pythonw in other systems
            return False
    elif is_text_file:
        # At this point we can't have a text file
        return False
    else:
        return check_python_help(real_filename)
예제 #6
0
    def render_issue(cls, description='', traceback='', include_env=False):
        """
        Render issue content.

        Parameters
        ----------
        description: str
            Description to include in issue message.
        traceback: str
            Traceback text.
        include_env: bool (False)
            Whether to include the IPython console environment.
        """
        # Get dependencies if they haven't beed computed yet.
        if not dependencies.DEPENDENCIES:
            try:
                dependencies.declare_dependencies()
            except ValueError:
                pass

        # Make a description header in case no description is supplied
        if not description:
            description = "### What steps reproduce the problem?"

        # Make error section from traceback and add appropriate reminder header
        if traceback:
            error_section = ("### Traceback\n"
                             "```python-traceback\n"
                             "{}\n"
                             "```".format(traceback))
        else:
            error_section = ''

        versions_text = get_versions_text()

        issue_template = f"""\
## Description

{description}

{error_section}

## Versions

{versions_text}
### Dependencies

```
{dependencies.status()}
```
"""

        # Report environment if selected
        if include_env:
            pyexe = cls.get_conf(cls, 'executable', section='main_interpreter')

            if is_conda_env(pyexec=pyexe):
                path = get_conda_env_path(pyexe)
                exe = find_conda()
                args = ['list', '--prefix', path]
            else:
                exe = pyexe
                args = ['-m', 'pip', 'list']

            proc = run_program(exe, args=args)
            ext_env, stderr = proc.communicate()
            issue_template += f"""
### Environment

<details><summary>Environment</summary>

```
{ext_env.decode()}
```
</details>
"""

        return issue_template