From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1RAwsT-0006PT-Jb for garchives@archives.gentoo.org; Tue, 04 Oct 2011 04:45:13 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8819E21C057; Tue, 4 Oct 2011 04:45:05 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 4B0C921C057 for ; Tue, 4 Oct 2011 04:45:05 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id BE4F91B4012 for ; Tue, 4 Oct 2011 04:45:04 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id CA03180042 for ; Tue, 4 Oct 2011 04:45:03 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dep/, pym/portage/tests/dep/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/dep/__init__.py pym/portage/tests/dep/test_best_match_to_list.py X-VCS-Directories: pym/portage/dep/ pym/portage/tests/dep/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: b33ab8168a18391cc8ebe3d0b8bbcdc53a1a1c3d Date: Tue, 4 Oct 2011 04:45:03 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 82dec4efd90507525196cb8d22ca5044 commit: b33ab8168a18391cc8ebe3d0b8bbcdc53a1a1c3d Author: Zac Medico gentoo org> AuthorDate: Tue Oct 4 04:44:46 2011 +0000 Commit: Zac Medico gentoo org> CommitDate: Tue Oct 4 04:44:46 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3Db33ab816 best_match_to_list: order by version number This should fix the issue shown in bug 375265, comment #10. --- pym/portage/dep/__init__.py | 36 ++++++++++++++++= +++++- pym/portage/tests/dep/test_best_match_to_list.py | 4 ++ 2 files changed, 39 insertions(+), 1 deletions(-) diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index 21e2fac..8c65d66 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -30,13 +30,19 @@ __all__ =3D [ import re, sys import warnings from itertools import chain + +import portage +portage.proxy.lazyimport.lazyimport(globals(), + 'portage.util:cmp_sort_key', +) + from portage import _unicode_decode from portage.eapi import eapi_has_slot_deps, eapi_has_src_uri_arrows, \ eapi_has_use_deps, eapi_has_strong_blocks, eapi_has_use_dep_defaults from portage.exception import InvalidAtom, InvalidData, InvalidDependStr= ing from portage.localization import _ from portage.versions import catpkgsplit, catsplit, \ - pkgcmp, ververify, _cp, _cpv + pkgcmp, vercmp, ververify, _cp, _cpv import portage.cache.mappings =20 if sys.hexversion >=3D 0x3000000: @@ -1798,6 +1804,7 @@ def best_match_to_list(mypkg, mylist): '>':2, '<':2, '>=3D':2, '<=3D':2, None:1} maxvalue =3D -2 bestm =3D None + mypkg_cpv =3D None for x in match_to_list(mypkg, mylist): if x.extended_syntax: if dep_getslot(x) is not None: @@ -1817,6 +1824,33 @@ def best_match_to_list(mypkg, mylist): if op_val > maxvalue: maxvalue =3D op_val bestm =3D x + elif op_val =3D=3D maxvalue and op_val =3D=3D 2: + # For >, <, >=3D, and <=3D, the one with the version + # closest to mypkg is the best match. + if mypkg_cpv is None: + mypkg_cpv =3D getattr(mypkg, "cpv", None) + if mypkg_cpv is None: + mypkg_cpv =3D remove_slot(mypkg) + if bestm.cpv =3D=3D mypkg_cpv or bestm.cpv =3D=3D x.cpv: + pass + elif x.cpv =3D=3D mypkg_cpv: + bestm =3D x + else: + # Sort the cpvs to find the one closest to mypkg_cpv + cpv_list =3D [bestm.cpv, mypkg_cpv, x.cpv] + ver_map =3D {} + for cpv in cpv_list: + ver_map[cpv] =3D '-'.join(catpkgsplit(cpv)[2:]) + def cmp_cpv(cpv1, cpv2): + return vercmp(ver_map[cpv1], ver_map[cpv2]) + cpv_list.sort(key=3Dcmp_sort_key(cmp_cpv)) + if cpv_list[0] is mypkg_cpv or cpv_list[-1] is mypkg_cpv: + if cpv_list[1] is x.cpv: + bestm =3D x + else: + # TODO: handle the case where mypkg_cpv is in the middle + pass + return bestm =20 def match_from_list(mydep, candidate_list): diff --git a/pym/portage/tests/dep/test_best_match_to_list.py b/pym/porta= ge/tests/dep/test_best_match_to_list.py index d050adc..9cf5abd 100644 --- a/pym/portage/tests/dep/test_best_match_to_list.py +++ b/pym/portage/tests/dep/test_best_match_to_list.py @@ -25,6 +25,10 @@ class Test_best_match_to_list(TestCase): =20 def testBest_match_to_list(self): tests =3D [ + ("dev-libs/A-4", [Atom(">=3Ddev-libs/A-3"), Atom(">=3Ddev-libs/A-2"= )], \ + [Atom(">=3Ddev-libs/A-3"), Atom(">=3Ddev-libs/A-2")]), + ("dev-libs/A-4", [Atom("<=3Ddev-libs/A-5"), Atom("<=3Ddev-libs/A-6"= )], \ + [Atom("<=3Ddev-libs/A-5"), Atom("<=3Ddev-libs/A-6")]), ("dev-libs/A-1", [Atom("dev-libs/A"), Atom("=3Ddev-libs/A-1")], \ [Atom("=3Ddev-libs/A-1"), Atom("dev-libs/A")]), ("dev-libs/A-1", [Atom("dev-libs/B"), Atom("=3Ddev-libs/A-1:0")], \