Created
November 21, 2015 16:32
-
-
Save drj42/c22808a141761356c733 to your computer and use it in GitHub Desktop.
TaskParameter quirks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import luigi | |
class Foo(luigi.Task): | |
message = 'Foo' | |
class RunOnceTask(luigi.Task): | |
my_task = luigi.TaskParameter() | |
_comp = False | |
def complete(self): | |
return RunOnceTask._comp | |
def run(self): | |
print('\n==> TASK:{}, TYPE:{}\n'.format( | |
self.my_task, type(self.my_task))) | |
RunOnceTask._comp = True | |
# Task param passed as class name | |
class A1(luigi.Task): | |
"""Works as expected.""" | |
def requires(self): | |
yield RunOnceTask(my_task=Foo) | |
class A2(luigi.Task): | |
"""But then this fails... luigi.task_register.TaskClassNotFoundException""" | |
def run(self): | |
yield RunOnceTask(my_task=Foo) | |
# Task class passed as string | |
class B1(luigi.Task): | |
"""Task runs, but task parameter is parsed as a string, not task.""" | |
def requires(self): | |
yield RunOnceTask(my_task='Foo') | |
class B2(luigi.Task): | |
"""Works. Task string converted to task class.""" | |
def run(self): | |
yield RunOnceTask(my_task='Foo') | |
if __name__ == '__main__': | |
luigi.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment