From ef66785dd2e877f7237aeea9c4c63810bfef092a Mon Sep 17 00:00:00 2001 From: Luis Pedro Coelho Date: Thu, 22 Feb 2024 13:16:55 +1000 Subject: [PATCH] ENH Support lambdas in Tasklets --- ChangeLog | 3 +++ docs/source/tasklets.rst | 3 +++ jug/task.py | 4 ++-- jug/tests/jugfiles/tasklets.py | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef778103..270b392f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +Unreleased + * Support for lambda functions in Tasklets + Version 2.3.1 Sun 5 November 2023 by luispedro * jug: update for Python 3.12 diff --git a/docs/source/tasklets.rst b/docs/source/tasklets.rst index e9dfb462..f90d3479 100644 --- a/docs/source/tasklets.rst +++ b/docs/source/tasklets.rst @@ -4,6 +4,9 @@ Tasklets .. versionadded:: 0.8 Tasklets were added in version 0.8, starting with the betas (named 0.7.9..) +.. versionchanged:: 2.4.0 + Since version 2.4.0, Tasklets can use a lambda function + A Tasklet is a light-weight task. It looks very similar to a Task *except that it does not save its results to disk*. Every time you need its output, it is recomputed. Other than that, you can pass it around, just like a Task. diff --git a/jug/task.py b/jug/task.py index 4d7bc96c..699903e4 100644 --- a/jug/task.py +++ b/jug/task.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2008-2021, Luis Pedro Coelho +# Copyright (C) 2008-2024, Luis Pedro Coelho # vim: set ts=4 sts=4 sw=4 expandtab smartindent: # LICENSE: MIT ''' @@ -440,7 +440,7 @@ def __jug_hash__(self): M.update(b'Tasklet') hash_update(M, [ ('base', self.base), - ('f', self.f), + ('f', self.f if getattr(self.f, '__name__', '') != '' else ('', self.f.__code__.co_code)) ]) return M.hexdigest().encode('utf-8') diff --git a/jug/tests/jugfiles/tasklets.py b/jug/tests/jugfiles/tasklets.py index 7c962287..e7813b9c 100644 --- a/jug/tests/jugfiles/tasklets.py +++ b/jug/tests/jugfiles/tasklets.py @@ -15,4 +15,6 @@ def plus1(x): t2 = t[2] t0_2 = Task(sum2, t0, t2) t0_2_1 = Tasklet(t0_2, plus1) +t0_2_2 = Tasklet(t0_2_1, lambda x: x + 1) +final = Task(sum2, t0_2_1, t0_2_2)