From aa2e475fd76f7df86080fccefe6f2a3162d9dc30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 28 Jan 2020 09:48:01 +0100 Subject: [PATCH] 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. --- wcs/ctl/shell.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/wcs/ctl/shell.py b/wcs/ctl/shell.py index adf525c3f..1df31e3df 100644 --- a/wcs/ctl/shell.py +++ b/wcs/ctl/shell.py @@ -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' ]