[med-svn] [python-cobra] 01/05: Add patches to improve Python3 compatibility

Afif Elghraoui afif-guest at moszumanska.debian.org
Sat Jun 13 19:33:52 UTC 2015


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

afif-guest pushed a commit to branch master
in repository python-cobra.

commit e9b5b4e1f70bd170905b5f60e17d04cefc8e27d0
Author: Afif Elghraoui <afif at ghraoui.name>
Date:   Sat Jun 13 03:06:40 2015 -0700

    Add patches to improve Python3 compatibility
    
    This is required for the package to install correctly, even
    though there are no build errors without fixing these errors.
---
 debian/patches/improve-python3-support.patch | 309 +++++++++++++++++++++++++++
 debian/patches/series                        |   1 +
 2 files changed, 310 insertions(+)

diff --git a/debian/patches/improve-python3-support.patch b/debian/patches/improve-python3-support.patch
new file mode 100644
index 0000000..6f3c28a
--- /dev/null
+++ b/debian/patches/improve-python3-support.patch
@@ -0,0 +1,309 @@
+Description: Improve Python3 compatibility
+ Some parts of the code had Python2-specific syntax. These instances have
+ been changed to work with both Python2 and Python3. It's interesting to
+ note that these do not cause build-time errors. The problem becomes
+ apparent when trying to install the built python3-cobra package.
+Author: Afif Elghraoui <afif at ghraoui.name>
+Forwarded: https://github.com/opencobra/cobrapy/pull/165
+Last-Update: 2015-06-13
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+--- python-cobra.orig/cobra/external/ppmap.py
++++ python-cobra/cobra/external/ppmap.py
+@@ -30,6 +30,8 @@
+ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ # POSSIBILITY OF SUCH DAMAGE.
+ 
++from __future__ import print_function
++
+ """
+ Very basic parallel processing support
+ 
+@@ -105,18 +107,18 @@
+     # Immediate evaluation example
+     start = time.time()
+     results = ppmap(None, busybeaver, range(10))
+-    print 'Time to queue the jobs:', time.time() - start
++    print('Time to queue the jobs: {:f}'.format(time.time() - start))
+     start = time.time()
+     # Casting the ppmap generator to a list forces each result to be
+     # evaluated.  When done immediately after the jobs are submitted,
+     # our program twiddles its thumbs while the work is finished.
+-    print list(results)
+-    print 'Time to get the results:', time.time() - start
++    print(list(results))
++    print('Time to get the results: {:f}'.format(time.time() - start))
+ 
+     # Delayed evaluation example
+     start = time.time()
+     results = ppmap(None, busybeaver, range(10))
+-    print 'Time to queue the jobs:', time.time() - start
++    print('Time to queue the jobs: {:f}'.format(time.time() - start))
+     # In contrast with the above example, this time we're submitting a
+     # batch of jobs then going off to do more work while they're
+     # processing.  Maybe "time.sleep" isn't the most exciting example,
+@@ -128,24 +130,24 @@
+     # results.
+     time.sleep(5)
+     start = time.time()
+-    print list(results)
+-    print 'Time to get the first results:', time.time() - start
++    print(list(results))
++    print('Time to get the first results: {:f}'.format(time.time() - start))
+ 
+     # Built-in map example
+-    print map(add, [1, 2, 3], [4, 5, 6], [7, 8, 9])
++    print(list(map(add, [1, 2, 3], [4, 5, 6], [7, 8, 9])))
+ 
+     # Trivial ppmap tests
+     for i in range(10):
+-        print '-' * 30
++        print('-' * 30)
+         start = time.time()
+-        print i, 'adders'
+-        print ppmap(i, add, [1, 2, 3], [4, 5, 6], [7, 8, 9])
+-        print 'Iteration time:', time.time() - start
++        print('{:d} adders'.format(i))
++        print(list(ppmap(i, add, [1, 2, 3], [4, 5, 6], [7, 8, 9])))
++        print('Iteration time: {:f}'.format(time.time() - start))
+ 
+     # Heavier ppmap tests
+     for i in range(10):
+-        print '-' * 30
++        print('-' * 30)
+         start = time.time()
+-        print i, 'beavers'
+-        print ppmap(i, busybeaver, range(10))
+-        print 'Iteration time:', time.time() - start
++        print('{:d} beavers'.format(i))
++        print(list(ppmap(i, busybeaver, range(10))))
++        print('Iteration time: {:f}'.format(time.time() - start))
+--- python-cobra.orig/cobra/mlab/mlab.py
++++ python-cobra/cobra/mlab/mlab.py
+@@ -1,5 +1,6 @@
+ #cobra.mlab.py
+ #System modules
++from __future__ import print_function
+ import cPickle, numpy, os, cobra, warnings
+ from copy import deepcopy
+ from scipy.sparse import dok_matrix
+@@ -48,7 +49,7 @@
+                     break
+     if not os.path.isfile(os.path.join(matlab_cobra_path,
+                            "initCobraToolbox.m")):
+-        print "initCobraToolbox not found in given path"
++        print("initCobraToolbox not found in given path")
+         return
+     # store the current directory so we can return to it
+     curdir = os.path.abspath(os.curdir)
+@@ -83,7 +84,7 @@
+     try:
+         import mlabwrap
+     except ImportError:
+-        print 'Could not import mlabwrap: ' + ImportError + '\n'
++        print('Could not import mlabwrap: ' + ImportError + '\n')
+         return False
+     #the_list = mlabwrap.mlab.cell_to_string(the_cell).rstrip('\t').split('\t')
+     #Because the mlabwrap.mlab.cell_to_string function will end with a tab, it must
+@@ -96,7 +97,7 @@
+     try:
+         import mlabwrap
+     except ImportError:
+-        print 'Could not import mlabwrap: ' + ImportError + '\n'
++        print('Could not import mlabwrap: ' + ImportError + '\n')
+         return False
+     if mlabwrap.mlab.double(the_logical)[0][0] == 1:
+         return True
+@@ -107,7 +108,7 @@
+     try:
+         import mlabwrap
+     except ImportError:
+-        print 'Could not load mlabwrap ' + ImportError + '\n'
++        print('Could not load mlabwrap ' + ImportError + '\n')
+         return False
+     if hasattr(the_list[0], 'id'):
+         the_list = [x.id for x in the_list]
+@@ -124,7 +125,7 @@
+         import mlabwrap
+         import scipy.sparse
+     except ImportError:
+-        print 'Could not load mlabwrap or scipy ' + ImportError + '\n'
++        print('Could not load mlabwrap or scipy ' + ImportError + '\n')
+         return False
+     [row_indices, column_indices, the_values] = mlabwrap.mlab.find(matlab_sparse_matrix , nout = 3)
+     #Change to 0-based indices
+@@ -148,7 +149,7 @@
+     try:
+         import mlabwrap
+     except ImportError:
+-        print 'Could not load mlabwrap ' + ImportError + '\n'
++        print('Could not load mlabwrap ' + ImportError + '\n')
+         return False
+     return mlabwrap.mlab.sparse(scipy_sparse_matrix.todense())
+ 
+@@ -157,7 +158,7 @@
+         import mlabwrap
+         import numpy
+     except ImportError:
+-        print 'Could not load mlabwrap or numpy ' + ImportError + '\n'
++        print('Could not load mlabwrap or numpy ' + ImportError + '\n')
+         return False
+     [row_indices, column_indices, the_values] = mlabwrap.mlab.find(matlab_sparse_matrix , nout = 3)
+     #Change to 0-based indices
+@@ -176,7 +177,7 @@
+     try:
+         import mlabwrap
+     except ImportError:
+-        print 'Could not load mlabwrap ' + ImportError + '\n'
++        print('Could not load mlabwrap ' + ImportError + '\n')
+         return False
+ 
+     return mlabwrap.mlab.sparse(numpy_array)
+@@ -398,8 +399,8 @@
+     matlab_result = matlab.optimizeCbModel(matlab_struct)
+     matlab_solution = repr(float(matlab_result.f))
+     if py_cobra_solution[:4] == matlab_solution[:4]:
+-        print 'SUCCESS: growth rate match between pyCOBRA and COBRA Toolbox: %s ~ %s'%(py_cobra_solution,
+-                                                                                       matlab_solution)
++        print('SUCCESS: growth rate match between pyCOBRA and COBRA Toolbox: '
++              '{:s} ~ {:s}'.format(py_cobra_solution, matlab_solution))
+     else:
+-        print 'FAILURE: pyCOBRA and COBRA Toolbox do not match: %s !~ %s'%(py_cobra_solution,
+-                                                                                       matlab_solution)
++        print('FAILURE: pyCOBRA and COBRA Toolbox do not match: '
++              '{:s} !~ {:s}'.format(py_cobra_solution, matlab_solution))
+--- python-cobra.orig/cobra/solvers/cplex_solver_java.py
++++ python-cobra/cobra/solvers/cplex_solver_java.py
+@@ -1,6 +1,7 @@
+ #cobra.solvers.cplex_solver
+ #Interface to ilog/cplex 12.4 python / jython interfaces
+ #QPs are not yet supported under jython
++from __future__ import print_function
+ from os import name as __name
+ from copy import deepcopy
+ from warnings import warn
+@@ -315,7 +316,7 @@
+ 
+     the_solution = format_solution(lp, cobra_model)
+     if status != 'optimal' and error_reporting:
+-        print '%s failed: %s'%(solver_name, status)
++        print('{:s} failed: {:s}'.format(solver_name, status))
+     cobra_model.solution = the_solution
+     solution = {'the_problem': lp, 'the_solution': the_solution}
+     return solution
+--- python-cobra.orig/cobra/solvers/glpk_solver_java.py
++++ python-cobra/cobra/solvers/glpk_solver_java.py
+@@ -1,5 +1,6 @@
+ ##cobra.solvers.glpk_solver
+ #This script provides wrappers for libglpk-java 1.0.22 and pyglpk 0.3
++from __future__ import print_function
+ from warnings import warn
+ from copy import deepcopy
+ ###solver specific parameters
+@@ -83,18 +84,18 @@
+             try:
+                 setattr(self._simplex_parameters, parameter_name,
+                         parameter_value)
+-            except Exception, e1:
++            except Exception as e1:
+                 try:
+                     setattr(self._mip_parameters, parameter_name,
+                             parameter_value)
+-                except Exception, e2:
++                except Exception as e2:
+                     if warning:
+-                        print "Could not set simplex parameter " +\
+-                              "%s: %s"%(parameter_name, repr(e1))
++                        print("Could not set simplex parameter " +\
++                              "{:s}: {:s}".format(parameter_name, repr(e1)))
+                         
+                         if self._mip_parameters is not None:
+-                            print "Could not set mip parameter " +\
+-                                  "%s: %s"%(parameter_name, repr(e2))
++                            print("Could not set mip parameter " +\
++                                  "{:s}: {:s}".format(parameter_name, repr(e2)))
+     def get_objective_value(self):
+         if self._mip:
+             tmp_value = self._g.glp_mip_obj_val(self._lp)
+@@ -222,8 +223,8 @@
+             y_dict = dict(zip(cobra_model.metabolites, y))
+         
+             objective_value = lp.objective_value
+-        except Exception, e:
+-            print repr(e)
++        except Exception as e:
++            print(repr(e))
+             y = y_dict = x = x_dict = objective_value = None
+             #print status
+     else:
+@@ -298,7 +299,7 @@
+     lp.solve()
+     status = get_status(lp)
+     if print_solver_time:
+-        print 'optimize time: %f'%(time() - start_time)
++        print('optimize time: {:f}'.format(time() - start_time))
+     return status
+ 
+     
+@@ -359,7 +360,7 @@
+     
+     the_solution = format_solution(lp, cobra_model)
+     if status != 'optimal' and error_reporting:
+-        print '%s failed: %s'%(solver_name, status)
++        print('{:s} failed: {:s}'.format(solver_name, status))
+     cobra_model.solution = the_solution
+     solution = {'the_problem': lp, 'the_solution': the_solution}
+     return solution
+--- python-cobra.orig/cobra/solvers/gurobi_solver_java.py
++++ python-cobra/cobra/solvers/gurobi_solver_java.py
+@@ -1,6 +1,7 @@
+ ##cobra.solvers.gurobi_solver
+ #Interface to the gurobi 5.0.1 python and java solvers
+ #QPs are not yet supported on java
++from __future__ import print_function
+ from warnings import warn
+ from os import name as __name
+ from copy import deepcopy
+@@ -70,7 +71,7 @@
+         else:
+             warn("%s is not a DoubleParam, IntParam, StringParam, IntAttr"%parameter_name)
+             ## raise Exception("%s is not a DoubleParam, IntParam, StringParam, IntAttr"%parameter_name)
+-    except Exception, e:
++    except Exception as e:
+         warn("%s %s didn't work %s"%(parameter_name, parameter_value, e))
+ 
+ def get_objective_value(lp):
+@@ -213,7 +214,7 @@
+     lp.optimize()
+     status = get_status(lp)
+     if print_solver_time:
+-        print 'optimize time: %f'%(time() - start_time)
++        print('optimize time: {:f}'.format(time() - start_time))
+     return status
+ 
+     
+@@ -274,7 +275,7 @@
+     status = solve_problem(lp, **the_parameters)
+     the_solution = format_solution(lp, cobra_model)
+     if status != 'optimal' and error_reporting:
+-        print '%s failed: %s'%(solver_name, status)
++        print('{:s} failed: {:s}'.format(solver_name, status))
+     cobra_model.solution = the_solution
+     solution = {'the_problem': lp, 'the_solution': the_solution}
+     return solution
+--- python-cobra.orig/cobra/topology/reporter_metabolites.py
++++ python-cobra/cobra/topology/reporter_metabolites.py
+@@ -1,6 +1,7 @@
+ #cobra.topology.reporter_metabolites.py: Module for topological analysis of cobra_models
+ #Based on Patil et al 2005 PNAS 102:2685-9
+ #TODO: Validate cobra.core compliance
++from __future__ import print_function
+ from copy import deepcopy
+ from numpy import array, corrcoef, mean, std, tril, where, unique, zeros
+ from scipy.stats import norm, randint
+@@ -162,4 +163,4 @@
+     tmp_reps = identify_reporter_metabolites(cobra_model, reaction_scores_dict,
+                                              background_correction=True)
+ 
+-    print 'Need to add in validation for the test'
++    print('Need to add in validation for the test')
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..93f6e2e
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+improve-python3-support.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-cobra.git



More information about the debian-med-commit mailing list