Пример #1
0
 def test_must_match_when_both_versions_are_composed_of_alphanumerics(self):
     self.assertTrue(
         version.match_required_version('2.3.3ab', '==', '2.3.3ab'))
     self.assertTrue(
         version.match_required_version('2.3.3ab', '<', '2.3.3ac'))
     self.assertTrue(
         version.match_required_version('2.3.3ad', '>', '2.3.3ac'))
     self.assertTrue(
         version.match_required_version('2.3.3ad', '<', '2.3.3ad.1'))
Пример #2
0
 def test_must_ignore_epoch_number_when_required_has_no_defined(self):
     self.assertTrue(
         version.match_required_version('1:1.3.0-1', '>', '1.1.0'))
     self.assertTrue(
         version.match_required_version('1:1.3.0-1', '>=', '1.1.0'))
     self.assertFalse(
         version.match_required_version('1:1.3.0-1', '<', '1.1.0'))
     self.assertFalse(
         version.match_required_version('1:1.3.0-1', '<=', '1.1.0'))
     self.assertFalse(
         version.match_required_version('1:1.3.0-1', '==', '1.1.0'))
Пример #3
0
    def _find_aur_providers(
            self, dep_name: str, dep_exp: str, aur_index: Iterable[str],
            exact_match: bool) -> Generator[Tuple[str, dict], None, None]:
        if exact_match and dep_name in aur_index:
            if dep_name == dep_exp:
                yield from self.aur_client.gen_updates_data((dep_name, ))
                return
            else:
                for _, dep_data in self.aur_client.gen_updates_data(
                    (dep_name, )):
                    split_informed_dep = self.re_dep_operator.split(dep_exp)
                    version_required = split_informed_dep[2]
                    exp_op = split_informed_dep[1].strip()

                    if match_required_version(dep_data['v'], exp_op,
                                              version_required):
                        yield dep_name, dep_data
                        return

        aur_search = self.aur_client.search(dep_name)

        if aur_search:
            aur_results = aur_search.get('results')

            if aur_results:
                if dep_name == dep_exp:
                    version_required, exp_op = None, None
                else:
                    split_informed_dep = self.re_dep_operator.split(dep_exp)
                    version_required = split_informed_dep[2]
                    exp_op = split_informed_dep[
                        1] if split_informed_dep[1] != '=' else '=='

                for pkgname, pkgdata in self.aur_client.gen_updates_data(
                    (aur_res['Name'] for aur_res in aur_results)):
                    if pkgname == dep_name or (dep_name in pkgdata['p']):
                        try:
                            if not version_required or match_required_version(
                                    pkgdata['v'], exp_op, version_required):
                                yield pkgname, pkgdata
                        except:
                            self._log.warning(
                                f"Could not compare AUR package '{pkgname}' version '{pkgdata['v']}' "
                                f"with the dependency expression '{dep_exp}'")
                            traceback.print_exc()
Пример #4
0
    def test_must_match_when_current_version_is_composed_of_alphanumerics_but_required_no(
            self):
        self.assertTrue(
            version.match_required_version('2.3.3op2', '>', '2.2.6'))
        self.assertTrue(
            version.match_required_version('2.3.3op2', '>=', '2.2.6'))
        self.assertFalse(
            version.match_required_version('2.3.3op2', '==', '2.2.6'))
        self.assertFalse(
            version.match_required_version('2.3.3op2', '<', '2.2.6'))
        self.assertFalse(
            version.match_required_version('2.3.3op2', '<=', '2.2.6'))

        # opposite comparisons
        self.assertFalse(
            version.match_required_version('2.2.6', '>', '2.3.3op2'))
        self.assertFalse(
            version.match_required_version('2.2.6', '>=', '2.3.3op2'))
        self.assertFalse(
            version.match_required_version('2.2.6', '==', '2.3.3op2'))
        self.assertTrue(
            version.match_required_version('2.2.6', '<', '2.3.3op2'))
        self.assertTrue(
            version.match_required_version('2.2.6', '<=', '2.3.3op2'))
Пример #5
0
    def _add_dependency_breakage(self, pkgname: str,
                                 pkgdeps: Optional[Set[str]],
                                 provided_versions: Dict[str, Set[str]],
                                 cannot_upgrade: Set[str],
                                 context: UpdateRequirementsContext):
        if pkgdeps:
            for dep in pkgdeps:
                dep_split = RE_DEP_OPERATORS.split(dep)

                if len(dep_split) > 1 and dep_split[1]:
                    real_providers = context.provided_map.get(dep_split[0])

                    if real_providers:
                        versions = provided_versions.get(dep_split[0])

                        if versions:
                            op = ''.join(RE_DEP_OPERATORS.findall(dep))

                            version_match = False

                            for v in versions:
                                try:
                                    if match_required_version(
                                            current_version=v,
                                            operator=op,
                                            required_version=dep_split[1]):
                                        version_match = True
                                        break
                                except:
                                    self.logger.error(
                                        "Error when comparing versions {} (provided) and {} (required)"
                                        .format(v, dep_split[1]))
                                    traceback.print_exc()

                            if not version_match:
                                for pname in real_providers:
                                    if pname not in cannot_upgrade:
                                        provider = context.to_update.get(pname)
                                        if provider:
                                            cannot_upgrade.add(pname)
                                            reason = self.i18n[
                                                'arch.sync.dep_breakage.reason'].format(
                                                    pkgname, dep)
                                            context.cannot_upgrade[
                                                pname] = UpgradeRequirement(
                                                    pkg=provider,
                                                    reason=reason)
Пример #6
0
    def test_must_consider_default_epoch_for_current_version_when_required_has_epoch(
            self):
        self.assertFalse(
            version.match_required_version('1.1.0', '==',
                                           '1:1.1.0'))  # 1.1.0 -> 0:1.1.0
        self.assertFalse(
            version.match_required_version('1.1.0', '>',
                                           '1:1.1.0'))  # 1.1.0 -> 0:1.1.0
        self.assertFalse(
            version.match_required_version('1.1.0', '>=',
                                           '1:1.1.0'))  # 1.1.0 -> 0:1.1.0
        self.assertTrue(version.match_required_version(
            '1.1.0', '<', '1:1.1.0'))  # 1.1.0 -> 0:1.1.0
        self.assertTrue(
            version.match_required_version('1.1.0', '<=',
                                           '1:1.1.0'))  # 1.1.0 -> 0:1.1.0

        self.assertTrue(
            version.match_required_version('1.1.0', '==',
                                           '0:1.1.0'))  # 1.1.0 -> 0:1.1.0
Пример #7
0
 def test_must_accept_single_or_both_equal_symbols_as_valid(self):
     self.assertTrue(version.match_required_version('1', '=', '1'))
     self.assertTrue(version.match_required_version('1', '==', '1'))
Пример #8
0
    def map_missing_deps(
        self,
        pkgs_data: Dict[str, dict],
        provided_map: Dict[str, Set[str]],
        remote_provided_map: Dict[str, Set[str]],
        remote_repo_map: Dict[str, str],
        aur_index: Iterable[str],
        deps_checked: Set[str],
        deps_data: Dict[str, dict],
        sort: bool,
        watcher: ProcessWatcher,
        choose_providers: bool = True,
        automatch_providers: bool = False,
        prefer_repository_provider: bool = False
    ) -> Optional[List[Tuple[str, str]]]:
        sorted_deps = [
        ]  # it will hold the proper order to install the missing dependencies

        missing_deps, repo_missing, aur_missing = set(), set(), set()

        deps_checked.update(pkgs_data.keys())

        for p, data in pkgs_data.items():
            if data['d']:
                for dep in data['d']:
                    if dep in pkgs_data:
                        continue
                    if dep not in provided_map:
                        dep_split = self.re_dep_operator.split(dep)
                        dep_name = dep_split[0].strip()

                        if dep_name not in deps_checked:
                            deps_checked.add(dep_name)

                            if dep_name not in provided_map:
                                self._fill_missing_dep(
                                    dep_name=dep_name,
                                    dep_exp=dep,
                                    aur_index=aur_index,
                                    missing_deps=missing_deps,
                                    remote_provided_map=remote_provided_map,
                                    remote_repo_map=remote_repo_map,
                                    repo_deps=repo_missing,
                                    aur_deps=aur_missing,
                                    watcher=watcher,
                                    deps_data=deps_data,
                                    automatch_providers=automatch_providers,
                                    prefer_repository_provider=
                                    prefer_repository_provider,
                                    dependent=p)
                            else:
                                version_pattern = '{}='.format(dep_name)
                                version_found = [
                                    p for p in provided_map
                                    if p.startswith(version_pattern)
                                ]

                                if version_found:
                                    version_found = version_found[0].split(
                                        '=')[1]
                                    version_required = dep_split[2]
                                    op = dep_split[1].strip()

                                    if not match_required_version(
                                            version_found, op,
                                            version_required):
                                        self._fill_missing_dep(
                                            dep_name=dep_name,
                                            dep_exp=dep,
                                            aur_index=aur_index,
                                            missing_deps=missing_deps,
                                            remote_provided_map=
                                            remote_provided_map,
                                            remote_repo_map=remote_repo_map,
                                            repo_deps=repo_missing,
                                            aur_deps=aur_missing,
                                            watcher=watcher,
                                            deps_data=deps_data,
                                            automatch_providers=
                                            automatch_providers,
                                            prefer_repository_provider=
                                            prefer_repository_provider,
                                            dependent=p)
                                else:
                                    self._fill_missing_dep(
                                        dep_name=dep_name,
                                        dep_exp=dep,
                                        aur_index=aur_index,
                                        missing_deps=missing_deps,
                                        remote_provided_map=remote_provided_map,
                                        remote_repo_map=remote_repo_map,
                                        repo_deps=repo_missing,
                                        aur_deps=aur_missing,
                                        watcher=watcher,
                                        deps_data=deps_data,
                                        automatch_providers=automatch_providers,
                                        prefer_repository_provider=
                                        prefer_repository_provider,
                                        dependent=p)

        if missing_deps:
            self._fill_single_providers_data(missing_deps, repo_missing,
                                             aur_missing, deps_data)

            missing_subdeps = self.map_missing_deps(
                pkgs_data={**deps_data},
                provided_map=provided_map,
                aur_index=aur_index,
                deps_checked=deps_checked,
                sort=False,
                deps_data=deps_data,
                watcher=watcher,
                remote_provided_map=remote_provided_map,
                remote_repo_map=remote_repo_map,
                automatch_providers=automatch_providers,
                choose_providers=False,
                prefer_repository_provider=prefer_repository_provider)

            if missing_subdeps:
                missing_deps.update(missing_subdeps)

        if sort:
            sorted_deps.extend(sorting.sort(deps_data.keys(), deps_data))
        else:
            sorted_deps.extend(((dep[0], dep[1]) for dep in missing_deps))

        if sorted_deps and choose_providers:
            return self.fill_providers_deps(
                missing_deps=sorted_deps,
                provided_map=provided_map,
                remote_provided_map=remote_provided_map,
                remote_repo_map=remote_repo_map,
                watcher=watcher,
                sort=sort,
                already_checked=deps_checked,
                aur_idx=aur_index,
                deps_data=deps_data,
                automatch_providers=automatch_providers,
                prefer_repository_provider=prefer_repository_provider)

        return sorted_deps
Пример #9
0
    def _find_repo_providers(
        self, dep_name: str, dep_exp: str, remote_provided_map: Dict[str,
                                                                     Set[str]],
        deps_data: Dict[str, dict], remote_repo_map: Dict[str, str]
    ) -> Generator[Tuple[str, str, Optional[dict]], None, None]:
        if dep_name == dep_exp:
            providers = remote_provided_map.get(dep_name)

            if providers:
                for pkgname in providers:
                    yield pkgname, remote_repo_map.get(pkgname), None

            else:  # try to find the package through the pacman's search mechanism
                match = pacman.find_one_match(dep_name)

                if match:
                    yield match, remote_repo_map.get(match), None

        else:  # handling cases when the dep has an expression ( e.g: xpto>=0.12 )
            exact_exp_providers = remote_provided_map.get(dep_exp)

            if exact_exp_providers:
                for p in exact_exp_providers:
                    yield p, remote_repo_map.get(p), None
            else:
                providers = remote_provided_map.get(dep_name)

                if not providers:  # try to find the package through the pacman's search mechanism
                    match = pacman.find_one_match(dep_name)

                    if match:
                        providers = {match}

                if providers:
                    providers_no_provided_data = {
                        p
                        for p in providers if p not in deps_data
                    }
                    missing_providers_data = None

                    if providers_no_provided_data:
                        missing_providers_data = pacman.map_updates_data(
                            providers_no_provided_data)

                        if not missing_providers_data:
                            raise Exception(
                                f"Could not retrieve information from providers: "
                                f"{', '.join(providers_no_provided_data)}")

                        data_not_found = {
                            p
                            for p in providers
                            if p not in missing_providers_data
                        }

                        if data_not_found:
                            raise Exception(
                                f"Could not retrieve information from providers: "
                                f"{', '.join(data_not_found)}")

                    split_informed_dep = self.re_dep_operator.split(dep_exp)

                    version_required = split_informed_dep[2]
                    exp_op = split_informed_dep[
                        1] if split_informed_dep[1] != '=' else '=='

                    for p in providers:
                        info = deps_data.get(p)

                        if not info and missing_providers_data:
                            info = missing_providers_data[p]

                        for provided_exp in info['p']:
                            split_dep = self.re_dep_operator.split(
                                provided_exp)

                            if len(split_dep
                                   ) == 3 and split_dep[0] == dep_name:
                                version_provided = split_dep[2]

                                if match_required_version(
                                        version_provided, exp_op,
                                        version_required):
                                    yield p, remote_repo_map.get(p), info
                                    break