summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-03 19:44:32 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2020-05-04 20:16:38 +0900
commit17259656bc2d9bbd001fa19170bb1f751ca272d1 (patch)
tree7a7b4575230f006b470c55c4ed0ca76cdd915f90
parentf17b84236391d27247aae9fb004c420b20b1142c (diff)
downloadbuildstream-17259656bc2d9bbd001fa19170bb1f751ca272d1.tar.gz
_pluginfactory/pluginfactory.py: Implement error reporting for pip origins
For plugins loaded from the pip origin, we now support specifying constraints. This is a non-breaking change and only involves specifying a package with constraints when specifying the 'package-name', however there are a few errors errors which can occur as a result, this patch tries to handle them all cleanly and provide the user with useful error messages.
-rw-r--r--src/buildstream/_pluginfactory/pluginfactory.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/buildstream/_pluginfactory/pluginfactory.py b/src/buildstream/_pluginfactory/pluginfactory.py
index 2de110ed4..042d0f565 100644
--- a/src/buildstream/_pluginfactory/pluginfactory.py
+++ b/src/buildstream/_pluginfactory/pluginfactory.py
@@ -200,14 +200,39 @@ class PluginFactory:
if ("pip", package_name) not in self._alternate_sources:
import pkg_resources
+ origin = self._origins[kind]
+
# key by a tuple to avoid collision
try:
package = pkg_resources.get_entry_info(package_name, self._entrypoint_group, kind)
except pkg_resources.DistributionNotFound as e:
- raise PluginError("Failed to load {} plugin '{}': {}".format(self._base_type.__name__, kind, e)) from e
+ raise PluginError(
+ "{}: Failed to load {} plugin '{}': {}".format(
+ origin.provenance, self._base_type.__name__, kind, e
+ ),
+ reason="package-not-found",
+ ) from e
+ except pkg_resources.VersionConflict as e:
+ raise PluginError(
+ "{}: Version conflict encountered while loading {} plugin '{}'".format(
+ origin.provenance, self._base_type.__name__, kind
+ ),
+ detail=e.report(),
+ reason="package-version-conflict",
+ ) from e
+ except pkg_resources.RequirementParseError as e:
+ raise PluginError(
+ "{}: Malformed package-name '{}' encountered: {}".format(origin.provenance, package_name, e),
+ reason="package-malformed-requirement",
+ ) from e
if package is None:
- raise PluginError("Pip package {} does not contain a plugin named '{}'".format(package_name, kind))
+ raise PluginError(
+ "{}: Pip package {} does not contain a plugin named '{}'".format(
+ origin.provenance, package_name, kind
+ ),
+ reason="plugin-not-found",
+ )
location = package.dist.get_resource_filename(
pkg_resources._manager, package.module_name.replace(".", os.sep) + ".py"