Commit 3035b737 authored by Halla Rempt's avatar Halla Rempt

Update scripter to allow running of scripts without a main() function

Allow scripter to play main()-less scripts without complaining

If a script is typed into the scripter window interactively and saved, scripter keeps a record of the file and automatically loads the script on the next run. When you press play on this auto-loaded script the runner module tries to load the module, then run it's main() method. However, an interactive script may not have a main method.  Scripter should run main() if it's present, but fail silently if it is not present.

Test Plan:
Not sure what to put here.
To trigger the initial bug Run krita, run scripter, create a script without main, save the script then press the play button.

Reviewers: #krita, woltherav

Reviewed By: #krita, woltherav

Subscribers: alvinhochun, rempt, eliakinalmeida, woltherav

Tags: #krita

Differential Revision:
parents a1d73ab3 0ba75097
......@@ -56,7 +56,14 @@ class RunAction(QAction):
spec = importlib.util.spec_from_file_location("users_script", document.filePath)
users_module = importlib.util.module_from_spec(spec)
# maybe script is to be execed, maybe main needs to be invoked
# if there is a main() then execute it, otherwise don't worry...
except AttributeError:
code = compile(script, '<string>', 'exec')
exec(script, {})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment