cmp functions in python should return -1, 0, or 1, although any int will work. However, due to some packages with very long version numbers currently in the tree, portage.versions.vercmp can return a long type, which will break any compare functions. Reproducible: Always Steps to Reproduce: Python 2.6.1 (r261:67515, Apr 7 2009, 11:30:57) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from portage.versions import * >>> pkg1 = pkgsplit('btrace-0.0.20060428050322') >>> pkg2 = pkgsplit('btrace-0.0.20071210202527') >>> pkg1, pkg2 (('btrace', '0.0.20060428050322', 'r0'), ('btrace', '0.0.20071210202527', 'r0')) >>> vercmp(pkg1[1], pkg2[1]) -10782152205L >>> # ^^ returns long, compare functions must return int. this causes problems ... class Foo(object): ... def __cmp__(self, x): ... return -10782152205 ... >>> [Foo() for _ in range(100)].sort() Actual Results: Traceback (most recent call last): File "<stdin>", line 1, in <module> OverflowError: long int too large to convert to int Expected Results: >>> from portage.versions import * >>> pkg1 = pkgsplit('btrace-0.0.20060428050322') >>> pkg2 = pkgsplit('btrace-0.0.20071210202527') >>> pkg1, pkg2 (('btrace', '0.0.20060428050322', 'r0'), ('btrace', '0.0.20071210202527', 'r0')) >>> vercmp(pkg1[1], pkg2[1]) -1
Created attachment 188656 [details, diff] ensure vercmp output is -1, 0 or 1
Thanks, I've committed a version of your patch in r13353. I've modified it to use the (a > b) - (a < b) construct as suggested in the py3k docs, since cmp() is no longer supported in py3k: http://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
Created attachment 188763 [details, diff] simplify pkgcmp Thanks, Zac. I totally forgot about cmp going away. Fixing vercmp also lets us simplify pkgcmp:
(In reply to comment #3) > Created an attachment (id=188763) [edit] > simplify pkgcmp Thanks, that's in svn r13354.
This is fixed in 2.2_rc31.
This is fixed in 2.1.6.12.