示例#1
0
def is_python_interpreter(filename):
    """Evaluate wether a file is a python interpreter or not."""
    real_filename = os.path.realpath(filename)  # To follow symlink if existent
    if (not osp.isfile(real_filename) or 
        not is_python_interpreter_valid_name(filename)):
        return False
    elif is_pythonw(filename):
        if os.name == 'nt':
            # pythonw is a binary on Windows
            if not encoding.is_text_file(real_filename):
                return True
            else:
                return False
        elif sys.platform == 'darwin':
            # pythonw is a text file in Anaconda but a binary in
            # the system
            if is_anaconda() and encoding.is_text_file(real_filename):
                return True
            elif not encoding.is_text_file(real_filename):
                return True
            else:
                return False
        else:
            # There's no pythonw in other systems
            return False
    elif encoding.is_text_file(real_filename):
        # At this point we can't have a text file
        return False
    else:
        return check_python_help(filename)
示例#2
0
    def start(self):
        """Main method of the WorkerUpdates worker"""
        if is_anaconda():
            self.url = 'https://repo.anaconda.com/pkgs/main'
            if os.name == 'nt':
                self.url += '/win-64/repodata.json'
            elif sys.platform == 'darwin':
                self.url += '/osx-64/repodata.json'
            else:
                self.url += '/linux-64/repodata.json'
        else:
            self.url = ('https://api.github.com/repos/'
                        'spyder-ide/spyder/releases')
        self.update_available = False
        self.latest_release = __version__

        error_msg = None

        try:
            if hasattr(ssl, '_create_unverified_context'):
                # Fix for issue # 2685 [Works only with Python >=2.7.9]
                # More info: https://www.python.org/dev/peps/pep-0476/#opting-out
                context = ssl._create_unverified_context()
                page = urlopen(self.url, context=context)
            else:
                page = urlopen(self.url)
            try:
                data = page.read()

                # Needed step for python3 compatibility
                if not is_text_string(data):
                    data = data.decode()
                data = json.loads(data)

                if is_anaconda():
                    if self.releases is None:
                        self.releases = []
                        for item in data['packages']:
                            if ('spyder' in item and
                                    not re.search(r'spyder-[a-zA-Z]', item)):
                                self.releases.append(item.split('-')[1])
                    result = self.check_update_available()
                else:
                    if self.releases is None:
                        self.releases = [item['tag_name'].replace('v', '')
                                         for item in data]
                        self.releases = list(reversed(self.releases))

                result = self.check_update_available()
                self.update_available, self.latest_release = result
            except Exception:
                error_msg = _('Unable to retrieve information.')
        except HTTPError:
            error_msg = _('Unable to retrieve information.')
        except URLError:
            error_msg = _('Unable to connect to the internet. <br><br>Make '
                          'sure the connection is working properly.')
        except Exception:
            error_msg = _('Unable to check for updates.')

        # Don't show dialog when starting up spyder and an error occur
        if not (self.startup and error_msg is not None):
            self.error = error_msg
            self.sig_ready.emit()
示例#3
0
}, {
    'modname': "qtconsole",
    'package_name': "qtconsole",
    'features': _("Main package for the IPython console"),
    'required_version': QTCONSOLE_REQVER
}, {
    'modname': "qtpy",
    'package_name': "qtpy",
    'features': _("Abstraction layer for Python Qt bindings."),
    'required_version': QTPY_REQVER
}, {
    'modname': "rtree",
    'package_name': "rtree",
    'features': _("Fast access to code snippets regions"),
    'required_version': RTREE_REQVER,
    'display': is_anaconda()
}, {
    'modname':
    "sphinx",
    'package_name':
    "sphinx",
    'features':
    _("Show help for objects in the Editor and Consoles in a dedicated pane"),
    'required_version':
    SPHINX_REQVER
}, {
    'modname': "spyder_kernels",
    'package_name': "spyder-kernels",
    'features': _("Jupyter kernels for the Spyder console"),
    'required_version': SPYDER_KERNELS_REQVER
}, {
示例#4
0
    _("Icon theme based on FontAwesome and Material Design icons"),
    'required_version':
    QTAWESOME_REQVER
}, {
    'modname': "qtconsole",
    'package_name': "qtconsole",
    'features': _("Main package for the IPython console"),
    'required_version': QTCONSOLE_REQVER
}, {
    'modname': "qtpy",
    'package_name': "qtpy",
    'features': _("Abstraction layer for Python Qt bindings."),
    'required_version': QTPY_REQVER
}]

if is_anaconda():
    DESCRIPTIONS.append({
        'modname': "rtree",
        'package_name': "rtree",
        'features': _("Fast access to code snippets regions"),
        'required_version': RTREE_REQVER
    })

DESCRIPTIONS += [{
    'modname':
    "sphinx",
    'package_name':
    "sphinx",
    'features':
    _("Show help for objects in the Editor and Consoles in a dedicated pane"),
    'required_version':
示例#5
0
    def _check_updates_ready(self):
        """Show results of the Spyder update checking process."""

        # `feedback` = False is used on startup, so only positive feedback is
        # given. `feedback` = True is used when after startup (when using the
        # menu action, and gives feeback if updates are, or are not found.
        feedback = self.give_updates_feedback

        # Get results from worker
        update_available = self.worker_updates.update_available
        latest_release = self.worker_updates.latest_release
        error_msg = self.worker_updates.error

        # Release url
        url_r = __project_url__ + '/releases/tag/v{}'.format(latest_release)
        url_i = 'https://docs.spyder-ide.org/installation.html'

        # Define the custom QMessageBox
        box = MessageCheckBox(icon=QMessageBox.Information,
                              parent=self)
        box.setWindowTitle(_("New Spyder version"))
        box.set_checkbox_text(_("Check for updates at startup"))
        box.setStandardButtons(QMessageBox.Ok)
        box.setDefaultButton(QMessageBox.Ok)

        # Adjust the checkbox depending on the stored configuration
        option = 'check_updates_on_startup'
        check_updates = self.get_conf(option)
        box.set_checked(check_updates)

        if error_msg is not None:
            msg = error_msg
            box.setText(msg)
            box.set_check_visible(False)
            box.exec_()
            check_updates = box.is_checked()
        else:
            if update_available:
                header = _("<b>Spyder {} is available!</b><br><br>").format(
                    latest_release)
                footer = _(
                    "For more information visit our "
                    "<a href=\"{}\">installation guide</a>."
                ).format(url_i)
                if is_anaconda():
                    content = _(
                        "<b>Important note:</b> Since you installed "
                        "Spyder with Anaconda, please <b>don't</b> use "
                        "<code>pip</code> to update it as that will break "
                        "your installation.<br><br>"
                        "Instead, run the following commands in a "
                        "terminal:<br>"
                        "<code>conda update anaconda</code><br>"
                        "<code>conda install spyder={}</code><br><br>"
                    ).format(latest_release)
                else:
                    content = _(
                        "Please go to <a href=\"{}\">this page</a> to "
                        "download it.<br><br>"
                    ).format(url_r)
                msg = header + content + footer
                box.setText(msg)
                box.set_check_visible(True)
                box.exec_()
                check_updates = box.is_checked()
            elif feedback:
                msg = _("Spyder is up to date.")
                box.setText(msg)
                box.set_check_visible(False)
                box.exec_()
                check_updates = box.is_checked()

        # Update checkbox based on user interaction
        self.set_conf(option, check_updates)

        # Enable check_updates_action after the thread has finished
        self.check_updates_action.setDisabled(False)

        # Provide feeback when clicking menu if check on startup is on
        self.give_updates_feedback = True
示例#6
0
@pytest.mark.slow
def test_update_pre_to_pre(qtbot):
    """Test we offer updates between prereleases."""
    worker = WorkerUpdates(None, False, version="4.0.0a1",
                           releases=['4.0.0b5'])
    worker.start()
    assert worker.update_available


@pytest.mark.slow
def test_update_pre_to_final(qtbot):
    """Test we offer updates from prereleases to the final versions."""
    worker = WorkerUpdates(None, False, version="4.0.0b3",
                           releases=['4.0.0'])
    worker.start()
    assert worker.update_available


@pytest.mark.slow
@pytest.mark.skipif(not is_anaconda(),
                    reason='It only makes sense for Anaconda.')
def test_releases_anaconda(qtbot):
    """Test we don't include spyder-kernels releases in detected releases."""
    worker = WorkerUpdates(None, False, version="3.3.1")
    worker.start()
    assert '0.2.4' not in worker.releases


if __name__ == "__main__":
    pytest.main()
示例#7
0
文件: updates.py 项目: zhuyuuc/spyder
    def start(self):
        """Main method of the WorkerUpdates worker"""
        if is_anaconda():
            self.url = 'https://repo.anaconda.com/pkgs/main'
            if os.name == 'nt':
                self.url += '/win-64/repodata.json'
            elif sys.platform == 'darwin':
                self.url += '/osx-64/repodata.json'
            else:
                self.url += '/linux-64/repodata.json'
        else:
            self.url = ('https://api.github.com/repos/'
                        'spyder-ide/spyder/releases')
        self.update_available = False
        self.latest_release = __version__

        error_msg = None

        try:
            if hasattr(ssl, '_create_unverified_context'):
                # Fix for issue # 2685 [Works only with Python >=2.7.9]
                # More info: https://www.python.org/dev/peps/pep-0476/#opting-out
                context = ssl._create_unverified_context()
                page = urlopen(self.url, context=context)
            else:
                page = urlopen(self.url)
            try:
                data = page.read()

                # Needed step for python3 compatibility
                if not is_text_string(data):
                    data = data.decode()
                data = json.loads(data)

                if is_anaconda():
                    if self.releases is None:
                        self.releases = []
                        for item in data['packages']:
                            if ('spyder' in item and
                                    not re.search(r'spyder-[a-zA-Z]', item)):
                                self.releases.append(item.split('-')[1])
                    result = self.check_update_available()
                else:
                    if self.releases is None:
                        self.releases = [
                            item['tag_name'].replace('v', '') for item in data
                        ]
                        self.releases = list(reversed(self.releases))

                result = self.check_update_available()
                self.update_available, self.latest_release = result
            except Exception:
                error_msg = _('Unable to retrieve information.')
        except HTTPError:
            error_msg = _('Unable to retrieve information.')
        except URLError:
            error_msg = _('Unable to connect to the internet. <br><br>Make '
                          'sure the connection is working properly.')
        except Exception:
            error_msg = _('Unable to check for updates.')

        # Don't show dialog when starting up spyder and an error occur
        if not (self.startup and error_msg is not None):
            self.error = error_msg
            self.sig_ready.emit()
示例#8
0
     'package_name': "qtconsole",
     'features': _("Main package for the IPython console"),
     'required_version': QTCONSOLE_REQVER
 },
 {
     'modname': "qtpy",
     'package_name': "qtpy",
     'features': _("Abstraction layer for Python Qt bindings."),
     'required_version': QTPY_REQVER
 },
 {
     'modname': "rtree",
     'package_name': "rtree",
     'features': _("Fast access to code snippets regions"),
     'required_version': RTREE_REQVER,
     'display': is_anaconda() or is_pynsist()
 },
 {
     'modname': "setuptools",
     'package_name': "setuptools",
     'features': _("Determine package version"),
     'required_version': SETUPTOOLS_REQVER
 },
 {
     'modname':
     "sphinx",
     'package_name':
     "sphinx",
     'features':
     _("Show help for objects in the Editor and Consoles in a dedicated pane"
       ),
示例#9
0
        qtbot.keyPress(code_editor, Qt.Key_Tab)

    qtbot.keyPress(completion, Qt.Key_Tab)

    assert "spam()" in [x['label'] for x in sig.args[0]]
    assert code_editor.toPlainText() == 'import foo\nfoo.spam'

    # Reset extra paths
    CONF.set('main', 'spyder_pythonpath', [])
    completion_plugin.after_configuration_update([])
    qtbot.wait(500)


@pytest.mark.slow
@pytest.mark.order(1)
@pytest.mark.skipif(not is_anaconda(), reason='Requires conda to be installed')
@pytest.mark.skipif(not running_in_ci(), reason='Run tests only on CI.')
@flaky(max_runs=5)
def test_completions_environment(completions_codeeditor, qtbot, tmpdir):
    """Exercise code completion when adding extra paths."""
    code_editor, completion_plugin = completions_codeeditor
    completion = code_editor.completion_widget
    code_editor.toggle_automatic_completions(False)
    code_editor.toggle_code_snippets(False)

    # Get jedi test env
    conda_envs_path = os.path.dirname(sys.prefix)
    conda_jedi_env = os.path.join(conda_envs_path, 'jedi-test-env')

    if os.name == 'nt':
        py_exe = os.path.join(conda_jedi_env, 'python.exe')