#744 Replace cmp= with key= for python3 support
Merged by mikem. Opened by franzh.
franzh/koji issue713  into  master

Download 744.patch
  1. replace cmp= with key= in _write_maven_repo_metadata()
  2. add unit test for _write_maven_repo_metadata()

:thumbsup:

rebased onto da888fed4ed446328c0fcf5b0d9c5d66d82fccb0

rebased onto f6a9d639df14836a8f384c70f83bf478fb88b9e5

[Dec 13 updates]
1. rewrite _sortByExtAndName() and return key pairs for sorting.
2. add unit test for taskinfo() in koji-web. it will test sorting results for changes in 1).

rebased onto 038dc5608294c3bf35090e1854a20568b6d1c9e0

It is one-use function. Maybe drop it and use following?

paths.sort(key=lambda x: os.path.splitext(os.path.basename(x[1]))[0])
paths.sort(key=lambda x: os.path.splitext(os.path.basename(x[1]))[1])
values['output'] = paths

@tkopecek,
I found it is 20% slower if it runs sort twice.

@franzh Ok, didn't expected such loss :-) But yes, makes sense, as keys are computed twice, etc.

cmp_to_key is new in python 2.7, so we cannot use it yet. RHEL6 still has 2.6.

OTOH, it looks like the python version from the lib should work in 2.6 if just included it.

Rebase and new patch for 2.6 compatibility.

Sorry, I haven't checked cmp_to_key is not supported in 2.6. To support 2.6, one solution is to back port cmp_to_key() in koji, the other is we can keep using cmp= in python2 and use cmp_to_key() only in python3.

But it doesn't need to add cmp_to_key() just for one time use.
The new patch goes with the second option. I add six.PY3 to check and prepare appropriate parameter for sorted()

rebased onto 806792f457b91604d1e1614f6c689794f17a3a56

Let's avoid backslash line continuations if we can, as pep8 suggests

rebased onto 885942e78bea56877b0774cfed2824d62842c18c

@mikem

Do you have any idea to run unittests on python 2.6.6 (centos6/rhel6) ?
The libraries in 2.6.6 are too old and result in many issues while running 'make test'.

Do you have any idea to run unittests on python 2.6.6 (centos6/rhel6) ?

Good question. I can see a few possibilities:

  1. adjust our tests to be portable across different unittest versions
  2. build an updated python-unittest for rhel6
  3. mayybe some virtualenv trickery (though that's probably getting too far from the actual target)

If we can make no.2 work, that might be the least work, but I don't know how feasible this is, since unittest is a core lib.

Hmm, looks like there is a python-unittest2 package in epel6. Perhaps something like:

try:
    import unittest2 as unittest
except ImportError:
    import unittest

(there's probably a better way to handle that import trickery, but that at least seems to work in a quick test here).

I've played with rhel6 compatibility and created this commit (on top of this PR). It runs all tests properly with py 2.6.6/2.7/3.5 except _relpath test which I want to drop via PR #819.

https://pagure.io/fork/tkopecek/koji/c/ab65dfba17709c2f320093d35a3b06f13817f030?branch=issue713-tests

@tkopecek
:thumbsup:

@tkopecek let's make a separate issue/pr for the rhel6 compatible unit test changes

Commit 45a5d3f9 fixes this pull-request

Pull-Request has been merged by mikem

Created issue #830 plus PR #831

Metadata