File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,10 +25,17 @@ def checkpoint(
2525
2626 cache_pickle_protocol: the pickle protocol used by the cache to save results to the disk.
2727 If None, use the global default `cache.pickle_protocol`
28+
29+ Optionally user can directly decorate the function with `@checkpoint` (without parenthesis),
30+ this will cause the function to be passed in directly with the `directory` parameter.
2831 """
2932
33+ # If true, the `directory` is actually the decorated function
34+ # and the actual `directory` is None
35+ used_without_parenthesis = callable (directory )
36+
3037 identifier = AutoFuncCallIdentifier ()
31- cache = PickleFileCache (directory , cache_pickle_protocol )
38+ cache = PickleFileCache (None if used_without_parenthesis else directory , cache_pickle_protocol )
3239 decorator = DecoratorCheckpoint (identifier , cache , on_error )
3340
34- return decorator
41+ return decorator ( directory ) if used_without_parenthesis else decorator
Original file line number Diff line number Diff line change 11## v1.0.x
22
3- ### v1.0.0
3+ ### v1.0.1
4+
5+ - Added support to decorate a function without parenthesis (` @checkpoint ` instead of ` @checkpoint() ` )
6+ - Thanks for the proposal in https://github.com/Vopaaz/checkpointing/issues/8
7+
8+ ### [ v1.0.0] ( https://checkpointing.readthedocs.io/en/v1.0.0/ )
49
510- Drop support for Python 3.7 to remove the pickle5 dependency
611
Original file line number Diff line number Diff line change 1+ As requested in https://github.com/Vopaaz/checkpointing/issues/8 we are introducing a new syntax
2+ to decorate with ` checkpoint ` without parenthesis.
Original file line number Diff line number Diff line change 1+ Running
2+ 0
Original file line number Diff line number Diff line change 1+ Running
2+ 1
Original file line number Diff line number Diff line change 1+ from checkpointing import checkpoint
2+
3+ @checkpoint
4+ def foo (a ):
5+ print ("Running" )
6+ return a
7+
8+ if __name__ == "__main__" :
9+ print (foo (0 ))
Original file line number Diff line number Diff line change 1+ from checkpointing import checkpoint
2+
3+ @checkpoint
4+ def foo (a ):
5+ print ("Running" )
6+ return a + 1
7+
8+ if __name__ == "__main__" :
9+ print (foo (0 ))
Original file line number Diff line number Diff line change 1+ Running
2+ 1
Original file line number Diff line number Diff line change 1+ 1
Original file line number Diff line number Diff line change 1+ from checkpointing import checkpoint
2+
3+
4+ @checkpoint
5+ def foo (a ):
6+ print ("Running" )
7+ return a
8+
9+
10+ if __name__ == "__main__" :
11+ print (foo (1 ))
You can’t perform that action at this time.
0 commit comments