summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2021-10-25 13:51:23 +0200
committerGitHub <noreply@github.com>2021-10-25 13:51:23 +0200
commitcc8d8cc9cb6ea002abf78e9a62c590bf15a3e0fa (patch)
treed757ef3dabc2d5b74e78fa167bedd80d5b293546 /lib
parentde8e795563e03fe2519296ef453c926cd62a7894 (diff)
downloadspack-cc8d8cc9cb6ea002abf78e9a62c590bf15a3e0fa.tar.gz
spack-cc8d8cc9cb6ea002abf78e9a62c590bf15a3e0fa.tar.bz2
spack-cc8d8cc9cb6ea002abf78e9a62c590bf15a3e0fa.tar.xz
spack-cc8d8cc9cb6ea002abf78e9a62c590bf15a3e0fa.zip
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/fetch.py4
-rw-r--r--lib/spack/spack/package.py6
-rw-r--r--lib/spack/spack/test/packaging.py29
3 files changed, 32 insertions, 7 deletions
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()