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
This commit is contained in:
Wouter Deconinck 2024-04-30 14:11:47 -05:00 committed by GitHub
parent 49d3eb1723
commit f2d0ba8fcc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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