Some fixes for spack-python interpreter mode.
This commit is contained in:
parent
4b960c131b
commit
a7fd8be514
@ -22,20 +22,24 @@
|
|||||||
# along with this program; if not, write to the Free Software Foundation,
|
# along with this program; if not, write to the Free Software Foundation,
|
||||||
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
##############################################################################
|
##############################################################################
|
||||||
import code
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import code
|
||||||
|
import argparse
|
||||||
import platform
|
import platform
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
|
|
||||||
import spack
|
import spack
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
subparser.add_argument('file', nargs='?', help="file to run")
|
subparser.add_argument(
|
||||||
|
'python_args', nargs=argparse.REMAINDER, help="File to run plus arguments.")
|
||||||
|
|
||||||
description = "Launch an interpreter as spack would launch a command"
|
description = "Launch an interpreter as spack would launch a command"
|
||||||
|
|
||||||
def python(parser, args):
|
def python(parser, args):
|
||||||
console = code.InteractiveConsole()
|
# Fake a main python shell by setting __name__ to __main__.
|
||||||
|
console = code.InteractiveConsole({'__name__' : '__main__'})
|
||||||
|
|
||||||
if "PYTHONSTARTUP" in os.environ:
|
if "PYTHONSTARTUP" in os.environ:
|
||||||
startup_file = os.environ["PYTHONSTARTUP"]
|
startup_file = os.environ["PYTHONSTARTUP"]
|
||||||
@ -43,9 +47,11 @@ def python(parser, args):
|
|||||||
with closing(open(startup_file)) as startup:
|
with closing(open(startup_file)) as startup:
|
||||||
console.runsource(startup.read(), startup_file, 'exec')
|
console.runsource(startup.read(), startup_file, 'exec')
|
||||||
|
|
||||||
if args.file:
|
python_args = args.python_args
|
||||||
with closing(open(args.file)) as file:
|
if python_args:
|
||||||
console.runsource(file.read(), args.file, 'exec')
|
sys.argv = python_args
|
||||||
|
with closing(open(python_args[0])) as file:
|
||||||
|
console.runsource(file.read(), python_args[0], 'exec')
|
||||||
else:
|
else:
|
||||||
console.interact("Spack version %s\nPython %s, %s %s"""
|
console.interact("Spack version %s\nPython %s, %s %s"""
|
||||||
% (spack.spack_version, platform.python_version(),
|
% (spack.spack_version, platform.python_version(),
|
||||||
|
Loading…
Reference in New Issue
Block a user