Return early in do_fetch when there is no code or a package is external (#26926)

Co-authored-by: Ryan Krattiger <ryan.krattiger@kitware.com>
This commit is contained in:
Harmen Stoppels 2021-10-25 13:51:23 +02:00 committed by GitHub
parent de8e795563
commit cc8d8cc9cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 7 deletions

View File

@ -76,10 +76,6 @@ def fetch(parser, args):
if args.missing and package.installed:
continue
# Do not attempt to fetch externals (they're local)
if package.spec.external:
continue
package.do_fetch()
package = spack.repo.get(spec)

View File

@ -1333,9 +1333,9 @@ def do_fetch(self, mirror_only=False):
Creates a stage directory and downloads the tarball for this package.
Working directory will be set to the stage directory.
"""
if not self.has_code:
tty.debug('No fetch required for {0}: package has no code.'
.format(self.name))
if not self.has_code or self.spec.external:
tty.debug('No fetch required for {0}'.format(self.name))
return
checksum = spack.config.get('config:checksum')
fetch = self.stage.managed_by_spack

View File

@ -19,6 +19,7 @@
import spack.binary_distribution as bindist
import spack.cmd.buildcache as buildcache
import spack.package
import spack.repo
import spack.store
import spack.util.gpg
@ -598,3 +599,31 @@ def _instr(pkg):
expected = pkg.download_instr if manual else 'All fetchers failed'
with pytest.raises(spack.fetch_strategy.FetchError, match=expected):
pkg.do_fetch()
@pytest.fixture()
def fetching_not_allowed(monkeypatch):
class FetchingNotAllowed(spack.fetch_strategy.FetchStrategy):
def mirror_id(self):
return None
def fetch(self):
raise Exception("Sources are fetched but shouldn't have been")
fetcher = FetchStrategyComposite()
fetcher.append(FetchingNotAllowed())
monkeypatch.setattr(spack.package.PackageBase, 'fetcher', fetcher)
def test_fetch_without_code_is_noop(install_mockery, fetching_not_allowed):
"""do_fetch for packages without code should be a no-op"""
pkg = Spec('a').concretized().package
pkg.has_code = False
pkg.do_fetch()
def test_fetch_external_package_is_noop(install_mockery, fetching_not_allowed):
"""do_fetch for packages without code should be a no-op"""
spec = Spec('a').concretized()
spec.external_path = "/some/where"
assert spec.external
spec.package.do_fetch()