For example, in the config I might have
[mytask]
param_a = file.txt
and then in my script:
class mytask(luigi.Task):
param_a = luigi.Parameter()
param_b = luigi.Parameter(default=extract_info(param_a))
This allows me to have a default value for param_b if it is undefined in the config file, or over-ride that if desired.
I can't see a way to do this, however. We can't actually assign parameters during the initialization phase of a task. At the point where extract_info(param_a) is executed, param_a does not have a value yet, as far as I can tell in my debugger.
Does anyone have any ideas on how this could be accomplished? This goes towards the larger question of dynamic parameters on task instantiation in general.
--
You received this message because you are subscribed to the Google Groups "Luigi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to luigi-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
class MyTask(luigi.Task):param_a = luigi.Parameter()param_b = luigi.Parameter(default=None)def __init__(self, *args, **kwargs):super(MyTask, self).__init__(*args, **kwargs)if self.param_b is None:self.param_b = extract_info(param_a)
This is what i used for myself...
#!/usr/bin/env python2.7
from datetime import datetime, timedelta
import luigi
from luigi import LocalTarget
class FirstTest(luigi.Task):
hours_delay = luigi.IntParameter(default=2)
pdate = luigi.DateSecondParameter(
default=datetime.now() - timedelta(hours=hours_delay.task_value('FirstTest', 'hours_delay')))
def __init__(self, *args, **kwargs):
super(FirstTest, self).__init__(*args, **kwargs)
if self.hours_delay != FirstTest.hours_delay.task_value('FirstTest', 'hours_delay'):
FirstTest.pdate = luigi.DateSecondParameter(
default=datetime.now() - timedelta(hours=self.hours_delay))
super(FirstTest, self).__init__(*args, **kwargs)
def run(self):
print(self.pdate)
def output(self):
return LocalTarget("always_run.txt")
if __name__ == '__main__':
luigi.run(main_task_cls=FirstTest)