本文整理汇总了Python中waflib.Task类的典型用法代码示例。如果您正苦于以下问题:Python Task类的具体用法?Python Task怎么用?Python Task使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Task类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_rule
def process_rule(self):
if not getattr(self,'rule',None):
return
name=str(getattr(self,'name',None)or self.target or self.rule)
cls=Task.task_factory(name,self.rule,getattr(self,'vars',[]),shell=getattr(self,'shell',True),color=getattr(self,'color','BLUE'))
tsk=self.create_task(name)
if getattr(self,'target',None):
if isinstance(self.target,str):
self.target=self.target.split()
if not isinstance(self.target,list):
self.target=[self.target]
for x in self.target:
if isinstance(x,str):
tsk.outputs.append(self.path.find_or_declare(x))
else:
x.parent.mkdir()
tsk.outputs.append(x)
if getattr(self,'install_path',None):
self.bld.install_files(self.install_path,tsk.outputs)
if getattr(self,'source',None):
tsk.inputs=self.to_nodes(self.source)
self.source=[]
if getattr(self,'scan',None):
cls.scan=self.scan
if getattr(self,'cwd',None):
tsk.cwd=self.cwd
if getattr(self,'update_outputs',None)or getattr(self,'on_results',None):
Task.update_outputs(cls)
if getattr(self,'always',None):
Task.always_run(cls)
for x in['after','before','ext_in','ext_out']:
setattr(cls,x,getattr(self,x,[]))
示例2: set_precedence_constraints
def set_precedence_constraints(tasks):
cstr_groups = Utils.defaultdict(list)
for x in tasks:
x.run_after = SetOfTasks(x)
x.run_after_groups = []
x.waiting_sets = []
h = x.hash_constraints()
cstr_groups[h].append(x)
# create sets which can be reused for all tasks
for k in cstr_groups.keys():
cstr_groups[k] = set(cstr_groups[k])
# this list should be short
for key1, key2 in itertools.combinations(cstr_groups.keys(), 2):
group1 = cstr_groups[key1]
group2 = cstr_groups[key2]
# get the first entry of the set
t1 = next(iter(group1))
t2 = next(iter(group2))
# add the constraints based on the comparisons
if Task.is_before(t1, t2):
for x in group2:
x.run_after_groups.append(group1)
for k in group1:
k.waiting_sets.append(group1)
elif Task.is_before(t2, t1):
for x in group1:
x.run_after_groups.append(group2)
for k in group2:
k.waiting_sets.append(group2)
示例3: process_rule
def process_rule(self):
if not getattr(self,'rule',None):
return
name=str(getattr(self,'name',None)or self.target or getattr(self.rule,'__name__',self.rule))
try:
cache=self.bld.cache_rule_attr
except AttributeError:
cache=self.bld.cache_rule_attr={}
cls=None
if getattr(self,'cache_rule','True'):
try:
cls=cache[(name,self.rule)]
except KeyError:
pass
if not cls:
cls=Task.task_factory(name,self.rule,getattr(self,'vars',[]),shell=getattr(self,'shell',True),color=getattr(self,'color','BLUE'),scan=getattr(self,'scan',None))
if getattr(self,'scan',None):
cls.scan=self.scan
elif getattr(self,'deps',None):
def scan(self):
nodes=[]
for x in self.generator.to_list(getattr(self.generator,'deps',None)):
node=self.generator.path.find_resource(x)
if not node:
self.generator.bld.fatal('Could not find %r (was it declared?)'%x)
nodes.append(node)
return[nodes,[]]
cls.scan=scan
if getattr(self,'update_outputs',None):
Task.update_outputs(cls)
if getattr(self,'always',None):
Task.always_run(cls)
for x in('after','before','ext_in','ext_out'):
setattr(cls,x,getattr(self,x,[]))
if getattr(self,'cache_rule','True'):
cache[(name,self.rule)]=cls
if getattr(self,'cls_str',None):
setattr(cls,'__str__',self.cls_str)
if getattr(self,'cls_keyword',None):
setattr(cls,'keyword',self.cls_keyword)
tsk=self.create_task(name)
if getattr(self,'target',None):
if isinstance(self.target,str):
self.target=self.target.split()
if not isinstance(self.target,list):
self.target=[self.target]
for x in self.target:
if isinstance(x,str):
tsk.outputs.append(self.path.find_or_declare(x))
else:
x.parent.mkdir()
tsk.outputs.append(x)
if getattr(self,'install_path',None):
self.bld.install_files(self.install_path,tsk.outputs)
if getattr(self,'source',None):
tsk.inputs=self.to_nodes(self.source)
self.source=[]
if getattr(self,'cwd',None):
tsk.cwd=self.cwd
示例4: process_rule
def process_rule(self):
"""
Process the attribute ``rule``. When present, :py:meth:`waflib.TaskGen.process_source` is disabled::
def build(bld):
bld(rule='cp ${SRC} ${TGT}', source='wscript', target='bar.txt')
"""
if not getattr(self, 'rule', None):
return
# create the task class
name = str(getattr(self, 'name', None) or self.target or self.rule)
cls = Task.task_factory(name, self.rule,
getattr(self, 'vars', []),
shell=getattr(self, 'shell', True), color=getattr(self, 'color', 'BLUE'))
# now create one instance
tsk = self.create_task(name)
if getattr(self, 'target', None):
if isinstance(self.target, str):
self.target = self.target.split()
if not isinstance(self.target, list):
self.target = [self.target]
for x in self.target:
if isinstance(x, str):
tsk.outputs.append(self.path.find_or_declare(x))
else:
x.parent.mkdir() # if a node was given, create the required folders
tsk.outputs.append(x)
if getattr(self, 'install_path', None):
# from waf 1.5
# although convenient, it does not 1. allow to name the target file and 2. symlinks
# TODO remove in waf 1.7
self.bld.install_files(self.install_path, tsk.outputs)
if getattr(self, 'source', None):
tsk.inputs = self.to_nodes(self.source)
# bypass the execution of process_source by setting the source to an empty list
self.source = []
if getattr(self, 'scan', None):
cls.scan = self.scan
if getattr(self, 'cwd', None):
tsk.cwd = self.cwd
# TODO remove on_results in waf 1.7
if getattr(self, 'update_outputs', None) or getattr(self, 'on_results', None):
Task.update_outputs(cls)
if getattr(self, 'always', None):
Task.always_run(cls)
for x in ['after', 'before', 'ext_in', 'ext_out']:
setattr(cls, x, getattr(self, x, []))
示例5: declare_chain
def declare_chain(name='',rule=None,reentrant=None,color='BLUE',ext_in=[],ext_out=[],before=[],after=[],decider=None,scan=None,install_path=None,shell=False):
ext_in=Utils.to_list(ext_in)
ext_out=Utils.to_list(ext_out)
if not name:
name=rule
cls=Task.task_factory(name,rule,color=color,ext_in=ext_in,ext_out=ext_out,before=before,after=after,scan=scan,shell=shell)
def x_file(self,node):
ext=decider and decider(self,node)or cls.ext_out
if ext_in:
_ext_in=ext_in[0]
tsk=self.create_task(name,node)
cnt=0
keys=set(self.mappings.keys())|set(self.__class__.mappings.keys())
for x in ext:
k=node.change_ext(x,ext_in=_ext_in)
tsk.outputs.append(k)
if reentrant!=None:
if cnt<int(reentrant):
self.source.append(k)
else:
for y in keys:
if k.name.endswith(y):
self.source.append(k)
break
cnt+=1
if install_path:
self.bld.install_files(install_path,tsk.outputs)
return tsk
for x in cls.ext_in:
task_gen.mappings[x]=x_file
return x_file
示例6: make_interpreted_test
def make_interpreted_test(self):
"""Create interpreted unit tests."""
for x in ['test_scripts_source', 'test_scripts_template']:
if not hasattr(self, x):
Logs.warn('a test_scripts taskgen i missing %s' % x)
return
self.ut_run, lst = Task.compile_fun(self.test_scripts_template, shell=getattr(self, 'test_scripts_shell', False))
script_nodes = self.to_nodes(self.test_scripts_source)
for script_node in script_nodes:
tsk = self.create_task('utest', [script_node])
tsk.vars = lst + tsk.vars
tsk.env['SCRIPT'] = script_node.path_from(tsk.get_cwd())
self.handle_ut_cwd('test_scripts_cwd')
env = getattr(self, 'test_scripts_env', None)
if env:
self.ut_env = env
else:
self.ut_env = dict(os.environ)
paths = getattr(self, 'test_scripts_paths', {})
for (k,v) in paths.items():
p = self.ut_env.get(k, '').split(os.pathsep)
if isinstance(v, str):
v = v.split(os.pathsep)
self.ut_env[k] = os.pathsep.join(p + v)
示例7: make_pytest
def make_pytest(self):
"""
Creates a ``utest`` task with a modified PYTHONPATH environment for Python.
"""
nodes = self.to_nodes(self.pytest_source)
tsk = self.create_task('utest', nodes)
tsk.dep_nodes.extend(self.pytest_dep_nodes)
if getattr(self, 'ut_str', None):
self.ut_run, lst = Task.compile_fun(self.ut_str, shell=getattr(self, 'ut_shell', False))
tsk.vars = lst + tsk.vars
if getattr(self, 'ut_cwd', None):
if isinstance(self.ut_cwd, str):
# we want a Node instance
if os.path.isabs(self.ut_cwd):
self.ut_cwd = self.bld.root.make_node(self.ut_cwd)
else:
self.ut_cwd = self.path.make_node(self.ut_cwd)
else:
if tsk.inputs:
self.ut_cwd = tsk.inputs[0].parent
else:
raise Errors.WafError("no valid input files for pytest task, check pytest_source value")
if not self.ut_cwd.exists():
self.ut_cwd.mkdir()
self.ut_env = dict(os.environ)
self.ut_env['PYTHONPATH'] = os.pathsep.join(self.pytest_paths) + self.ut_env.get('PYTHONPATH', '')
示例8: declare_chain
def declare_chain(
name="",
rule=None,
reentrant=True,
color="BLUE",
ext_in=[],
ext_out=[],
before=[],
after=[],
decider=None,
scan=None,
):
ext_in = Utils.to_list(ext_in)
ext_out = Utils.to_list(ext_out)
cls = Task.task_factory(
name, rule, color=color, ext_in=ext_in, ext_out=ext_out, before=before, after=after, scan=scan
)
def x_file(self, node):
ext = decider and decider(self, node) or cls.ext_out
if ext_in:
_ext_in = ext_in[0]
out_source = [node.change_ext(x, ext_in=_ext_in) for x in ext]
if reentrant:
for i in range(reentrant):
self.source.append(out_source[i])
tsk = self.create_task(name, node, out_source)
for x in cls.ext_in:
task_gen.mappings[x] = x_file
return x_file
示例9: compile_template
def compile_template(line):
"""
Compile a template expression into a python function (like jsps, but way shorter)
"""
extr = []
def repl(match):
g = match.group
if g("dollar"):
return "$"
elif g("backslash"):
return "\\"
elif g("subst"):
extr.append(g("code"))
return "<<|@|>>"
return None
line2 = reg_act.sub(repl, line)
params = line2.split("<<|@|>>")
assert extr
indent = 0
buf = []
app = buf.append
def app(txt):
buf.append(indent * "\t" + txt)
for x in range(len(extr)):
if params[x]:
app("lst.append(%r)" % params[x])
f = extr[x]
if f.startswith("if") or f.startswith("for"):
app(f + ":")
indent += 1
elif f.startswith("py:"):
app(f[3:])
elif f.startswith("endif") or f.startswith("endfor"):
indent -= 1
elif f.startswith("else") or f.startswith("elif"):
indent -= 1
app(f + ":")
indent += 1
elif f.startswith("xml:"):
app("lst.append(xml_escape(%s))" % f[4:])
else:
# app('lst.append((%s) or "cannot find %s")' % (f, f))
app("lst.append(%s)" % f)
if extr:
if params[-1]:
app("lst.append(%r)" % params[-1])
fun = COMPILE_TEMPLATE % "\n\t".join(buf)
# print(fun)
return Task.funex(fun)
示例10: compile_template
def compile_template(line):
"""
Compile a template expression into a python function (like jsps, but way shorter)
"""
extr = []
def repl(match):
g = match.group
if g('dollar'): return "$"
elif g('backslash'):
return "\\"
elif g('subst'):
extr.append(g('code'))
return "<<|@|>>"
return None
line2 = reg_act.sub(repl, line)
params = line2.split('<<|@|>>')
assert(extr)
indent = 0
buf = []
dvars = []
app = buf.append
def app(txt):
buf.append(indent * '\t' + txt)
for x in range(len(extr)):
if params[x]:
app("lst.append(%r)" % params[x])
f = extr[x]
if f.startswith('if') or f.startswith('for'):
app(f + ':')
indent += 1
elif f.startswith('py:'):
app(f[3:])
elif f.startswith('endif') or f.startswith('endfor'):
indent -= 1
elif f.startswith('else') or f.startswith('elif'):
indent -= 1
app(f + ':')
indent += 1
elif f.startswith('xml:'):
app('lst.append(xml_escape(%s))' % f[4:])
else:
#app('lst.append((%s) or "cannot find %s")' % (f, f))
app('lst.append(%s)' % f)
if extr:
if params[-1]:
app("lst.append(%r)" % params[-1])
fun = COMPILE_TEMPLATE % "\n\t".join(buf)
#print(fun)
return Task.funex(fun)
示例11: run
def run(self):
run_str = """mkdir -p ${TGT[0].parent.abspath()} && echo '<?xml version="1.0"?>
<Library DMSystem="oaDMFileSys">
<oaDMFileSys libReadOnly="No"
origFileSystem="Unix"/>
</Library>' >> ${TGT[0].abspath()}"""
(f, dvars) = Task.compile_fun(run_str, False)
return f(self)
示例12: get_build_iterator
def get_build_iterator(self):
"""
Creates a Python generator object that returns lists of tasks that may be processed in parallel.
:return: tasks which can be executed immediatly
:rtype: generator returning lists of :py:class:`waflib.Task.TaskBase`
"""
self.cur = 0
if self.targets and self.targets != '*':
(self._min_grp, self._exact_tg) = self.get_targets()
global lazy_post
if self.post_mode != POST_LAZY:
while self.cur < len(self.groups):
self.post_group()
self.cur += 1
self.cur = 0
while self.cur < len(self.groups):
# first post the task generators for the group
if self.post_mode != POST_AT_ONCE:
self.post_group()
# then extract the tasks
tasks = self.get_tasks_group(self.cur)
# if the constraints are set properly (ext_in/ext_out, before/after)
# the call to set_file_constraints may be removed (can be a 15% penalty on no-op rebuilds)
# (but leave set_file_constraints for the installation step)
#
# if the tasks have only files, set_file_constraints is required but set_precedence_constraints is not necessary
#
Task.set_file_constraints(tasks)
Task.set_precedence_constraints(tasks)
self.cur_tasks = tasks
self.cur += 1
if not tasks: # return something else the build will stop
continue
yield tasks
while 1:
yield []
示例13: get_build_iterator
def get_build_iterator(self):
"""creates a generator object that returns tasks executable in parallel (yield)"""
self.cur = 0
if self.targets and self.targets != '*':
(self._min_grp, self._exact_tg) = self.get_targets()
global lazy_post
if self.post_mode != POST_LAZY:
while self.cur < len(self.groups):
self.post_group()
self.cur += 1
self.cur = 0
while self.cur < len(self.groups):
# first post the task generators for the group
if self.post_mode != POST_AT_ONCE:
self.post_group()
# then extract the tasks
tasks = []
for tg in self.groups[self.cur]:
# TODO a try-except might be more efficient
if isinstance(tg, Task.TaskBase):
tasks.append(tg)
else:
tasks.extend(tg.tasks)
# if the constraints are set properly (ext_in/ext_out, before/after)
# the call to set_file_constraints may be removed (can be a 15% penalty on no-op rebuilds)
# (but leave set_file_constraints for the installation step)
#
# if the tasks have only files, set_file_constraints is required but set_precedence_constraints is not necessary
#
Task.set_file_constraints(tasks)
Task.set_precedence_constraints(tasks)
self.cur += 1
if not tasks: # return something else the build will stop
continue
yield tasks
while 1:
yield []
示例14: declare_chain
def declare_chain(name='', rule=None, reentrant=True, color='BLUE',
ext_in=[], ext_out=[], before=[], after=[], decider=None, scan=None, install_path=None, shell=False):
"""
Create a new mapping and a task class for processing files by extension.
See Tools/flex.py for an example.
:param name: name for the task class
:type name: string
:param rule: function to execute or string to be compiled in a function
:type rule: string or function
:param reentrant: re-inject the output file in the process
:type reentrant: bool
:param color: color for the task output
:type color: string
:param ext_in: execute the task only after the files of such extensions are created
:type ext_in: list of string
:param ext_out: execute the task only before files of such extensions are processed
:type ext_out: list of string
:param before: execute instances of this task before classes of the given names
:type before: list of string
:param after: execute instances of this task after classes of the given names
:type after: list of string
:param decider: if present, use it to create the output nodes for the task
:type decider: function
:param scan: scanner function for the task
:type scan: function
:param install_path: installation path for the output nodes
:type install_path: string
"""
ext_in = Utils.to_list(ext_in)
ext_out = Utils.to_list(ext_out)
if not name:
name = rule
cls = Task.task_factory(name, rule, color=color, ext_in=ext_in, ext_out=ext_out, before=before, after=after, scan=scan, shell=shell)
def x_file(self, node):
ext = decider and decider(self, node) or cls.ext_out
if ext_in:
_ext_in = ext_in[0]
out_source = [node.change_ext(x, ext_in=_ext_in) for x in ext]
if reentrant:
for i in range(reentrant):
self.source.append(out_source[i])
tsk = self.create_task(name, node, out_source)
if install_path:
self.bld.install_files(install_path, out_source)
return tsk
for x in cls.ext_in:
task_gen.mappings[x] = x_file
return x_file
示例15: process_rule
def process_rule(self):
if not getattr(self, "rule", None):
return
name = str(getattr(self, "name", None) or self.target or self.rule)
cls = Task.task_factory(
name,
self.rule,
getattr(self, "vars", []),
shell=getattr(self, "shell", True),
color=getattr(self, "color", "BLUE"),
)
tsk = self.create_task(name)
if getattr(self, "target", None):
if isinstance(self.target, str):
self.target = self.target.split()
if not isinstance(self.target, list):
self.target = [self.target]
for x in self.target:
if isinstance(x, str):
tsk.outputs.append(self.path.find_or_declare(x))
else:
x.parent.mkdir()
tsk.outputs.append(x)
if getattr(self, "install_path", None):
self.bld.install_files(self.install_path, tsk.outputs)
if getattr(self, "source", None):
tsk.inputs = self.to_nodes(self.source)
self.source = []
if getattr(self, "scan", None):
cls.scan = self.scan
if getattr(self, "cwd", None):
tsk.cwd = self.cwd
if getattr(self, "update_outputs", None) or getattr(self, "on_results", None):
Task.update_outputs(cls)
if getattr(self, "always", None):
Task.always_run(cls)
for x in ["after", "before", "ext_in", "ext_out"]:
setattr(cls, x, getattr(self, x, []))