allpy
changeset 1074:87ba56d634cf
Replaced allpy.util.Binder with functools.partial everywhere (functools.partial is 2.5-compatible)
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Fri, 25 May 2012 20:28:00 +0400 |
parents | 22b719ab88c5 |
children | 3c32489fcb3b |
files | allpy/util.py pair_cores/against-database.py pair_cores/pair_cores_all.py |
diffstat | 3 files changed, 5 insertions(+), 16 deletions(-) [+] |
line diff
1.1 --- a/allpy/util.py Fri May 25 20:12:23 2012 +0400 1.2 +++ b/allpy/util.py Fri May 25 20:28:00 2012 +0400 1.3 @@ -59,15 +59,4 @@ 1.4 self.__dict__ = self.module.__dict__ 1.5 return self.__dict__[attr] 1.6 1.7 -class Binder(object): 1.8 - def __init__(self, func, *args, **kwargs): 1.9 - self.func = func 1.10 - self.args = args 1.11 - self.kwargs = kwargs 1.12 - def __call__(self): 1.13 - try: 1.14 - self.func(*self.args, **self.kwargs) 1.15 - except Exception, e: 1.16 - sys.stderr.write("%s: %s\n" % (e.__class__, e)) 1.17 - 1.18 # vim: set et ts=4 sts=4 sw=4:
2.1 --- a/pair_cores/against-database.py Fri May 25 20:12:23 2012 +0400 2.2 +++ b/pair_cores/against-database.py Fri May 25 20:28:00 2012 +0400 2.3 @@ -5,11 +5,11 @@ 2.4 import warnings 2.5 import argparse 2.6 import multiprocessing as mp 2.7 +from functools import partial 2.8 2.9 from pair_cores_all import homology_from_markup_all 2.10 score_all = __import__('score-all').score_all 2.11 from allpy.homology import MonomerHomology as MH 2.12 -from allpy.util import Binder 2.13 from allpy.structure import CachedDownloadPdb 2.14 2.15 def makedirs(d): 2.16 @@ -30,10 +30,10 @@ 2.17 case_tasks = [] 2.18 for f in glob.glob(os.path.join(markups_dir, mask)): 2.19 f = os.path.basename(f) 2.20 - case_tasks.append(Binder(case_homology, 2.21 + case_tasks.append(partial(case_homology, 2.22 os.path.join(markups_dir, f), 2.23 os.path.join(output_dir, case, f+suffix), True)) 2.24 - case_tasks.append(Binder(case_homology, 2.25 + case_tasks.append(partial(case_homology, 2.26 os.path.join(markups_dir, f), 2.27 os.path.join(output_dir, no_case, f+suffix), False)) 2.28 jobs = jobs or mp.cpu_count()
3.1 --- a/pair_cores/pair_cores_all.py Fri May 25 20:12:23 2012 +0400 3.2 +++ b/pair_cores/pair_cores_all.py Fri May 25 20:28:00 2012 +0400 3.3 @@ -5,9 +5,9 @@ 3.4 import multiprocessing as mp 3.5 import argparse 3.6 import glob 3.7 +from functools import partial 3.8 3.9 from pair_cores import homology_from_3d, CachedDownloadPdb, cached_download_pdb 3.10 -from allpy.util import Binder 3.11 3.12 MAX_GLOBS = 10 3.13 3.14 @@ -68,7 +68,7 @@ 3.15 for file in files: 3.16 path = os.path.join(input_dir, file) 3.17 if os.path.isfile(path): 3.18 - tasks.append(Binder(func, input_filename=path, 3.19 + tasks.append(partial(func, input_filename=path, 3.20 homology_filename=os.path.join(output_dir, file+suffix), 3.21 max_delta=max_delta, pdb_getter=pdb_getter)) 3.22 cpu_count = cpu_count or mp.cpu_count()