[cmor] 07/10: fixes for python3 patch

Alastair McKinstry mckinstry at moszumanska.debian.org
Mon Jul 31 06:35:50 UTC 2017


This is an automated email from the git hooks/post-receive script.

mckinstry pushed a commit to branch debian/master
in repository cmor.

commit 3adc26771e7de3f63af77dba621a564bde000c20
Author: Alastair McKinstry <mckinstry at debian.org>
Date:   Sat Jul 29 21:13:36 2017 +0100

    fixes for python3 patch
---
 debian/patches/python3.patch | 294 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 292 insertions(+), 2 deletions(-)

diff --git a/debian/patches/python3.patch b/debian/patches/python3.patch
index 0ee9e57..0f8ae25 100644
--- a/debian/patches/python3.patch
+++ b/debian/patches/python3.patch
@@ -889,13 +889,14 @@ Index: cmor-3.2.5/Src/_cmormodule.c
      if (coords_obj == Py_None) {
          coord_vals = NULL;
      } else {
-@@ -1011,11 +1038,59 @@ static PyMethodDef MyExtractMethods[] =
+@@ -1011,11 +1038,58 @@ static PyMethodDef MyExtractMethods[] =
      {NULL, NULL}                /*sentinel */
  };
  
 -PyMODINIT_FUNC init_cmor(void)
 -{
 -    PyObject *cmor_module;
+-    cmor_module = Py_InitModule("_cmor", MyExtractMethods);
 +#if PY_MAJOR_VERSION >= 3
 +
 +static int MyExtract_traverse(PyObject *m, visitproc visit, void *arg) {
@@ -942,7 +943,6 @@ Index: cmor-3.2.5/Src/_cmormodule.c
 +      INITERROR;
 +    struct module_state *st = GETSTATE(module);
 +
-     cmor_module = Py_InitModule("_cmor", MyExtractMethods);
      import_array();
      CMORError = PyErr_NewException("_cmor.CMORError", NULL, NULL);
 -    PyModule_AddObject(cmor_module, "CMORError", CMORError);
@@ -2675,3 +2675,293 @@ Index: cmor-3.2.5/Src/_controlvocabulary.c
 +    return module;
 +#endif
  }
+Index: cmor-3.2.5/LibCV/PrePARE/PrePARE.py
+===================================================================
+--- cmor-3.2.5.orig/LibCV/PrePARE/PrePARE.py
++++ cmor-3.2.5/LibCV/PrePARE/PrePARE.py
+@@ -16,6 +16,7 @@ Created on Fri Feb 19 11:33:52 2016
+ 
+ @author: Denis Nadeau LLNL
+ '''
++from __future__ import print_function
+ import cmip6_cv
+ import cdms2
+ import argparse
+@@ -137,25 +138,25 @@ class checkCMIP6(object):
+             self.var = [self.infile.variable_id]
+ 
+         if((self.var == []) or (len(self.var) > 1)):
+-            print bcolors.FAIL
+-            print "!!!!!!!!!!!!!!!!!!!!!!!!!"
+-            print "! Error:  The input file does not have an history attribute and the CMIP6 variable could not be found"
+-            print "!         Please use the --variable option to specify your CMIP6 variable"
+-            print "! Check your file or use CMOR 3.x to achieve compliance for ESGF publication."
+-            print "!!!!!!!!!!!!!!!!!!!!!!!!!"
+-            print bcolors.ENDC
++            print (bcolors.FAIL)
++            print ("!!!!!!!!!!!!!!!!!!!!!!!!!")
++            print ("! Error:  The input file does not have an history attribute and the CMIP6 variable could not be found")
++            print ("!         Please use the --variable option to specify your CMIP6 variable")
++            print ("! Check your file or use CMOR 3.x to achieve compliance for ESGF publication.")
++            print ("!!!!!!!!!!!!!!!!!!!!!!!!!")
++            print (bcolors.ENDC)
+ 
+             raise KeyboardInterrupt
+ 
+         try:
+             self.keys = self.infile.listattribute(self.var[0])
+         except BaseException:
+-            print bcolors.FAIL
+-            print "!!!!!!!!!!!!!!!!!!!!!!!!!"
+-            print "! Error:  The variable " + self.var[0] + " could not be found"
+-            print "! Check your file variables "
+-            print "!!!!!!!!!!!!!!!!!!!!!!!!!"
+-            print bcolors.ENDC
++            print (bcolors.FAIL)
++            print ("!!!!!!!!!!!!!!!!!!!!!!!!!")
++            print ("! Error:  The variable " + self.var[0] + " could not be found")
++            print ("! Check your file variables ")
++            print ("!!!!!!!!!!!!!!!!!!!!!!!!!")
++            print (bcolors.ENDC)
+ 
+             raise
+ 
+@@ -195,9 +196,9 @@ class checkCMIP6(object):
+             cmip6_cv.set_cur_dataset_attribute(
+                 key,
+                 value) for key,
+-            value in self.dictGbl.iteritems()]
++            value in list(self.dictGbl.items())]
+         member_id = ""
+-        if("sub_experiment_id" in self.dictGbl.keys() ):
++        if("sub_experiment_id" in list(self.dictGbl.keys()) ):
+                 if(self.dictGbl["sub_experiment_id"] not in ["none"]):
+                     member_id = self.dictGbl["sub_experiment_id"] + \
+                         '-' + self.dictGbl["variant_label"]
+@@ -286,32 +287,32 @@ class checkCMIP6(object):
+             fn)
+ 
+         if not isinstance(self.dictGbl['realization_index'], numpy.ndarray):
+-            print bcolors.FAIL
+-            print "====================================================================================="
+-            print "realization_index is not an integer: ", type(self.dictGbl['realization_index'])
+-            print "====================================================================================="
+-            print bcolors.ENDC
++            print (bcolors.FAIL)
++            print ("=====================================================================================")
++            print ("realization_index is not an integer: ", type(self.dictGbl['realization_index']))
++            print ("=====================================================================================")
++            print (bcolors.ENDC)
+             cmip6_cv.set_CV_Error()
+         if not isinstance(self.dictGbl['initialization_index'], numpy.ndarray):
+-            print bcolors.FAIL
+-            print "====================================================================================="
+-            print "initialization_index is not an integer: ", type(self.dictGbl['initialization_index'])
+-            print "====================================================================================="
+-            print bcolors.ENDC
++            print (bcolors.FAIL)
++            print ("=====================================================================================")
++            print ("initialization_index is not an integer: ", type(self.dictGbl['initialization_index']))
++            print ("=====================================================================================")
++            print (bcolors.ENDC)
+             cmip6_cv.set_CV_Error()
+         if not isinstance(self.dictGbl['physics_index'], numpy.ndarray):
+-            print bcolors.FAIL
+-            print "====================================================================================="
+-            print "physics_index is not an integer: ", type(self.dictGbl['physics_index'])
+-            print "====================================================================================="
+-            print bcolors.ENDC
++            print (bcolors.FAIL)
++            print ("=====================================================================================")
++            print ("physics_index is not an integer: ", type(self.dictGbl['physics_index']))
++            print ("=====================================================================================")
++            print (bcolors.ENDC)
+             cmip6_cv.set_CV_Error()
+         if not isinstance(self.dictGbl['forcing_index'], numpy.ndarray):
+-            print bcolors.FAIL
+-            print "====================================================================================="
+-            print "forcing_index is not an integer: ", type(self.dictGbl['forcing_index'])
+-            print "====================================================================================="
+-            print bcolors.ENDC
++            print (bcolors.FAIL)
++            print ("=====================================================================================")
++            print ("forcing_index is not an integer: ", type(self.dictGbl['forcing_index']))
++            print ("=====================================================================================")
++            print (bcolors.ENDC)
+             cmip6_cv.set_CV_Error()
+ 
+         prepLIST = cmip6_cv.list_variable_attributes(varid)
+@@ -319,7 +320,7 @@ class checkCMIP6(object):
+             if(key == "comment"):
+                 continue
+             # Is this attritue in file?
+-            if(key in self.dictVars.keys()):
++            if(key in list(self.dictVars.keys())):
+                 # Verify that attribute value is equal to file attribute
+                 table_value = prepLIST[key]
+                 file_value = self.dictVars[key]
+@@ -340,12 +341,12 @@ class checkCMIP6(object):
+                 file_value = str(file_value)
+                 table_value = str(table_value)
+                 if table_value != file_value:
+-                    print bcolors.FAIL
+-                    print "====================================================================================="
+-                    print "You file contains \"" + key + "\":\"" + str(file_value) + "\" and"
+-                    print "CMIP6 tables requires \"" + key + "\":\"" + str(table_value) + "\"."
+-                    print "====================================================================================="
+-                    print bcolors.ENDC
++                    print (bcolors.FAIL)
++                    print ("=====================================================================================")
++                    print ("You file contains \"" + key + "\":\"" + str(file_value) + "\" and")
++                    print ("CMIP6 tables requires \"" + key + "\":\"" + str(table_value) + "\".")
++                    print ("=====================================================================================")
++                    print (bcolors.ENDC)
+                     cmip6_cv.set_CV_Error()
+             else:
+                 # That attribute is not in the file
+@@ -354,20 +355,20 @@ class checkCMIP6(object):
+                     table_value = table_value[0]
+                 if isinstance(table_value, float):
+                     table_value = "{0:.2g}".format(table_value)
+-                print bcolors.FAIL
+-                print "====================================================================================="
+-                print "CMIP6 variable " + self.var[0] + " requires \"" + key + "\":\"" + str(table_value) + "\"."
+-                print "====================================================================================="
+-                print bcolors.ENDC
++                print (bcolors.FAIL)
++                print ("=====================================================================================")
++                print ("CMIP6 variable " + self.var[0] + " requires \"" + key + "\":\"" + str(table_value) + "\".")
++                print ("=====================================================================================")
++                print (bcolors.ENDC)
+                 cmip6_cv.set_CV_Error()
+ 
+         if(cmip6_cv.get_CV_Error()):
+             raise KeyboardInterrupt
+-        print bcolors.OKGREEN
+-        print "*************************************************************************************"
+-        print "* This file is compliant with the CMIP6 specification and can be published in ESGF. *"
+-        print "*************************************************************************************"
+-        print bcolors.ENDC
++        print (bcolors.OKGREEN)
++        print ("*************************************************************************************")
++        print ("* This file is compliant with the CMIP6 specification and can be published in ESGF. *")
++        print ("*************************************************************************************")
++        print (bcolors.ENDC)
+ 
+ 
+ #  =========================
+@@ -398,7 +399,7 @@ def main():
+     try:
+         args = parser.parse_args()
+     except argparse.ArgumentTypeError as errmsg:
+-        print >> sys.stderr, str(errmsg)
++        print (str(errmsg), file=sys.stderr)
+         return 1
+     except SystemExit:
+         return 1
+@@ -407,12 +408,12 @@ def main():
+         process = checkCMIP6(args)
+         process.ControlVocab()
+     except KeyboardInterrupt:
+-        print bcolors.FAIL
+-        print "!!!!!!!!!!!!!!!!!!!!!!!!!"
+-        print "! Error:  The input file is not CMIP6 compliant"
+-        print "! Check your file or use CMOR 3.x to achieve compliance for ESGF publication."
+-        print "!!!!!!!!!!!!!!!!!!!!!!!!!"
+-        print bcolors.ENDC
++        print (bcolors.FAIL)
++        print ("!!!!!!!!!!!!!!!!!!!!!!!!!")
++        print ("! Error:  The input file is not CMIP6 compliant")
++        print ("! Check your file or use CMOR 3.x to achieve compliance for ESGF publication.")
++        print ("!!!!!!!!!!!!!!!!!!!!!!!!!")
++        print (bcolors.ENDC)
+         sys.exit(-1)
+ # process.checkActivities()
+     return(0)
+@@ -423,12 +424,12 @@ if(__name__ == '__main__'):
+         sys.exit(main())
+ 
+     except KeyboardInterrupt:
+-        print bcolors.FAIL
+-        print "!!!!!!!!!!!!!!!!!!!!!!!!!"
+-        print "! Error:  The input file is not CMIP6 compliant"
+-        print "! Check your file or use CMOR 3.x to achieve compliance for ESGF publication."
+-        print "!!!!!!!!!!!!!!!!!!!!!!!!!"
+-        print bcolors.ENDC
++        print (bcolors.FAIL)
++        print ("!!!!!!!!!!!!!!!!!!!!!!!!!")
++        print ("! Error:  The input file is not CMIP6 compliant")
++        print ("! Check your file or use CMOR 3.x to achieve compliance for ESGF publication.")
++        print ("!!!!!!!!!!!!!!!!!!!!!!!!!")
++        print (bcolors.ENDC)
+         sys.exit(-1)
+     except BaseException:
+         sys.exit(-1)
+Index: cmor-3.2.5/Test/test_chunking.py
+===================================================================
+--- cmor-3.2.5.orig/Test/test_chunking.py
++++ cmor-3.2.5/Test/test_chunking.py
+@@ -1,3 +1,4 @@
++from __future__ import print_function
+ import cmor
+ import numpy
+ import sys
+@@ -11,7 +12,7 @@ try:
+     cdms2.setNetcdfDeflateFlag(0)
+     cdms2.setNetcdfDeflateLevelFlag(0)
+ except BaseException:
+-    print "This test code needs a recent cdms2 interface for i/0"
++    print ("This test code needs a recent cdms2 interface for i/0")
+     sys.exit()
+ 
+ 
+@@ -24,7 +25,7 @@ cmor.dataset_json("Test/common_user_inpu
+ 
+ tables = []
+ tables.append(cmor.load_table("CMIP6_chunking.json"))
+-print 'Tables ids:', tables
++print ('Tables ids:', tables)
+ 
+ 
+ # read in data, just one slice
+Index: cmor-3.2.5/Test/test_python_sos_psu_units.py
+===================================================================
+--- cmor-3.2.5.orig/Test/test_python_sos_psu_units.py
++++ cmor-3.2.5/Test/test_python_sos_psu_units.py
+@@ -1,3 +1,4 @@
++from __future__ import print_function
+ import cmor
+ import numpy
+ import unittest
+@@ -74,9 +75,9 @@ class TestCase(unittest.TestCase):
+                 for i in range(4):
+                     tval = [i / 4. + d]
+                     tbnd = [i / 4. + d - 0.125, i / 4. + d + 0.125]
+-                    print 'tvar', tval
+-                    print 'tbnd', tbnd
+-                    print 'writing time:', i, i / 4.
++                    print ('tvar', tval)
++                    print ('tbnd', tbnd)
++                    print ('writing time:', i, i / 4.)
+                     data = numpy.random.random(
+                         (ntimes, nlat, nlon)) * 30. + 273
+                     data = data.astype("f")
+@@ -87,13 +88,13 @@ class TestCase(unittest.TestCase):
+                     tval = [i / 4. + d + 200]
+                     tbnd = [i / 4. + d + 200 - 0.125, i / 4. + d + 200 + 0.125]
+                     cmor.write(ivar3, data, time_vals=tval, time_bnds=tbnd)
+-                    print 'wrote var 1 time:', i
+-                file = cmor.close(ivar, True)
++                    print ('wrote var 1 time:', i)
++                file0 = cmor.close(ivar, True)
+                 file1 = cmor.close(ivar2, True)
+                 file2 = cmor.close(ivar3, True)
+-                print 'File:', file
+-                print 'File:', file1
+-                print 'File:', file2
++                print ('File:', file0)
++                print ('File:', file1)
++                print ('File:', file2)
+         except BaseException:
+             raise
+ 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/cmor.git



More information about the debian-science-commits mailing list