summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWouter Deconinck <wdconinc@gmail.com>2024-04-30 14:11:47 -0500
committerGitHub <noreply@github.com>2024-04-30 12:11:47 -0700
commitf2d0ba8fccf2808e3a341a807d6892e683f325e9 (patch)
tree05965bc7a171dfe2e15a512deb9d4d6b8b1f0a95
parent49d3eb1723a2c7220883acfd2a24860a15ed4ef3 (diff)
downloadspack-f2d0ba8fccf2808e3a341a807d6892e683f325e9.tar.gz
spack-f2d0ba8fccf2808e3a341a807d6892e683f325e9.tar.bz2
spack-f2d0ba8fccf2808e3a341a807d6892e683f325e9.tar.xz
spack-f2d0ba8fccf2808e3a341a807d6892e683f325e9.zip
PackageStillNeededError: add pkg that needs spec to exception msg (#43845)
* PackageStillNeededError: add pkg that needs spec to exception msg * PackageStillNeededError: f-string with short fmt and hash * PackageStillNeededError: split long string
-rw-r--r--lib/spack/spack/package_base.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/spack/spack/package_base.py b/lib/spack/spack/package_base.py
index 0be36f08ea..7c17c7d02e 100644
--- a/lib/spack/spack/package_base.py
+++ b/lib/spack/spack/package_base.py
@@ -2555,7 +2555,12 @@ class PackageStillNeededError(InstallError):
"""Raised when package is still needed by another on uninstall."""
def __init__(self, spec, dependents):
- super().__init__("Cannot uninstall %s" % spec)
+ spec_fmt = spack.spec.DEFAULT_FORMAT + " /{hash:7}"
+ dep_fmt = "{name}{@versions} /{hash:7}"
+ super().__init__(
+ f"Cannot uninstall {spec.format(spec_fmt)}, "
+ f"needed by {[dep.format(dep_fmt) for dep in dependents]}"
+ )
self.spec = spec
self.dependents = dependents