Class: Daytona::SandboxPythonCodeToolbox
- Inherits:
-
Object
- Object
- Daytona::SandboxPythonCodeToolbox
- Defined in:
- lib/daytona/code_toolbox/sandbox_python_code_toolbox.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
-
#get_run_command(code, params = nil) ⇒ String
Get the run command for executing Python code.
Instance Method Details
#get_run_command(code, params = nil) ⇒ String
Get the run command for executing Python code
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/daytona/code_toolbox/sandbox_python_code_toolbox.rb', line 12 def get_run_command(code, params = nil) encoded_code = Base64.encode64(code) # Override plt.show() method if matplotlib is imported if matplotlib_imported?(code) encoded_code = Base64.encode64( Base64.decode64(PYTHON_CODE_WRAPPER).gsub('{encoded_code}', encoded_code) ) end argv = params&.argv&.join(' ') || '' # Execute the bootstrapper code directly # Use -u flag to ensure unbuffered output for real-time error reporting " sh -c 'python3 -u -c \"exec(__import__(\\\"base64\\\").b64decode(\\\"\\\"\\\"#{encoded_code}\\\"\\\"\\\")" \ ".decode())\" #{argv}' " end |