2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-25 11:19:52 +01:00

Accept functools.partial() as a task rule #1862 (#1865)

Accept functools.partial() as task generator rules #1862
This commit is contained in:
Gustavo J. A. M. Carneiro 2016-11-26 10:00:01 +00:00 committed by Thomas Nagy
parent 99d5112da6
commit ac55bf5bf7
2 changed files with 14 additions and 0 deletions

View File

@ -11,6 +11,7 @@ is deferred. To achieve this, various methods are called from the method "apply"
"""
import copy, re, os
from functools import partial
from waflib import Task, Utils, Logs, Errors, ConfigSet, Node
feats = Utils.defaultdict(set)
@ -634,6 +635,13 @@ def process_rule(self):
if getattr(self, 'cwd', None):
tsk.cwd = self.cwd
if type(tsk.run) is partial:
# Python documentation says: "partial objects defined in classes
# behave like static methods and do not transform into bound
# methods during instance attribute look-up."
tsk.run = partial(tsk.run, tsk)
@feature('seq')
def sequence_order(self):
"""

View File

@ -10,6 +10,8 @@ through Python versions 2.5 to 3.X and across different platforms (win32, linux,
"""
import os, sys, errno, traceback, inspect, re, datetime, platform, base64, signal
import functools
try:
import cPickle
except ImportError:
@ -604,6 +606,10 @@ def h_cmd(ins):
elif isinstance(ins, list) or isinstance(ins, tuple):
# or a list of functions/strings
ret = str([h_cmd(x) for x in ins])
elif isinstance(ins, functools.partial):
ret = str([h_list(ins.args),
h_list(tuple(ins.keywords.items())),
h_fun(ins.func)])
else:
# or just a python function
ret = str(h_fun(ins))