spack python: add -m option to run modules as scripts

It's often useful to run a module with `python -m`, e.g.:

    python -m pyinstrument script.py

Running a python script this way was hard, though, as `spack python` did
not have a similar `-m` option.  This PR adds a `-m` option to `spack
python` so that we can do things like this:

    spack python -m pyinstrument ./test.py

This makes it easy to write a script that uses a small part of Spack and
then profile it.  Previously thee easiest way to do this was to write a
custom Spack command, which is often overkill.
This commit is contained in:
Todd Gamblin
2020-01-28 21:31:53 -08:00
parent 90f3635afd
commit a7b43f1015
3 changed files with 32 additions and 2 deletions

View File

@@ -1272,7 +1272,7 @@ _spack_pydoc() {
_spack_python() {
if $list_options
then
SPACK_COMPREPLY="-h --help -c"
SPACK_COMPREPLY="-h --help -c -m"
else
SPACK_COMPREPLY=""
fi