From 03ef43d86b8498f09a6837e37e1347517d53e622 Mon Sep 17 00:00:00 2001 From: John Sirois Date: Tue, 30 Jun 2015 09:30:59 -0700 Subject: [PATCH] Tread carefully around DistributionNotFound. Old versions of pkg_resources do not populate the requirers argument so make sure its present - carefully - before using it. Testing Done: CI went green here: https://travis-ci.org/pantsbuild/pex/builds/67608347 Bugs closed: 130, 131 Reviewed at https://rbcommons.com/s/twitter/r/2400/ --- pex/environment.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pex/environment.py b/pex/environment.py index efc92d917..162ab8eb6 100644 --- a/pex/environment.py +++ b/pex/environment.py @@ -148,7 +148,10 @@ def _resolve(self, working_set, reqs): except DistributionNotFound as e: TRACER.log('Failed to resolve a requirement: %s' % e) unresolved_reqs.add(e.args[0].project_name) - if e.args[1]: + # Older versions of pkg_resources just call `DistributionNotFound(req)` instead of the + # modern `DistributionNotFound(req, requirers)` and so we may not have the 2nd requirers + # slot at all. + if len(e.args) >= 2 and e.args[1]: unresolved_reqs.update(e.args[1]) unresolved_reqs = set([req.lower() for req in unresolved_reqs])