diff --git a/lib/spack/docs/conf.py b/lib/spack/docs/conf.py index 30123635eb..542a3d9024 100644 --- a/lib/spack/docs/conf.py +++ b/lib/spack/docs/conf.py @@ -206,6 +206,8 @@ def setup(sphinx): # Spack classes that are private and we don't want to expose ("py:class", "spack.provider_index._IndexBase"), ("py:class", "spack.repo._PrependFileLoader"), + # Spack classes that intersphinx is unable to resolve + ("py:class", "spack.version.VersionBase"), ] # The reST default role (used for this markup: `text`) to use for all documents. diff --git a/lib/spack/spack/cmd/checksum.py b/lib/spack/spack/cmd/checksum.py index 3cfdcabff9..0483f4dd91 100644 --- a/lib/spack/spack/cmd/checksum.py +++ b/lib/spack/spack/cmd/checksum.py @@ -15,7 +15,7 @@ import spack.spec import spack.stage import spack.util.crypto -from spack.package_base import preferred_version +from spack.package_base import deprecated_version, preferred_version from spack.util.naming import valid_fully_qualified_module_name from spack.version import VersionBase, ver @@ -81,6 +81,9 @@ def checksum(parser, args): if versions: remote_versions = None for version in versions: + if deprecated_version(pkg, version): + tty.warn("Version {0} is deprecated".format(version)) + version = ver(version) if not isinstance(version, VersionBase): tty.die( @@ -101,7 +104,7 @@ def checksum(parser, args): url_dict = pkg.fetch_remote_versions() if not url_dict: - tty.die("Could not find any versions for {0}".format(pkg.name)) + tty.die("Could not find any remote versions for {0}".format(pkg.name)) version_lines = spack.stage.get_checksums_for_versions( url_dict, diff --git a/lib/spack/spack/package_base.py b/lib/spack/spack/package_base.py index f4573e6f19..f05c0ff868 100644 --- a/lib/spack/spack/package_base.py +++ b/lib/spack/spack/package_base.py @@ -100,6 +100,23 @@ is_windows = sys.platform == "win32" +def deprecated_version(pkg, version): + """Return True if the version is deprecated, False otherwise. + + Arguments: + pkg (Package): The package whose version is to be checked. + version (str or spack.version.VersionBase): The version being checked + """ + if not isinstance(version, VersionBase): + version = Version(version) + + for k, v in pkg.versions.items(): + if version == k and v.get("deprecated", False): + return True + + return False + + def preferred_version(pkg): """ Returns a sorted list of the preferred versions of the package. diff --git a/lib/spack/spack/test/cmd/checksum.py b/lib/spack/spack/test/cmd/checksum.py index a84b0eb8b7..84696bb6f8 100644 --- a/lib/spack/spack/test/cmd/checksum.py +++ b/lib/spack/spack/test/cmd/checksum.py @@ -68,3 +68,13 @@ def test_checksum_versions(mock_packages, mock_fetch, mock_stage): output = spack_checksum("preferred-test", versions[0]) assert "Found 1 version" in output assert "version(" in output + + +def test_checksum_missing_version(mock_packages, mock_fetch, mock_stage): + output = spack_checksum("preferred-test", "99.99.99", fail_on_error=False) + assert "Could not find any remote versions" in output + + +def test_checksum_deprecated_version(mock_packages, mock_fetch, mock_stage): + output = spack_checksum("deprecated-versions", "1.1.0", fail_on_error=False) + assert "Version 1.1.0 is deprecated" in output diff --git a/lib/spack/spack/test/packages.py b/lib/spack/spack/test/packages.py index 07161ad83f..3a22abcd7c 100644 --- a/lib/spack/spack/test/packages.py +++ b/lib/spack/spack/test/packages.py @@ -321,3 +321,11 @@ def test_has_test_method_fails(capsys): captured = capsys.readouterr()[1] assert "is not a class" in captured + + +def test_package_deprecated_version(mock_packages, mock_fetch, mock_stage): + spec = Spec("deprecated-versions") + pkg_cls = spack.repo.path.get_pkg_class(spec.name) + + assert spack.package_base.deprecated_version(pkg_cls, "1.1.0") + assert not spack.package_base.deprecated_version(pkg_cls, "1.0.0")