Author: bugman Date: Tue Oct 9 20:47:25 2012 New Revision: 17792 URL: http://svn.gna.org/viewcvs/relax?rev=17792&view=rev Log: Better Python 2.3 support. The compat module is now imported at the very start to allow the builtins to be set before any other imports. The sorted() builtin method is now mimicked and the os.devnull string set for Python 2.3 and earlier. Modified: trunk/compat.py trunk/relax.py Modified: trunk/compat.py URL: http://svn.gna.org/viewcvs/relax/trunk/compat.py?rev=17792&r1=17791&r2=17792&view=diff ============================================================================== --- trunk/compat.py (original) +++ trunk/compat.py Tue Oct 9 20:47:25 2012 @@ -23,7 +23,28 @@ """Temporary module for allowing relax to support both Python 2 and 3.""" # Python module imports. +from copy import deepcopy +import os +import platform import sys + + +# The operating system. +SYSTEM = platform.uname()[0] + + +def sorted(data): + """Python 2.3 and earlier replacement function for the builtin sorted() function.""" + + # Make a copy of the data. + new_data = deepcopy(data) + + # Sort. + new_data.sort() + + # Return the new data. + return new_data + # The Python version. py_version = sys.version_info[0] @@ -37,6 +58,21 @@ # This should work as all range() usage for Python 3 in relax must match the old xrange() usage. __builtin__.range = __builtin__.xrange + # The sorted() builtin function for Python 2.3 and earlier. + if sys.version_info[1] <= 3: + setattr(__builtin__, 'sorted', sorted) + + # The os.devnull object for Python 2.3 and earlier. + if sys.version_info[1] <= 3: + if SYSTEM == 'Linux': + os.devnull = '/dev/null' + elif SYSTEM == 'Windows' or SYSTEM == 'Microsoft': + os.devnull = 'nul' + elif SYSTEM == 'Darwin': + os.devnull = 'Dev:Null' + else: + os.devnull = None + # Python 3 work-arounds. if py_version == 3: Modified: trunk/relax.py URL: http://svn.gna.org/viewcvs/relax/trunk/relax.py?rev=17792&r1=17791&r2=17792&view=diff ============================================================================== --- trunk/relax.py (original) +++ trunk/relax.py Tue Oct 9 20:47:25 2012 @@ -29,6 +29,9 @@ # along with this program; if not, write to the Free Software # # # ############################################################################### + +# Python 2 and 3 work-arounds. +import compat # Dependency checks. import dep_check @@ -55,9 +58,6 @@ # Modify the environmental variables. putenv('PDBVIEWER', 'vmd') - -# Python 2 and 3 work-arounds. -import compat def start(mode=None, profile_flag=False):