# This file is part of Pimlico
# Copyright (C) 2020 Mark Granroth-Wilding
# Licensed under the GNU LGPL v3.0 - https://www.gnu.org/licenses/lgpl-3.0.en.html
"""
Basic set of shell commands that are always available.
"""
from __future__ import print_function
from pimlico.cli.shell.base import ShellCommand
[docs]class PythonCmd(ShellCommand):
commands = ["python", "py"]
help_text = "Run a Python interpreter using the current environment, including import availability of " \
"all the project code, as well as the dataset in the 'data' variable"
[docs] def execute(self, shell, *args, **kwargs):
from code import interact
import sys
# Customize the prompt so we see that we're in the interpreter
sys.ps1 = "py>> "
sys.ps2 = "py.. "
print("Entering Python interpreter. Type Ctrl+D to exit\n")
# Enter the interpreter
interact(local=shell.env)
print("Leaving Python interpreter")
BASIC_SHELL_COMMANDS = [MetadataCmd(), PythonCmd()]