Exemple #1
0
    def check(self, raise_=True):
        """Check that all requirements are available (importable)
           and their versions match (using pkg.__version__).

        :param raise_: Raise DistributionNotFound if ImportError
          or VersionConflict if version doesn't match?
          If false just return None.
        """
        for req in self:
            try:
                mod = __import__(req.modname)
            except ImportError:
                if raise_:
                    raise DistributionNotFound(str(req))
                return False
            if not req.specs: # No version constraints
                continue
            try:
                version = mod.__version__
            except AttributeError as e:
                raise AttributeError("%s: %s" % (e, mod))
            if version not in req:
                if raise_:
                    raise VersionConflict(
                      "Need %s. Found %s" % (str(req), version))
                return False
        return True
def check_libraries_requirements():
    """Check if the required dependencies are met.
    Calling this function at the program start will allow the program to terminate
    gracefully in case of an unmet dependency instead of crashing while performing
    important tasks."""
    file_path = paths.get_base_path('requirements.txt')

    try:
        # Skip the check if we are running in a |PyInstaller| bundle. Assume everything is all right.
        if not paths.is_pyinstaller_bundle():
            with file(file_path) as req_file:
                requirements = req_file.readlines()
                require(requirements)

        # Libtorrent requirements
        try:
            # Workaround for libtorrent version (not available on pip so it cannot
            # be written inside requirements.txt).
            import libtorrent

            if LooseVersion(libtorrent.version) < LooseVersion(
                    libtorrent_least_required_version):
                raise VersionConflict(
                    'libtorrent {}'.format(libtorrent.version),
                    'libtorrent >= {}'.format(
                        libtorrent_least_required_version))

        except ImportError:
            raise DistributionNotFound('libtorrent')

        # Kivy requirements
        try:
            import multiprocessing
            multiprocessing.freeze_support()

            import kivy

            kivy.require(kivy_least_required_version)

        except ImportError:
            raise DistributionNotFound('kivy')

        except Exception:
            # Kivy raises an Exception with a not-so-nicely formatted message
            # Just print it and exit
            msg = "".join(_format_exc_info(*sys.exc_info())) + \
                  "\nAvast DeepScreen is known to fail here."
            MessageBox(msg, 'Kivy error')
            sys.exit(1)

    except VersionConflict as ex:
        message = 'Wrong library version. Installed: {}. Required: {}'.format(
            ex.args[0], ex.args[1])
        MessageBox(message, 'Error')
        sys.exit(1)

    except DistributionNotFound as ex:
        message = 'Missing python library. Required: {}'.format(ex.args[0])
        MessageBox(message, 'Error')
        sys.exit(1)
Exemple #3
0
 def test_get_exitcode(self):
     self.assertEqual(get_exitcode(KeyboardInterrupt()), 130)
     self.assertEqual(get_exitcode(AssertionError()), 255)
     self.assertEqual(get_exitcode(SystemExit(999)), 999)
     self.assertEqual(get_exitcode(VersionConflict(
         'version 1.0', 'version 2.0')), 13)
     self.assertEqual(get_exitcode(EOFError()), 0)
     self.assertEqual(get_exitcode(None), 0)
Exemple #4
0
    def init(self):
        """ Init module """
        log.info('Initializing module Market')

        Plugin.directory = Path(
            self.context.settings['development']['modules'])

        me = Plugin(self.name)
        me._register_in_global()

        self.check_updates()

        plugins_to_download = self.plugin_list
        try:
            plugins_to_download.extend(self.settings['preordered_plugins'])
        except (KeyError, TypeError):
            ...
        try:
            plugins_to_download.extend(getenv('PREORDERED_PLUGINS').split(','))
        except AttributeError:
            ...

        # self.download_plugins(set(plugins_to_download))
        GitManagerMixin.git_manager = self.context.git_manager
        GitManagerMixin.git_config = self.settings['git_config']
        self.clone_plugins(set(plugins_to_download))

        req_status = self.check_requirements()

        if req_status['attention']:
            if self.settings['requirements']['raise_on_attention']:
                raise VersionConflict(req_status['attention'])
            else:
                for i in req_status['attention'].values():
                    for plugin, requirement in map(
                            lambda y: (y['plugin'], y['requirement']), i):
                        plugin.installer(package=requirement)
        if req_status['conflict']:
            raise VersionConflict(req_status['conflict'])

        for i in req_status['safe'].values():
            for plugin, requirement in map(
                    lambda y: (y['plugin'], y['requirement']), i):
                plugin.installer(package=requirement)

        self.copy_configs()
Exemple #5
0
 def test_get_exitcode(self):
     self.assertEqual(get_exitcode(KeyboardInterrupt()), 130)
     self.assertEqual(get_exitcode(AssertionError()), 255)
     self.assertEqual(get_exitcode(SystemExit(999)), 999)
     self.assertEqual(get_exitcode(VersionConflict(
         "libclang-py3 0.3", "libclang-py3==0.2")), 13)
     self.assertEqual(get_exitcode(EOFError()), 0)
     self.assertEqual(get_exitcode(None), 0)
Exemple #6
0
 def test_version_conflict_in_collecting_bears(self, import_fn, _):
     with bear_test_module():
         import_fn.side_effect = VersionConflict("msg1", "msg2")
         retval, output = execute_coala(coala.main, "coala", "-A")
         self.assertEqual(retval, 13)
         self.assertIn(("There is a conflict in the version of a "
                        "dependency you have installed"), output)
         self.assertIn("pip install msg2", output)  # Check recommendation
Exemple #7
0
 def test_version_conflict_in_collecting_bears(self, import_fn, _):
     with bear_test_module():
         import_fn.side_effect = VersionConflict('msg1', 'msg2')
         retval, output = execute_coala(coala.main, 'coala', '-B')
         self.assertEqual(retval, 13)
         self.assertIn(('There is a conflict in the version of a '
                        'dependency you have installed'), output)
         self.assertIn('pip install "msg2"', output)
Exemple #8
0
 def test_version_conflict_in_collecting_bears(self, import_fn):
     with bear_test_module():
         import_fn.side_effect = VersionConflict('msg1', 'msg2')
         retval, stdout, stderr = execute_coala(coala.main, 'coala', '-B')
         self.assertEqual(retval, 13)
         self.assertIn(('There is a conflict in the version of a '
                        'dependency you have installed'), stderr)
         self.assertIn('pip3 install "msg2"', stderr)
         self.assertFalse(stdout)
         self.assertNotEqual(
             retval, 0, 'coala must return nonzero when errors occured')
Exemple #9
0
    def find(self, modpath, raise_=True):
        """Try to find the distribution and check version.

        - Also checks if distribution is in the same directory
          as given `modpath`.
        - Automatically reinstalls zetup in develop mode
          on distribution version mismatch
          if handling zetup's own config from zetup's project src.

        :param raise_:
           Raise a ``VersionConflict``
           if version doesn't match the given one?
           If ``False`` just return ``None``.
        """
        # If no version is given (for whatever reason), just do nothing:
        if not self.version:
            return None
        try:
            dist = get_distribution(self)
        except DistributionNotFound:
            return None
        # check if distribution path matches package path
        if os.path.normcase(os.path.realpath(dist.location)) \
          != os.path.normcase(os.path.dirname(os.path.realpath(modpath))):
            return None
        if dist.parsed_version != self.version.parsed:
            message = (
                "Version of distribution %s "
                "doesn't match version %s from %s. "
                % (repr(dist), self.version, repr(self.zfg)))
            # are we handling zetup's own config?
            if self == 'zetup':
                from zetup.zetup import Zetup
                # and was it loaded from zetup's project src?
                if isinstance(self.zfg, Zetup):
                    print('zetup:', message)
                    # then automatically reinstall zetup in develop mode
                    print('zetup: Reinstalling in develop mode...')
                    import zetup.commands.dev
                    self.zfg.dev()
                    # reset setuptools distribution cache
                    pkg_resources.working_set = pkg_resources.WorkingSet(
                        pkg_resources.working_set.entries)
                    # and return updated dist
                    return get_distribution(self)

            elif raise_:
                raise VersionConflict(
                    message + "Please reinstall %s." % str.__repr__(self))
            return None
        return dist
Exemple #10
0
        def resolve_requirement(requirement: Requirement):
            dist = best.get(requirement.key)
            if dist is None:
                # Find the best distribution and add it to the map
                dist = self.by_key.get(requirement.key)
                if dist is None or (dist not in requirement
                                    and replace_conflicting):
                    ws = self
                    with lock:
                        if env[0] is None:
                            if dist is None:
                                env[0] = Environment(self.entries)
                            else:
                                # Use an empty environment and workingset to avoid
                                # any further conflicts with the conflicting
                                # distribution
                                env[0] = Environment([])
                                ws = WorkingSet([])
                    dist = best[requirement.key] = env[0].best_match(
                        requirement,
                        ws,
                        installer,
                        replace_conflicting=replace_conflicting,
                    )
                    if dist is None:
                        requirers = required_by.get(requirement, None)
                        raise DistributionNotFound(requirement, requirers)
                resolved.append(dist)

            if dist not in requirement:
                # Oops, the "best" so far conflicts with a dependency
                dependent_requirement = required_by[requirement]
                raise VersionConflict(
                    dist, requirement).with_context(dependent_requirement)

            with lock:
                # push the new requirements onto the stack
                new_requirements = [
                    requirement
                    for requirement in dist.requires(requirement.extras)[::-1]
                    if requirement.key not in self.excludes
                ]
                req_stack.extend(new_requirements)

                # Register the new requirements needed by requirement
                for new_requirement in new_requirements:
                    required_by[new_requirement].add(requirement.project_name)
                    requirement_extras[new_requirement] = requirement.extras

                processed[requirement] = True
Exemple #11
0
    def test_unimportable_bear(self, import_fn):
        with bear_test_module():
            import_fn.side_effect = SyntaxError
            retval, output = execute_coala(coala.main, "coala", "-A")
            self.assertEqual(retval, 0)
            self.assertIn("Unable to collect bears from", output)

            import_fn.side_effect = VersionConflict("msg1", "msg2")
            retval, output = execute_coala(coala.main, "coala", "-A")
            # Note that bear version conflicts don't give exitcode=13,
            # they just give a warning with traceback in log_level debug.
            self.assertEqual(retval, 0)
            self.assertRegex(
                output, "Unable to collect bears from .* because there "
                "is a conflict with the version of a dependency "
                "you have installed")
            self.assertIn("pip install msg2", output)  # Check recommendation
Exemple #12
0
    def test_unimportable_bear(self, import_fn):
        with bear_test_module():
            import_fn.side_effect = SyntaxError
            retval, output = execute_coala(coala.main, 'coala', '-B')
            self.assertEqual(retval, 0)
            self.assertIn('Unable to collect bears from', output)

            import_fn.side_effect = VersionConflict('msg1', 'msg2')
            retval, output = execute_coala(coala.main, 'coala', '-B')
            # Note that bear version conflicts don't give exitcode=13,
            # they just give a warning with traceback in log_level debug.
            self.assertEqual(retval, 0)
            self.assertRegex(
                output, 'Unable to collect bears from .* because there '
                'is a conflict with the version of a dependency '
                'you have installed')
            self.assertIn('pip install "msg2"', output)
Exemple #13
0
    def find(self, modpath, raise_=True):
        """Try to find the distribution and check version.

        :param raise_: Raise a VersionConflict
          if version doesn't match the given one?
          If false just return None.
        """
        try:
            dist = get_distribution(self)
        except DistributionNotFound:
            return None
        if os.path.realpath(dist.location) \
          != os.path.realpath(os.path.dirname(modpath)):
            return None
        if dist.parsed_version != self.version.parsed:
            if raise_:
                raise VersionConflict(
                  "Version of distribution %s"
                  " doesn't match %s.__version__ %s."
                  % (dist, self.pkg, self.version))
            return None
        return dist
Exemple #14
0
import sys
import platform
from pkg_resources import VersionConflict

from .about import (__author__, __author_email__, __description__, __name__,
                    __url__, __version__)

if sys.version_info <= (3, 0):
    raise VersionConflict("ORES requires Python '>=3' but your Python version is " + platform.python_version())


__all__ = [__name__, __version__, __author__, __author_email__,
           __description__, __url__]
Exemple #15
0
from .. import ClusterExpansion
from ..core.local_orbit_list_generator import LocalOrbitListGenerator
from ..core.structure import Structure
from .variable_transformation import transform_parameters
from ..input_output.logging_tools import logger
from pkg_resources import VersionConflict

try:
    import mip
    from mip.constants import BINARY, INTEGER
    from distutils.version import LooseVersion

    try:
        if LooseVersion(mip.constants.VERSION) < '1.6.3':
            raise VersionConflict(
                'Python-MIP version 1.6.3 or later is required in order '
                'to use the ground state finder.')
    except AttributeError:
        # This will happen with recent versions of MIP since mip.constants.VERSION
        # has moved to mip.VERSION, but that is fine.
        pass
except ImportError:
    raise ImportError(
        'Python-MIP (https://python-mip.readthedocs.io/en/latest/) is required in '
        'order to use the ground state finder.')


class GroundStateFinder:
    """
    This class provides functionality for determining the ground states
    using a binary cluster expansion. This is efficiently achieved through the
Exemple #16
0
 def test_version_conflict_in_collecting_bears(self, import_fn, _):
     with bear_test_module():
         import_fn.side_effect = VersionConflict('msg1', 'msg2')
         retval, _ = execute_coala(coala.main, 'coala', '--json', '-B')
         self.assertEqual(retval, 13)
Exemple #17
0
    def resolve(
        self,
        requirements: Sequence[Requirement],
        env: Optional[Environment] = None,
        installer: Optional[Callable[[str], Distribution]] = None,
        replace_conflicting: Optional[bool] = False,
        extras: List[str] = None,
    ) -> List[Distribution]:
        """List all distributions needed to (recursively) meet `requirements`
        `requirements` must be a sequence of ``Requirement`` objects.  `env`,
        if supplied, should be an ``Environment`` instance.  If
        not supplied, it defaults to all distributions available within any
        entry or distribution in the working set.  `installer`, if supplied,
        will be invoked with each requirement that cannot be met by an
        already-installed distribution; it should return a ``Distribution`` or
        ``None``.
        Unless `replace_conflicting=True`, raises a VersionConflict exception
        if
        any requirements are found on the path that have the correct name but
        the wrong version.  Otherwise, if an `installer` is supplied it will be
        invoked to obtain the correct version of the requirement and activate
        it.
        `extras` is a list of the extras to be used with these requirements.
        This is important because extra requirements may look like `my_req;
        extra = "my_extra"`, which would otherwise be interpreted as a purely
        optional requirement.  Instead, we want to be able to assert that these
        requirements are truly required.
        """

        # set up the stack
        requirements = list(requirements)[::-1]
        # set of processed requirements
        processed = {}
        # key -> dist
        best = {}
        resolved = []

        requirement_extras = _ReqExtras()

        # Mapping of requirement to set of distributions that required it;
        # useful for reporting info about conflicts.
        required_by = defaultdict(set)

        while requirements:
            # process dependencies breadth-first
            requirement = requirements.pop(0)
            if requirement in processed:
                # Ignore cyclic or redundant dependencies
                continue

            if not requirement_extras.markers_pass(requirement, extras):
                continue

            dist = best.get(requirement.key)
            if dist is None:
                # Find the best distribution and add it to the map
                dist = self.by_key.get(requirement.key)
                if dist is None or (dist not in requirement and replace_conflicting):
                    ws = self
                    if env is None:
                        if dist is None:
                            env = Environment(self.entries)
                        else:
                            # Use an empty environment and workingset to avoid
                            # any further conflicts with the conflicting
                            # distribution
                            env = Environment([])
                            ws = WorkingSet([])
                    dist = best[requirement.key] = env.best_match(
                        requirement,
                        ws,
                        installer,
                        replace_conflicting=replace_conflicting,
                    )
                    if dist is None:
                        requirers = required_by.get(requirement, None)
                        raise DistributionNotFound(requirement, requirers)
                resolved.append(dist)

            if dist not in requirement:
                # Oops, the "best" so far conflicts with a dependency
                dependent_requirement = required_by[requirement]
                raise VersionConflict(dist, requirement).with_context(
                    dependent_requirement
                )

            # push the new requirements onto the stack
            new_requirements = [
                requirement
                for requirement in dist.requires(requirement.extras)[::-1]
                if requirement.key not in self.excludes
            ]
            requirements.extend(new_requirements)

            # Register the new requirements needed by requirement
            for new_requirement in new_requirements:
                required_by[new_requirement].add(requirement.project_name)
                requirement_extras[new_requirement] = requirement.extras

            processed[requirement] = True

        # return list of distros to activate
        return resolved
Exemple #18
0
    >>> for feature, value in zip(features, values):
    ...     print("\t{0}: {1}".format(feature, repr(value)))
    ...
        <len(<english.informals.revision.matches>)>: 2
        <len(<spanish.informals.revision.matches>)>: 0
"""  # noqa
import platform
import sys

from pkg_resources import VersionConflict

from .about import (__author__, __author_email__, __description__, __name__,
                    __url__, __version__)
from .datasources import Datasource
from .dependencies import Dependent, DependentSet
from .extractors import Extractor
from .features import Feature
from .score_processor import ScoreProcessor
from .scoring import Model

if sys.version_info <= (3, 0):
    raise VersionConflict("Revscoring requires Python '>=3' " +
                          "but your Python version is " +
                          platform.python_version())

__all__ = [
    Datasource, Dependent, DependentSet, Extractor, Feature, Model,
    ScoreProcessor, __name__, __version__, __author__, __author_email__,
    __description__, __url__
]