mailRe: Failing system tests and the Python 2.5 fatality.


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by Edward d'Auvergne on November 11, 2014 - 16:50:
Hi Troels,

I've fixed the Python 3 compatibility for relax which had reverted to
quite a poor state.  The trunk should now be in a reasonable state to
run on all Python versions between 2.5 and 3.4 (excluding the dead
3.0).  To write code that is both Python 2 and 3 compatible in the
future, please note the following:

- Always use range() rather than xrange().  The only real reason for
xrange() would be a massive iteration over hundreds of millions or
more items.  The lib.compat module aliases range() to xrange() in
Python 3, but this should not be relied upon, especially in the relax
library whereby the lib.compat module may not always be imported.


- To create a list of numbers using range(126, 130, 2), for example,
wrap it in the list function as list(range(126, 130, 2)).  In Python
3, range() returns an iterator object rather than a list, just like
xrange() does in Python 2.  Actually, many functions now return
iterators and these can simply be wrapped in the list() function call
to obtain the correct object.


- dict.iteritems() can never be used, as it no longer exists in Python
3.  This was introduced into many parts of relax:

$ grep -r iteritems . --exclude-dir=.svn
./test_suite/shared_data/dispersion/Kjaergaard_et_al_2013/5_clustered_analyses.py:for
key, value in cdp.clustering.iteritems():
./test_suite/system_tests/relax_fit.py:            for s_id, time in
cdp.relax_times.iteritems():
./test_suite/system_tests/relax_disp.py:                for param,
param_conv in par_dic.iteritems():
./auto_analyses/relax_disp_repeat_cpmg.py:        for setting, value
in self.settings.iteritems():
./auto_analyses/relax_fit.py:            for s_id, time in
cdp.relax_times.iteritems():

As a standard alternative that will work on all Python versions, try:

for item in settings:
    print(item, settings[item])

I have converted all your code to use this construct.


- The same for dict.items() and dict.values(), though this can be used
as list(dict.items()) or list(dict.values()).  However it might be
better to use the above simple construct to obtain the key and then
directly reference the dict[key] value in the code.


- At all costs, avoid map, lambda, filter, and reduce.  These will
probably one day be eliminated from Python, as the creator of Python
does not like them
(http://www.artima.com/weblogs/viewpost.jsp?thread=98196).  Although
this is compact, it only takes a few lines of Python to do the same
thing.  The 2to3 conversion script is good for eliminating most, but
not all of these things.


- In general, using simple coding techniques rather than 'advanced'
language helper functions will result in more portable and
future-proof code.


Cheers,

Edward


On 10 November 2014 19:29, Edward d'Auvergne <edward@xxxxxxxxxxxxx> wrote:
Hi Troels,

Thank you for fixing those!  Once I sort out a few other issues, I'll
release relax 3.3.2.

Cheers,

Edward




On 10 November 2014 13:46, Edward d'Auvergne <edward@xxxxxxxxxxxxx> wrote:
Hi Troels,

I was wondering what your plans are for your recently introduced
system tests which currently fail?  These are:

F     1.06 s for Relax_disp.test_cpmg_synthetic_dx_map_points
F    57.81 s for Relax_disp.test_dx_map_clustered_create_par_file

The last test also takes far more time than it requires.  I would like
to soon release a new relax 3.3.2 release with all the recent bug
fixes, but the test suite needs to be passing on all systems before I
can do anything.  There is also the 'with' statement in the system
test problem which is fatal for Python 2.5 and which must be resolved
(https://gna.org/bugs/?22801,
http://thread.gmane.org/gmane.science.nmr.relax.scm/24011/focus=7229).
The new release is required as the Mac OS X binary release is
currently non-functional due to the bundled matplotlib package being
broken (https://gna.org/bugs/?22821).

Cheers,

Edward



Related Messages


Powered by MHonArc, Updated Tue Nov 11 17:20:13 2014