44 'SCRIPT_INFO' , 'call_parse' ]
55
66# Cell
7- import inspect ,functools ,argparse ,shutil
7+ import inspect ,argparse ,shutil
8+ from functools import wraps ,partial
89from .imports import *
910from .utils import *
1011from .docments import docments
@@ -97,12 +98,9 @@ def args_from_prog(func, prog):
9798# Cell
9899def call_parse (func = None , nested = False ):
99100 "Decorator to create a simple CLI from `func` using `anno_parser`"
100- if func is None : return functools . partial (call_parse , nested = nested )
101+ if func is None : return partial (call_parse , nested = nested )
101102
102- mod = inspect .getmodule (inspect .currentframe ().f_back )
103- if not mod : return func
104-
105- @functools .wraps (func )
103+ @wraps (func )
106104 def _f (* args , ** kwargs ):
107105 mod = inspect .getmodule (inspect .currentframe ().f_back )
108106 if not mod : return func (* args , ** kwargs )
@@ -114,9 +112,10 @@ def _f(*args, **kwargs):
114112 args = args .__dict__
115113 xtra = otherwise (args .pop ('xtra' , '' ), eq (1 ), p .prog )
116114 tfunc = trace (func ) if args .pop ('pdb' , False ) else func
117- tfunc (** merge (args , args_from_prog (func , xtra )))
115+ return tfunc (** merge (args , args_from_prog (func , xtra )))
118116
119- if mod .__name__ == "__main__" :
117+ mod = inspect .getmodule (inspect .currentframe ().f_back )
118+ if getattr (mod , __name__ , '' ) == "__main__" :
120119 setattr (mod , func .__name__ , _f )
121120 SCRIPT_INFO .func = func .__name__
122121 return _f ()
0 commit comments