From 9b4805cc19cfc31e9481c681e14cab21a88a122b Mon Sep 17 00:00:00 2001 From: Patrick Elmer Date: Wed, 28 Dec 2022 11:00:30 +0100 Subject: [PATCH] Change implementation to be callable only with --- src/magicli.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/magicli.py b/src/magicli.py index 45e3c4d..4a479eb 100644 --- a/src/magicli.py +++ b/src/magicli.py @@ -76,3 +76,17 @@ def print_help_and_exit(app_name, functions): words += ['--' + arg for arg in specs.args] print(' '*4 + ' '.join(words)) exit() + + +def first_calling_frame(): + for s in reversed(inspect.stack()): + if s.code_context == None: + continue + if s.code_context[0].startswith('import magicli'): + return s.frame + return None + + +frame = first_calling_frame() +if frame != None: + magicli(glbls=frame.f_globals)