Skip to content

Commit e0b1efa

Browse files
committed
fixes #435
1 parent c3f3dd7 commit e0b1efa

File tree

3 files changed

+63
-77
lines changed

3 files changed

+63
-77
lines changed

fastcore/script.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
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
89
from .imports import *
910
from .utils import *
1011
from .docments import docments
@@ -97,12 +98,9 @@ def args_from_prog(func, prog):
9798
# Cell
9899
def 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

Comments
 (0)