ctl: port shell command for python 3 (#39317)

Command was initially copied/adapted from Django, this is an almost straight
cherrypick of later commit 723c9a8c6db60108f584972498fa6bbd3b408444.
This commit is contained in:
Frédéric Péters 2020-01-28 09:48:01 +01:00
parent 1b7299db0c
commit aa2e475fd7
1 changed files with 9 additions and 9 deletions

View File

@ -69,16 +69,16 @@ class CmdShell(Command):
readline.parse_and_bind("tab:complete")
# We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
# conventions and get $PYTHONSTARTUP first then import user.
# conventions and get $PYTHONSTARTUP first then .pythonrc.py.
if not sub_options.plain:
pythonrc = os.environ.get("PYTHONSTARTUP")
if pythonrc and os.path.isfile(pythonrc):
try:
execfile(pythonrc)
except NameError:
pass
# This will import .pythonrc.py as a side-effect
import user
for pythonrc in (os.environ.get("PYTHONSTARTUP"),
os.path.expanduser('~/.pythonrc.py')):
if pythonrc and os.path.isfile(pythonrc):
try:
with open(pythonrc) as handle:
exec(compile(handle.read(), pythonrc, 'exec'))
except NameError:
pass
code.interact(local=imported_objects)
shells = [ 'ipython', 'bpython' ]