summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/cmd/python.py57
-rw-r--r--lib/spack/spack/cmd/unit_test.py17
-rwxr-xr-xshare/spack/spack-completion.bash2
-rwxr-xr-xshare/spack/spack-completion.fish4
4 files changed, 49 insertions, 31 deletions
diff --git a/lib/spack/spack/cmd/python.py b/lib/spack/spack/cmd/python.py
index 71ce88eed6..a4f177fa38 100644
--- a/lib/spack/spack/cmd/python.py
+++ b/lib/spack/spack/cmd/python.py
@@ -116,39 +116,38 @@ def ipython_interpreter(args):
def python_interpreter(args):
"""A python interpreter is the default interpreter"""
- # Fake a main python shell by setting __name__ to __main__.
- console = code.InteractiveConsole({"__name__": "__main__", "spack": spack})
- if "PYTHONSTARTUP" in os.environ:
- startup_file = os.environ["PYTHONSTARTUP"]
- if os.path.isfile(startup_file):
- with open(startup_file) as startup:
- console.runsource(startup.read(), startup_file, "exec")
- if args.python_command:
- propagate_exceptions_from(console)
- console.runsource(args.python_command)
- elif args.python_args:
- propagate_exceptions_from(console)
+ if args.python_args and not args.python_command:
sys.argv = args.python_args
- with open(args.python_args[0]) as file:
- console.runsource(file.read(), args.python_args[0], "exec")
+ runpy.run_path(args.python_args[0], run_name="__main__")
else:
- # Provides readline support, allowing user to use arrow keys
- console.push("import readline")
- # Provide tabcompletion
- console.push("from rlcompleter import Completer")
- console.push("readline.set_completer(Completer(locals()).complete)")
- console.push('readline.parse_and_bind("tab: complete")')
-
- console.interact(
- "Spack version %s\nPython %s, %s %s"
- % (
- spack.spack_version,
- platform.python_version(),
- platform.system(),
- platform.machine(),
+ # Fake a main python shell by setting __name__ to __main__.
+ console = code.InteractiveConsole({"__name__": "__main__", "spack": spack})
+ if "PYTHONSTARTUP" in os.environ:
+ startup_file = os.environ["PYTHONSTARTUP"]
+ if os.path.isfile(startup_file):
+ with open(startup_file) as startup:
+ console.runsource(startup.read(), startup_file, "exec")
+ if args.python_command:
+ propagate_exceptions_from(console)
+ console.runsource(args.python_command)
+ else:
+ # Provides readline support, allowing user to use arrow keys
+ console.push("import readline")
+ # Provide tabcompletion
+ console.push("from rlcompleter import Completer")
+ console.push("readline.set_completer(Completer(locals()).complete)")
+ console.push('readline.parse_and_bind("tab: complete")')
+
+ console.interact(
+ "Spack version %s\nPython %s, %s %s"
+ % (
+ spack.spack_version,
+ platform.python_version(),
+ platform.system(),
+ platform.machine(),
+ )
)
- )
def propagate_exceptions_from(console):
diff --git a/lib/spack/spack/cmd/unit_test.py b/lib/spack/spack/cmd/unit_test.py
index 2931be5e74..db0c7ff0e5 100644
--- a/lib/spack/spack/cmd/unit_test.py
+++ b/lib/spack/spack/cmd/unit_test.py
@@ -34,6 +34,13 @@ def setup_parser(subparser):
default=False,
help="show full pytest help, with advanced options",
)
+ subparser.add_argument(
+ "-n",
+ "--numprocesses",
+ type=int,
+ default=1,
+ help="run tests in parallel up to this wide, default 1 for sequential",
+ )
# extra spack arguments to list tests
list_group = subparser.add_argument_group("listing tests")
@@ -229,6 +236,16 @@ def unit_test(parser, args, unknown_args):
if args.extension:
pytest_root = spack.extensions.load_extension(args.extension)
+ if args.numprocesses is not None and args.numprocesses > 1:
+ pytest_args.extend(
+ [
+ "--dist",
+ "loadfile",
+ "--tx",
+ f"{args.numprocesses}*popen//python=spack-tmpconfig spack python",
+ ]
+ )
+
# pytest.ini lives in the root of the spack repository.
with llnl.util.filesystem.working_dir(pytest_root):
if args.list:
diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash
index 90d17c5f48..1319d1685f 100755
--- a/share/spack/spack-completion.bash
+++ b/share/spack/spack-completion.bash
@@ -1956,7 +1956,7 @@ _spack_uninstall() {
_spack_unit_test() {
if $list_options
then
- SPACK_COMPREPLY="-h --help -H --pytest-help -l --list -L --list-long -N --list-names --extension -s -k --showlocals"
+ SPACK_COMPREPLY="-h --help -H --pytest-help -n --numprocesses -l --list -L --list-long -N --list-names --extension -s -k --showlocals"
else
_unit_tests
fi
diff --git a/share/spack/spack-completion.fish b/share/spack/spack-completion.fish
index 84e1a4721e..8547de9349 100755
--- a/share/spack/spack-completion.fish
+++ b/share/spack/spack-completion.fish
@@ -2958,12 +2958,14 @@ complete -c spack -n '__fish_spack_using_command uninstall' -l origin -r -f -a o
complete -c spack -n '__fish_spack_using_command uninstall' -l origin -r -d 'only remove DB records with the specified origin'
# spack unit-test
-set -g __fish_spack_optspecs_spack_unit_test h/help H/pytest-help l/list L/list-long N/list-names extension= s/ k/= showlocals
+set -g __fish_spack_optspecs_spack_unit_test h/help H/pytest-help n/numprocesses= l/list L/list-long N/list-names extension= s/ k/= showlocals
complete -c spack -n '__fish_spack_using_command_pos_remainder 0 unit-test' -f -a '(__fish_spack_unit_tests)'
complete -c spack -n '__fish_spack_using_command unit-test' -s h -l help -f -a help
complete -c spack -n '__fish_spack_using_command unit-test' -s h -l help -d 'show this help message and exit'
complete -c spack -n '__fish_spack_using_command unit-test' -s H -l pytest-help -f -a pytest_help
complete -c spack -n '__fish_spack_using_command unit-test' -s H -l pytest-help -d 'show full pytest help, with advanced options'
+complete -c spack -n '__fish_spack_using_command unit-test' -s n -l numprocesses -r -f -a numprocesses
+complete -c spack -n '__fish_spack_using_command unit-test' -s n -l numprocesses -r -d 'run tests in parallel up to this wide, default 1 for sequential'
complete -c spack -n '__fish_spack_using_command unit-test' -s l -l list -f -a list
complete -c spack -n '__fish_spack_using_command unit-test' -s l -l list -d 'list test filenames'
complete -c spack -n '__fish_spack_using_command unit-test' -s L -l list-long -f -a list