From ac6d9298979fd5c22220c9a32710465aa88e35e8 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Thu, 16 Aug 2018 10:42:23 -0500 Subject: Fix spack versions behavior when no URL (#8967) * Fix spack versions behavior when no URL * Unit test packages without URLs or safe versions --- lib/spack/spack/cmd/versions.py | 23 +++++++++++++++-------- lib/spack/spack/package.py | 20 ++++++++++++++++---- lib/spack/spack/test/cmd/versions.py | 14 ++++++++++++++ 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/lib/spack/spack/cmd/versions.py b/lib/spack/spack/cmd/versions.py index 8c55f83769..abb64f3747 100644 --- a/lib/spack/spack/cmd/versions.py +++ b/lib/spack/spack/cmd/versions.py @@ -42,20 +42,27 @@ def setup_parser(subparser): def versions(parser, args): pkg = spack.repo.get(args.package) + tty.msg('Safe versions (already checksummed):') + safe_versions = pkg.versions + + if not safe_versions: + print(' Found no versions for {0}'.format(pkg.name)) + tty.debug('Manually add versions to the package.') + else: + colify(sorted(safe_versions, reverse=True), indent=2) + + tty.msg('Remote versions (not yet checksummed):') + fetched_versions = pkg.fetch_remote_versions() remote_versions = set(fetched_versions).difference(safe_versions) - tty.msg("Safe versions (already checksummed):") - colify(sorted(safe_versions, reverse=True), indent=2) - - tty.msg("Remote versions (not yet checksummed):") if not remote_versions: if not fetched_versions: - print(" Found no versions for %s" % pkg.name) - tty.debug("Check the list_url and list_depth attribute on the " - "package to help Spack find versions.") + print(' Found no versions for {0}'.format(pkg.name)) + tty.debug('Check the list_url and list_depth attributes of the ' + 'package to help Spack find versions.') else: - print(" Found no unchecksummed versions for %s" % pkg.name) + print(' Found no unchecksummed versions for {0}'.format(pkg.name)) else: colify(sorted(remote_versions, reverse=True), indent=2) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index cb4a6e1ac3..d3a716f552 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -2063,8 +2063,15 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)): @property def all_urls(self): + """A list of all URLs in a package. + + Check both class-level and version-specific URLs. + + Returns: + list: a list of URLs + """ urls = [] - if self.url: + if hasattr(self, 'url') and self.url: urls.append(self.url) for args in self.versions.values(): @@ -2073,10 +2080,15 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)): return urls def fetch_remote_versions(self): - """Try to find remote versions of this package using the - list_url and any other URLs described in the package file.""" + """Find remote versions of this package. + + Uses ``list_url`` and any other URLs listed in the package file. + + Returns: + dict: a dictionary mapping versions to URLs + """ if not self.all_urls: - raise spack.util.web.VersionFetchError(self.__class__) + return {} try: return spack.util.web.find_versions_of_archive( diff --git a/lib/spack/spack/test/cmd/versions.py b/lib/spack/spack/test/cmd/versions.py index 69d2dae056..e1816ff230 100644 --- a/lib/spack/spack/test/cmd/versions.py +++ b/lib/spack/spack/test/cmd/versions.py @@ -48,3 +48,17 @@ def test_no_unchecksummed_versions(): """Test a package for which no unchecksummed versions are available.""" versions('bzip2') + + +@pytest.mark.network +def test_versions_no_url(): + """Test a package with versions but without a ``url`` attribute.""" + + versions('graphviz') + + +@pytest.mark.network +def test_no_versions_no_url(): + """Test a package without versions or a ``url`` attribute.""" + + versions('opengl') -- cgit v1.2.3-60-g2f50