From 010b431692f5b7fd755e685cad057e6c288c161e Mon Sep 17 00:00:00 2001 From: Asher Mancinelli Date: Thu, 24 Jun 2021 16:12:45 -0600 Subject: Add Externally Findable section to info command (#24503) * Add Externally Findable section to info command * Use comma delimited detection attributes in addition to boolean value * Unit test externally detectable part of spack info --- lib/spack/spack/cmd/info.py | 20 ++++++++++++++++++++ lib/spack/spack/test/cmd/info.py | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'lib') diff --git a/lib/spack/spack/cmd/info.py b/lib/spack/spack/cmd/info.py index 441223b738..c3e5a51903 100644 --- a/lib/spack/spack/cmd/info.py +++ b/lib/spack/spack/cmd/info.py @@ -155,6 +155,26 @@ def print_text_info(pkg): color.cprint('') color.cprint(section_title('Maintainers: ') + mnt) + color.cprint('') + color.cprint(section_title('Externally Detectable: ')) + + # If the package has an 'executables' field, it can detect an installation + if hasattr(pkg, 'executables'): + find_attributes = [] + if hasattr(pkg, 'determine_version'): + find_attributes.append('version') + + if hasattr(pkg, 'determine_variants'): + find_attributes.append('variants') + + # If the package does not define 'determine_version' nor + # 'determine_variants', then it must use some custom detection + # mechanism. In this case, just inform the user it's detectable somehow. + color.cprint(' True{0}'.format( + ' (' + ', '.join(find_attributes) + ')' if find_attributes else '')) + else: + color.cprint(' False') + color.cprint('') color.cprint(section_title("Tags: ")) if hasattr(pkg, 'tags'): diff --git a/lib/spack/spack/test/cmd/info.py b/lib/spack/spack/test/cmd/info.py index 0ff6857617..b62a842b8b 100644 --- a/lib/spack/spack/test/cmd/info.py +++ b/lib/spack/spack/test/cmd/info.py @@ -48,6 +48,22 @@ def test_it_just_runs(pkg): info(pkg) +@pytest.mark.parametrize('pkg_query,expected', [ + ('zlib', 'False'), + ('gcc', 'True (version, variants)'), +]) +@pytest.mark.usefixtures('mock_print') +def test_is_externally_detectable(pkg_query, expected, parser, info_lines): + args = parser.parse_args([pkg_query]) + spack.cmd.info.info(parser, args) + + line_iter = info_lines.__iter__() + for line in line_iter: + if 'Externally Detectable' in line: + is_externally_detectable = next(line_iter).strip() + assert is_externally_detectable == expected + + @pytest.mark.parametrize('pkg_query', [ 'hdf5', 'cloverleaf3d', @@ -59,6 +75,7 @@ def test_info_fields(pkg_query, parser, info_lines): expected_fields = ( 'Description:', 'Homepage:', + 'Externally Detectable:', 'Safe versions:', 'Variants:', 'Installation Phases:', -- cgit v1.2.3-60-g2f50