-
Notifications
You must be signed in to change notification settings - Fork 335
Allow for other PythonScriptEngine environments besides task data #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
danfunk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this.
| # 02110-1301 USA | ||
|
|
||
|
|
||
| class Box(dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like giving people the option of not using Box.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should deprecate box too. The ultimate goal here should be to provide a default that does nothing but execute and evaluate with the task data added to the context, with no additional changes to anything outside of execution/evaluation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a deprecation warning and a BoxedTaskDataEnvironment if consumers need/want it. Updated two tests that relied on Box to use this new environment.
|
|
||
| self.globals = default_globals or {} | ||
| self.globals.update(scripting_additions or {}) | ||
| def __init__(self, default_globals=None, scripting_additions=None, environment=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the environment is passed in, why would continue to accept default_globals and default_additions as separate arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for backwards compatibility of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should log some sort of deprecation warning, so we can move people away from this in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the warning and updated tests that used default_globals/scripting_additions.
| @@ -0,0 +1,112 @@ | |||
| import copy | |||
|
|
|||
| class BasePythonScriptEngineEnvironment: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the interface I always wanted for SpiffWorkflows Python execution. Really beautiful.
|
Kudos, SonarCloud Quality Gate passed! |








Opening this as a draft while I test more and work on back end integration to start to gather feedback on the approach. Names and new public apis might be tweaked along the way.Edit: ready for review.The current usage of task data to track the environment for the PythonScriptEngine is convenient but does lend itself to growing task data as the environment is copied from task to task. Larger workflows can run into issues with their task data size. This change provides a way for applications utilizing SpiffWorkflow to provide their own mechanism for tracking the state of the PythonScriptEngine between executions. If nothing is done the library works as it currently does.
Box was moved from the PythonScriptEngine proper to the PythonScriptEngineEnvrionment since custom environments may or may not want to Box.
If a custom environment is provided the application needs to properly restore it like it would for a PythonScriptEngine instance.