MCPcopy Create free account
hub / github.com/StackStorm/st2 / PythonRunner

Class PythonRunner

contrib/runners/python_runner/python_runner/python_runner.py:85–472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83
84
85class PythonRunner(GitWorktreeActionRunner):
86 def __init__(
87 self,
88 runner_id,
89 config=None,
90 timeout=PYTHON_RUNNER_DEFAULT_ACTION_TIMEOUT,
91 log_level=None,
92 sandbox=True,
93 use_parent_args=True,
94 ):
95
96 """
97 :param timeout: Action execution timeout in seconds.
98 :type timeout: ``int``
99
100 :param log_level: Log level to use for the child actions.
101 :type log_level: ``str``
102
103 :param sandbox: True to use python binary from pack-specific virtual environment for the
104 child action False to use a default system python binary from PATH.
105 :type sandbox: ``bool``
106
107 :param use_parent_args: True to use command line arguments from the parent process.
108 :type use_parent_args: ``bool``
109 """
110 super(PythonRunner, self).__init__(runner_id=runner_id)
111
112 self._config = config
113 self._timeout = timeout
114 self._enable_common_pack_libs = cfg.CONF.packs.enable_common_libs or False
115 self._log_level = log_level or cfg.CONF.actionrunner.python_runner_log_level
116 self._sandbox = sandbox
117 self._use_parent_args = use_parent_args
118
119 def pre_run(self):
120 super(PythonRunner, self).pre_run()
121
122 # TODO: This is awful, but the way "runner_parameters" and other variables get assigned on
123 # the runner instance is even worse. Those arguments should be passed to the constructor.
124 self._env = self.runner_parameters.get(RUNNER_ENV, {})
125 self._timeout = self.runner_parameters.get(RUNNER_TIMEOUT, self._timeout)
126 self._log_level = self.runner_parameters.get(RUNNER_LOG_LEVEL, self._log_level)
127
128 if self._log_level == PYTHON_RUNNER_DEFAULT_LOG_LEVEL:
129 self._log_level = cfg.CONF.actionrunner.python_runner_log_level
130
131 def run(self, action_parameters):
132 LOG.debug("Running pythonrunner.")
133 LOG.debug("Getting pack name.")
134 pack = self.get_pack_ref()
135 LOG.debug("Getting user.")
136 user = self.get_user()
137 LOG.debug("Serializing parameters.")
138 serialized_parameters = json_encode(
139 action_parameters if action_parameters else {}
140 )
141 LOG.debug("Getting virtualenv_path.")
142 virtualenv_path = get_sandbox_virtualenv_path(pack=pack)

Callers 1

get_runnerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected