summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam J. Stewart <ajstewart426@gmail.com>2020-04-03 01:12:03 -0500
committerGitHub <noreply@github.com>2020-04-02 23:12:03 -0700
commit75a2f8046a5782dc227f2679d6860558db4b1bfb (patch)
tree81b527da07fb920d480c0fe3dd11d07596fe97fa /lib
parent1662c3581bb8e07a4a59841b31354877b24ed7c9 (diff)
downloadspack-75a2f8046a5782dc227f2679d6860558db4b1bfb.tar.gz
spack-75a2f8046a5782dc227f2679d6860558db4b1bfb.tar.bz2
spack-75a2f8046a5782dc227f2679d6860558db4b1bfb.tar.xz
spack-75a2f8046a5782dc227f2679d6860558db4b1bfb.zip
Add commands to facilitate Spack/Python/OS reporting (#15834)
* Add --version arg to spack python command * Add `spack debug report` command
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/debug.py18
-rw-r--r--lib/spack/spack/cmd/python.py9
-rw-r--r--lib/spack/spack/test/cmd/debug.py14
-rw-r--r--lib/spack/spack/test/cmd/python.py7
4 files changed, 46 insertions, 2 deletions
diff --git a/lib/spack/spack/cmd/debug.py b/lib/spack/spack/cmd/debug.py
index 4fc39251af..074e95209a 100644
--- a/lib/spack/spack/cmd/debug.py
+++ b/lib/spack/spack/cmd/debug.py
@@ -3,7 +3,10 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+from __future__ import print_function
+
import os
+import platform
import re
from datetime import datetime
from glob import glob
@@ -11,7 +14,9 @@ from glob import glob
import llnl.util.tty as tty
from llnl.util.filesystem import working_dir
+import spack.architecture as architecture
import spack.paths
+from spack.main import get_version
from spack.util.executable import which
description = "debugging commands for troubleshooting Spack"
@@ -23,6 +28,7 @@ def setup_parser(subparser):
sp = subparser.add_subparsers(metavar='SUBCOMMAND', dest='debug_command')
sp.add_parser('create-db-tarball',
help="create a tarball of Spack's installation metadata")
+ sp.add_parser('report', help='print information useful for bug reports')
def _debug_tarball_suffix():
@@ -78,6 +84,16 @@ def create_db_tarball(args):
tty.msg('Created %s' % tarball_name)
+def report(args):
+ print('* **Spack:**', get_version())
+ print('* **Python:**', platform.python_version())
+ print('* **Platform:**', architecture.Arch(
+ architecture.platform(), 'frontend', 'frontend'))
+
+
def debug(parser, args):
- action = {'create-db-tarball': create_db_tarball}
+ action = {
+ 'create-db-tarball': create_db_tarball,
+ 'report': report,
+ }
action[args.debug_command](args)
diff --git a/lib/spack/spack/cmd/python.py b/lib/spack/spack/cmd/python.py
index 2f2290aad8..a91f3663fb 100644
--- a/lib/spack/spack/cmd/python.py
+++ b/lib/spack/spack/cmd/python.py
@@ -3,6 +3,8 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+from __future__ import print_function
+
import os
import sys
import code
@@ -21,6 +23,9 @@ level = "long"
def setup_parser(subparser):
subparser.add_argument(
+ '-V', '--version', action='store_true',
+ help='print the Python version number and exit')
+ subparser.add_argument(
'-c', dest='python_command', help='command to execute')
subparser.add_argument(
'-m', dest='module', action='store',
@@ -31,6 +36,10 @@ def setup_parser(subparser):
def python(parser, args, unknown_args):
+ if args.version:
+ print('Python', platform.python_version())
+ return
+
if args.module:
sys.argv = ['spack-python'] + unknown_args + args.python_args
runpy.run_module(args.module, run_name="__main__", alter_sys=True)
diff --git a/lib/spack/spack/test/cmd/debug.py b/lib/spack/spack/test/cmd/debug.py
index 4a06276abf..2898ad670e 100644
--- a/lib/spack/spack/test/cmd/debug.py
+++ b/lib/spack/spack/test/cmd/debug.py
@@ -3,12 +3,15 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+import platform
+
import pytest
import os
import os.path
-from spack.main import SpackCommand
+import spack.architecture as architecture
+from spack.main import SpackCommand, get_version
from spack.util.executable import which
debug = SpackCommand('debug')
@@ -41,3 +44,12 @@ def test_create_db_tarball(tmpdir, database):
spec_suffix = '%s/.spack/spec.yaml' % spec.dag_hash()
assert spec_suffix in contents
+
+
+def test_report():
+ out = debug('report')
+ arch = architecture.Arch(architecture.platform(), 'frontend', 'frontend')
+
+ assert get_version() in out
+ assert platform.python_version() in out
+ assert str(arch) in out
diff --git a/lib/spack/spack/test/cmd/python.py b/lib/spack/spack/test/cmd/python.py
index 5bc05e0127..b1c9d3db00 100644
--- a/lib/spack/spack/test/cmd/python.py
+++ b/lib/spack/spack/test/cmd/python.py
@@ -3,6 +3,8 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+import platform
+
import pytest
import spack
@@ -16,6 +18,11 @@ def test_python():
assert out.strip() == spack.spack_version
+def test_python_version():
+ out = python('-V')
+ assert platform.python_version() in out
+
+
def test_python_with_module():
# pytest rewrites a lot of modules, which interferes with runpy, so
# it's hard to test this. Trying to import a module like sys, that