From cc8d8cc9cb6ea002abf78e9a62c590bf15a3e0fa Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Mon, 25 Oct 2021 13:51:23 +0200 Subject: Return early in do_fetch when there is no code or a package is external (#26926) Co-authored-by: Ryan Krattiger --- lib/spack/spack/cmd/fetch.py | 4 ---- lib/spack/spack/package.py | 6 +++--- lib/spack/spack/test/packaging.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/cmd/fetch.py b/lib/spack/spack/cmd/fetch.py index 4993c49912..1aa55923c3 100644 --- a/lib/spack/spack/cmd/fetch.py +++ b/lib/spack/spack/cmd/fetch.py @@ -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) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 5f66d8255d..00ba8a38d5 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1333,9 +1333,9 @@ class PackageBase(six.with_metaclass(PackageMeta, PackageViewMixin, object)): 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 diff --git a/lib/spack/spack/test/packaging.py b/lib/spack/spack/test/packaging.py index cb3d146745..32a07f5e2d 100644 --- a/lib/spack/spack/test/packaging.py +++ b/lib/spack/spack/test/packaging.py @@ -19,6 +19,7 @@ from llnl.util.filesystem import mkdirp 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 test_manual_download(install_mockery, mock_download, monkeypatch, manual, 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() -- cgit v1.2.3-70-g09d2