Python Jupyter Environment¶
- class oscopilot.environments.py_jupyter_env.AddLinePrints[source]¶
Bases:
NodeTransformerTransformer to insert print statements indicating the line number before every executable line in the AST.
- insert_print_statement(line_number)[source]¶
Inserts a print statement for a given line number.
- Parameters:
line_number (int) – The line number.
- Returns:
The print statement AST node.
- Return type:
ast.Expr
- class oscopilot.environments.py_jupyter_env.PythonJupyterEnv[source]¶
Bases:
BaseEnvA class representing an environment for executing Python code in a Jupyter environment.
This class manages the execution of Python code using IPython kernel, providing methods for preprocessing code, executing code steps, handling output messages, and terminating the kernel.
It inherits from BaseEnv, which provides basic environment functionality.
- aliases = ['py', 'API']¶
- detect_active_line(line)[source]¶
Detects active line markers in the output line.
- Parameters:
line (str) – The output line from the IPython kernel.
- Returns:
The modified line and active line number, if detected.
- Return type:
tuple
- file_extension = 'py'¶
- name = 'Python'¶
- preprocess_code(code)[source]¶
Preprocesses the Python code before execution.
- Parameters:
code (str) – The Python code to preprocess.
- Returns:
The preprocessed code.
- Return type:
str
- oscopilot.environments.py_jupyter_env.add_active_line_prints(code)[source]¶
Adds print statements indicating line numbers to a Python string.
- Parameters:
code (str) – The Python code.
- Returns:
The code with added print statements.
- Return type:
str