Fix spack versions behavior when no URL (#8967)

* Fix spack versions behavior when no URL
* Unit test packages without URLs or safe versions
This commit is contained in:
Adam J. Stewart 2018-08-16 10:42:23 -05:00 committed by Todd Gamblin
parent ead9363bee
commit ac6d929897
3 changed files with 45 additions and 12 deletions

View file

@ -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)

View file

@ -2063,8 +2063,15 @@ def format_doc(self, **kwargs):
@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 @@ def all_urls(self):
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(

View file

@ -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')