summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew W Elble <aweits@rit.edu>2020-03-06 19:29:01 -0500
committerTodd Gamblin <tgamblin@llnl.gov>2020-03-20 11:21:40 -0700
commit654914d53e2bb578eb8d82ca02a0547cf7834f5d (patch)
treebcebdb21213f27b79c11f6b627626c76106bd6ca /lib
parent3753424a87ebb86e9b6c972a8d136c8c2f2f604b (diff)
downloadspack-654914d53e2bb578eb8d82ca02a0547cf7834f5d.tar.gz
spack-654914d53e2bb578eb8d82ca02a0547cf7834f5d.tar.bz2
spack-654914d53e2bb578eb8d82ca02a0547cf7834f5d.tar.xz
spack-654914d53e2bb578eb8d82ca02a0547cf7834f5d.zip
Fix for being able to 'spack load' packages that have been renamed. (#14348)
* Fix for being able to 'spack load' packages that have been renamed. * tests: add test for 'spack load' of a installed, but renamed/deleted package
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/modules/common.py6
-rw-r--r--lib/spack/spack/test/modules/common.py31
2 files changed, 36 insertions, 1 deletions
diff --git a/lib/spack/spack/modules/common.py b/lib/spack/spack/modules/common.py
index d6fb536e8f..c09a225116 100644
--- a/lib/spack/spack/modules/common.py
+++ b/lib/spack/spack/modules/common.py
@@ -342,7 +342,11 @@ def get_module(module_type, spec, get_full_path, required=True):
The module name or path. May return ``None`` if the module is not
available.
"""
- if spec.package.installed_upstream:
+ try:
+ upstream = spec.package.installed_upstream
+ except spack.repo.UnknownPackageError:
+ upstream, record = spack.store.db.query_by_spec_hash(spec.dag_hash())
+ if upstream:
module = (spack.modules.common.upstream_module_index
.upstream_module(spec, module_type))
if not module:
diff --git a/lib/spack/spack/test/modules/common.py b/lib/spack/spack/test/modules/common.py
index cc2eb61d0b..f2cb60e1db 100644
--- a/lib/spack/spack/test/modules/common.py
+++ b/lib/spack/spack/test/modules/common.py
@@ -11,6 +11,7 @@ import collections
import spack.spec
import spack.modules.tcl
from spack.modules.common import UpstreamModuleIndex
+from spack.spec import Spec
import spack.error
@@ -183,3 +184,33 @@ module_index:
assert m1_path == '/path/to/a'
finally:
spack.modules.common.upstream_module_index = old_index
+
+
+def test_load_installed_package_not_in_repo(install_mockery, mock_fetch,
+ monkeypatch):
+ # Get a basic concrete spec for the trivial install package.
+ spec = Spec('trivial-install-test-package')
+ spec.concretize()
+ assert spec.concrete
+
+ # Get the package
+ pkg = spec.package
+
+ def find_nothing(*args):
+ raise spack.repo.UnknownPackageError(
+ 'Repo package access is disabled for test')
+
+ try:
+ pkg.do_install()
+
+ spec._package = None
+ monkeypatch.setattr(spack.repo, 'get', find_nothing)
+ with pytest.raises(spack.repo.UnknownPackageError):
+ spec.package
+
+ module_path = spack.modules.common.get_module('tcl', spec, True)
+ assert module_path
+ pkg.do_uninstall()
+ except Exception:
+ pkg.remove_prefix()
+ raise