Allow uninstalling missing packages (#11874)

Remove package access from directory_layout; add regression test to ensure
that specs can be uninstalled without a package being known
This commit is contained in:
Peter Scheibel 2019-06-29 16:04:15 -07:00 committed by Todd Gamblin
parent 7f2e364fa1
commit 9c16b4a7f6
2 changed files with 19 additions and 6 deletions

View File

@ -78,7 +78,10 @@ def path_for_spec(self, spec):
if spec.external: if spec.external:
return spec.external_path return spec.external_path
if self.check_upstream and spec.package.installed_upstream: if self.check_upstream:
upstream, record = spack.store.db.query_by_spec_hash(
spec.dag_hash())
if upstream:
raise SpackError( raise SpackError(
"Internal error: attempted to call path_for_spec on" "Internal error: attempted to call path_for_spec on"
" upstream-installed package.") " upstream-installed package.")

View File

@ -12,17 +12,27 @@
from spack.spec import Spec from spack.spec import Spec
def test_install_and_uninstall(install_mockery, mock_fetch): def test_install_and_uninstall(install_mockery, mock_fetch, monkeypatch):
# Get a basic concrete spec for the trivial install package. # Get a basic concrete spec for the trivial install package.
spec = Spec('trivial-install-test-package') spec = Spec('trivial-install-test-package')
spec.concretize() spec.concretize()
assert spec.concrete assert spec.concrete
# Get the package # Get the package
pkg = spack.repo.get(spec) pkg = spec.package
def find_nothing(*args):
raise spack.repo.UnknownPackageError(
'Repo package access is disabled for test')
try: try:
pkg.do_install() pkg.do_install()
spec._package = None
monkeypatch.setattr(spack.repo, 'get', find_nothing)
with pytest.raises(spack.repo.UnknownPackageError):
spec.package
pkg.do_uninstall() pkg.do_uninstall()
except Exception: except Exception:
pkg.remove_prefix() pkg.remove_prefix()