Exemple #1
0
 def __init__(self, name, defaults=None, load=True, version=None,
              subfolder=None, backup=False, raw_mode=False,
              remove_obsolete=False):
     DefaultsConfig.__init__(self, name, subfolder)
     self.raw = 1 if raw_mode else 0
     if (version is not None and
             re.match(r'^(\d+).(\d+).(\d+)$', version) is None):
         raise ValueError("Version number %r is incorrect - must be in X.Y.Z format" % version)
     if isinstance(defaults, dict):
         defaults = [ (self.DEFAULT_SECTION_NAME, defaults) ]
     self.defaults = defaults
     if defaults is not None:
         self.reset_to_defaults(save=False)
     fname = self.filename()
     if backup:
         try:
             shutil.copyfile(fname, "%s.bak" % fname)
         except IOError:
             pass
     if load:
         # If config file already exists, it overrides Default options:
         self.load_from_ini()
         old_ver = self.get_version(version)
         _major = lambda _t: _t[:_t.find('.')]
         _minor = lambda _t: _t[:_t.rfind('.')]
         # Save new defaults
         self._save_new_defaults(defaults, version, subfolder)
         # Updating defaults only if major/minor version is different
         if _minor(version) != _minor(old_ver):
             if backup:
                 try:
                     shutil.copyfile(fname, "%s-%s.bak" % (fname, old_ver))
                 except IOError:
                     pass
             if check_version(old_ver, '2.4.0', '<'):
                 self.reset_to_defaults(save=False)
             else:
                 self._update_defaults(defaults, old_ver)
             if check_version(old_ver, '44.1.0', '<'):
                 run_lines = to_text_string(self.get('ipython_console',
                                                     'startup/run_lines'))
                 if run_lines is not NoDefault:
                     run_lines = run_lines.replace(',', '; ')
                     self.set('ipython_console',
                              'startup/run_lines', run_lines)
             # Remove deprecated options if major version has changed
             if remove_obsolete or _major(version) != _major(old_ver):
                 self._remove_deprecated_options(old_ver)
             # Set new version number
             self.set_version(version, save=False)
         if defaults is None:
             # If no defaults are defined, set .ini file settings as default
             self.set_as_defaults()
Exemple #2
0
 def __init__(self, name, defaults=None, load=True, version=None,
              subfolder=None, backup=False, raw_mode=False,
              remove_obsolete=False):
     DefaultsConfig.__init__(self, name, subfolder)
     self.raw = 1 if raw_mode else 0
     if (version is not None and
             re.match(r'^(\d+).(\d+).(\d+)$', version) is None):
         raise ValueError("Version number %r is incorrect - must be in X.Y.Z format" % version)
     if isinstance(defaults, dict):
         defaults = [ (self.DEFAULT_SECTION_NAME, defaults) ]
     self.defaults = defaults
     if defaults is not None:
         self.reset_to_defaults(save=False)
     fname = self.filename()
     if backup:
         try:
             shutil.copyfile(fname, "%s.bak" % fname)
         except IOError:
             pass
     if load:
         # If config file already exists, it overrides Default options:
         self.load_from_ini()
         old_ver = self.get_version(version)
         _major = lambda _t: _t[:_t.find('.')]
         _minor = lambda _t: _t[:_t.rfind('.')]
         # Save new defaults
         self._save_new_defaults(defaults, version, subfolder)
         # Updating defaults only if major/minor version is different
         if _minor(version) != _minor(old_ver):
             if backup:
                 try:
                     shutil.copyfile(fname, "%s-%s.bak" % (fname, old_ver))
                 except IOError:
                     pass
             if check_version(old_ver, '2.4.0', '<'):
                 self.reset_to_defaults(save=False)
             else:
                 self._update_defaults(defaults, old_ver)
             if check_version(old_ver, '44.1.0', '<'):
                 run_lines = to_text_string(self.get('ipython_console',
                                                     'startup/run_lines'))
                 if run_lines is not NoDefault:
                     run_lines = run_lines.replace(',', '; ')
                     self.set('ipython_console',
                              'startup/run_lines', run_lines)
             # Remove deprecated options if major version has changed
             if remove_obsolete or _major(version) != _major(old_ver):
                 self._remove_deprecated_options(old_ver)
             # Set new version number
             self.set_version(version, save=False)
         if defaults is None:
             # If no defaults are defined, set .ini file settings as default
             self.set_as_defaults()
Exemple #3
0
    def apply_configuration_patches(self, old_version=None):
        """
        Override method.

        Apply any patch to configuration values on version changes.
        """
        if old_version and check_version(old_version, '2.4.0', '<'):
            self.reset_to_defaults(save=False)
        else:
            self._update_defaults(self.defaults, old_version)

        if old_version and check_version(old_version, '44.1.0', '<'):
            run_lines = to_text_string(self.get('ipython_console',
                                                'startup/run_lines'))
            if run_lines is not NoDefault:
                run_lines = run_lines.replace(',', '; ')
                self.set('ipython_console', 'startup/run_lines', run_lines)
Exemple #4
0
    def get_defaults_path_name_from_version(self, old_version=None):
        """
        Override method.

        Get defaults location based on version.
        """
        if old_version:
            if check_version(old_version, '3.0.0', '<='):
                name = '{}-{}'.format('defaults', old_version)
                path = self._module_source_path
            elif check_version(old_version, '52.0.0', '<'):
                name = '{}-{}'.format(self._defaults_name_prefix, old_version)
                path = osp.join(get_conf_path(), 'defaults')
        else:
            super_class = super(SpyderUserConfig, self)
            path, name = super_class.get_defaults_path_name_from_version()

        return path, name
Exemple #5
0
 def _load_old_defaults(self, old_version):
     """Read old defaults"""
     old_defaults = cp.ConfigParser()
     if check_version(old_version, '3.0.0', '<='):
         path = get_module_source_path('spyder')
     else:
         path = osp.dirname(self.filename())
     path = osp.join(path, 'defaults') 
     old_defaults.read(osp.join(path, 'defaults-'+old_version+'.ini'))
     return old_defaults
Exemple #6
0
 def _load_old_defaults(self, old_version):
     """Read old defaults"""
     old_defaults = cp.ConfigParser()
     if check_version(old_version, '3.0.0', '<='):
         path = get_module_source_path('spyder')
     else:
         path = osp.dirname(self.filename())
     path = osp.join(path, 'defaults')
     old_defaults.read(osp.join(path, 'defaults-' + old_version + '.ini'))
     return old_defaults
Exemple #7
0
    def get_config_fpath_from_version(self, version=None):
        """
        Override method.

        Return the configuration path for given version.

        If no version is provided, it returns the current file path.
        """
        if version is None or self._external_plugin:
            fpath = self.get_config_fpath()
        elif check_version(version, '51.0.0', '<'):
            fpath = osp.join(get_conf_path(), 'spyder.ini')
        else:
            fpath = self.get_config_fpath()

        return fpath
Exemple #8
0
    def register_plugin(self, plugin_class):
        """Register plugin configuration."""
        conf_section = plugin_class.CONF_SECTION
        if plugin_class.CONF_FILE and conf_section:
            path = self.get_plugin_config_path(conf_section)
            version = plugin_class.CONF_VERSION
            version = version if version else '0.0.0'
            name_map = plugin_class._CONF_NAME_MAP
            name_map = name_map if name_map else {'spyder': []}
            defaults = plugin_class.CONF_DEFAULTS

            if conf_section in self._plugin_configs:
                raise RuntimeError('A plugin with section "{}" already '
                                   'exists!'.format(conf_section))

            plugin_config = MultiUserConfig(name_map,
                                            path=path,
                                            defaults=defaults,
                                            load=True,
                                            version=version,
                                            backup=True,
                                            raw_mode=True,
                                            remove_obsolete=False,
                                            external_plugin=True)

            # Recreate external plugin configs to deal with part two
            # (the shortcut conflicts) of spyder-ide/spyder#11132
            spyder_config = self._user_config._configs_map['spyder']
            if check_version(spyder_config._old_version, '54.0.0', '<'):
                # Remove all previous .ini files
                try:
                    plugin_config.cleanup()
                except EnvironmentError:
                    pass

                # Recreate config
                plugin_config = MultiUserConfig(name_map,
                                                path=path,
                                                defaults=defaults,
                                                load=True,
                                                version=version,
                                                backup=True,
                                                raw_mode=True,
                                                remove_obsolete=False,
                                                external_plugin=True)

            self._plugin_configs[conf_section] = (plugin_class, plugin_config)
Exemple #9
0
    def check_update_available(self, version, releases):
        """Checks if there is an update available.

        It takes as parameters the current version of Spyder and a list of
        valid cleaned releases in chronological order (what github api returns
        by default). Example: ['2.3.4', '2.3.3' ...]
        """
        if is_stable_version(version):
            # Remove non stable versions from the list
            releases = [r for r in releases if is_stable_version(r)]

        latest_release = releases[0]

        if version.endswith('dev'):
            return (False, latest_release)

        return (check_version(version, latest_release, '<'), latest_release)
Exemple #10
0
    def check_update_available(self, version, releases):
        """Checks if there is an update available.

        It takes as parameters the current version of Spyder and a list of
        valid cleaned releases in chronological order (what github api returns
        by default). Example: ['2.3.4', '2.3.3' ...]
        """
        if is_stable_version(version):
            # Remove non stable versions from the list
            releases = [r for r in releases if is_stable_version(r)]

        latest_release = releases[0]

        if version.endswith('dev'):
            return (False, latest_release)

        return (check_version(version, latest_release, '<'), latest_release)
Exemple #11
0
    def get_backup_fpath_from_version(self, version=None, old_version=None):
        """
        Override method.

        Make a backup of the configuration file.
        """
        if old_version and check_version(old_version, '51.0.0', '<'):
            name = 'spyder.ini'
            fpath = os.path.join(get_conf_path(), name)
            if version is None:
                backup_fpath = "{}{}".format(fpath, self._backup_suffix)
            else:
                backup_fpath = "{}-{}{}".format(fpath, version,
                                                self._backup_suffix)
        else:
            super_class = super(SpyderUserConfig, self)
            backup_fpath = super_class.get_backup_fpath_from_version(
                version, old_version)

        return backup_fpath
Exemple #12
0
    def check_update_available(self):
        """Checks if there is an update available.

        It takes as parameters the current version of Spyder and a list of
        valid cleaned releases in chronological order.
        Example: ['2.3.2', '2.3.3' ...] or with github ['2.3.4', '2.3.3' ...]
        """
        # Don't perform any check for development versions
        if 'dev' in self.version:
            return (False, latest_release)

        # Filter releases
        if is_stable_version(self.version):
            releases = [r for r in self.releases if is_stable_version(r)]
        else:
            releases = [r for r in self.releases
                        if not is_stable_version(r) or r in self.version]

        latest_release = releases[-1]

        return (check_version(self.version, latest_release, '<'),
                latest_release)
Exemple #13
0
    def check_update_available(self):
        """Checks if there is an update available.

        It takes as parameters the current version of Spyder and a list of
        valid cleaned releases in chronological order.
        Example: ['2.3.2', '2.3.3' ...] or with github ['2.3.4', '2.3.3' ...]
        """
        # Don't perform any check for development versions
        if 'dev' in self.version:
            return (False, latest_release)

        # Filter releases
        if is_stable_version(self.version):
            releases = [r for r in self.releases if is_stable_version(r)]
        else:
            releases = [
                r for r in self.releases
                if not is_stable_version(r) or r in self.version
            ]

        latest_release = releases[-1]

        return (check_version(self.version, latest_release,
                              '<'), latest_release)
Exemple #14
0
# Third party imports
from qtpy.QtCore import QPoint, Qt
from qtpy.QtGui import QCursor, QTextCursor, QTextDocument
from qtpy.QtWidgets import QApplication, QToolTip
from qtpy import QT_VERSION
from spyder_kernels.utils.dochelpers import (getargspecfromtext, getobj,
                                             getsignaturefromtext)

# Local imports
from spyder.config.base import _
from spyder.py3compat import is_text_string, to_text_string
from spyder.utils import encoding, sourcecode, programs
from spyder.utils.misc import get_error_match
from spyder.widgets.arraybuilder import NumpyArrayDialog

QT55_VERSION = programs.check_version(QT_VERSION, "5.5", ">=")

if QT55_VERSION:
    from qtpy.QtCore import QRegularExpression
else:
    from qtpy.QtCore import QRegExp


class BaseEditMixin(object):
    def __init__(self):
        self.eol_chars = None
        self.calltip_size = 600

    #------Line number area
    def get_linenumberarea_width(self):
        """Return line number area width"""
Exemple #15
0
def test_check_version():
    """Test the compare function for versions."""
    assert check_version('0.9.4-1', '0.9.4', '>=')
    assert check_version('3.0.0rc1', '3.0.0', '<')
    assert check_version('1.0', '1.0b2', '>')
Exemple #16
0
def test_not_update(qtbot):
    """Test the update checking for a version that don't needs an update."""
    worker = WorkerUpdates(None, False, version="1000.0.0")
    worker.start()
    assert not worker.update_available
    assert not check_version("1000.0.0", worker.latest_release, '<')
Exemple #17
0
"""
This module contains the Line Number panel
"""
import sys

from qtpy import QT_VERSION
from qtpy.QtCore import QSize, Qt
from qtpy.QtGui import QPainter, QColor

from spyder.py3compat import to_text_string
from spyder.utils import icon_manager as ima
from spyder.utils.programs import check_version
from spyder.api.panel import Panel
from spyder.plugins.editor.lsp import DiagnosticSeverity

QT55_VERSION = check_version(QT_VERSION, "5.5", ">=")


class LineNumberArea(Panel):
    """Line number area (on the left side of the text editor widget)"""

    # --- Qt Overrides
    # -----------------------------------------------------------------

    def __init__(self, editor):
        Panel.__init__(self, editor)

        self.setMouseTracking(True)
        self.scrollable = True
        self.linenumbers_color = QColor(Qt.darkGray)
Exemple #18
0
# Local imports
from spyder.config.manager import CONF
from spyder.py3compat import to_text_string
from spyder.utils import programs
from spyder.utils import syntaxhighlighters as sh

# To save metadata about widget shortcuts (needed to build our
# preferences page)
Shortcut = namedtuple('Shortcut', 'data')

# Stylesheet to remove the indicator that appears on tool buttons with a menu.
STYLE_BUTTON_CSS = "QToolButton::menu-indicator{image: none;}"

# Check for old PyQt versions
OLD_PYQT = programs.check_version(PYQT_VERSION, "5.12", "<")


def font_is_installed(font):
    """Check if font is installed"""
    return [
        fam for fam in QFontDatabase().families()
        if to_text_string(fam) == font
    ]


def get_family(families):
    """Return the first installed font family in family list"""
    if not isinstance(families, list):
        families = [families]
    for family in families:
Exemple #19
0
def test_check_version():
    """Test the compare function for versions."""
    assert check_version('0.9.4-1', '0.9.4', '>=')
    assert check_version('3.0.0rc1', '3.0.0', '<')
    assert check_version('1.0', '1.0b2', '>')
Exemple #20
0
# Third party imports
from qtpy.QtCore import QPoint, Qt
from qtpy.QtGui import QCursor, QTextCursor, QTextDocument
from qtpy.QtWidgets import QApplication, QToolTip
from qtpy import QT_VERSION
from spyder_kernels.utils.dochelpers import (getargspecfromtext, getobj,
                                             getsignaturefromtext)

# Local imports
from spyder.config.base import _
from spyder.py3compat import is_text_string, to_text_string
from spyder.utils import encoding, sourcecode, programs
from spyder.utils.misc import get_error_match
from spyder.widgets.arraybuilder import NumpyArrayDialog

QT55_VERSION = programs.check_version(QT_VERSION, "5.5", ">=")

if QT55_VERSION:
    from qtpy.QtCore import QRegularExpression
else:
    from qtpy.QtCore import QRegExp


class BaseEditMixin(object):

    def __init__(self):
        self.eol_chars = None
        self.calltip_size = 600

    #------Line number area
    def get_linenumberarea_width(self):
Exemple #21
0
This module contains the Line Number panel
"""
import sys

from qtpy import QT_VERSION
from qtpy.QtCore import QSize, Qt
from qtpy.QtGui import QPainter, QColor

from spyder.py3compat import to_text_string
from spyder.utils import icon_manager as ima
from spyder.utils.programs import check_version
from spyder.api.panel import Panel
from spyder.plugins.editor.lsp import DiagnosticSeverity


QT55_VERSION = check_version(QT_VERSION, "5.5", ">=")


class LineNumberArea(Panel):
    """Line number area (on the left side of the text editor widget)"""

    # --- Qt Overrides
    # -----------------------------------------------------------------

    def __init__(self, editor):
        Panel.__init__(self, editor)

        self.setMouseTracking(True)
        self.scrollable = True
        self.linenumbers_color = QColor(Qt.darkGray)