From 35f70a6a7962643f32b87a6d9a125292060a60b1 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 10 Oct 2014 11:48:58 -0700 Subject: Make VersionConflict report who is requiring package fixes issue 268 --HG-- branch : BB-268_make_VersionConflict_report_who_required_package_3 --- pkg_resources.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 517298c9..1ca8dd8e 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -589,6 +589,9 @@ class WorkingSet(object): # key -> dist best = {} to_activate = [] + # key with req -> set of things that required it + # useful for reporting info about conflicts + required_by = collections.defaultdict(set) while requirements: # process dependencies breadth-first @@ -624,8 +627,13 @@ class WorkingSet(object): if dist not in req: # Oops, the "best" so far conflicts with a dependency # XXX put more info here - raise VersionConflict(dist, req) - requirements.extend(dist.requires(req.extras)[::-1]) + raise VersionConflict( + "%s is installed but %s is required by %s" + % (dist, req, list(required_by.get(req)))) + new_requirements = dist.requires(req.extras)[::-1] + requirements.extend(new_requirements) + for new_requirement in new_requirements: + required_by[new_requirement].add(req.project_name) processed[req] = True # return list of distros to activate -- cgit v1.2.3 From 9e8c932911dfa605f48428af7f3c23282012ab6c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 11 Oct 2014 12:55:09 -0400 Subject: Remove TODO comment, now done --- pkg_resources.py | 1 - 1 file changed, 1 deletion(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 1ca8dd8e..35e2ed24 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -626,7 +626,6 @@ class WorkingSet(object): to_activate.append(dist) if dist not in req: # Oops, the "best" so far conflicts with a dependency - # XXX put more info here raise VersionConflict( "%s is installed but %s is required by %s" % (dist, req, list(required_by.get(req)))) -- cgit v1.2.3 From e83d7d416f8706e262235b594384c70bf854eced Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 11 Oct 2014 13:01:01 -0400 Subject: Extract variables --- pkg_resources.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index 35e2ed24..ac72d71f 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -626,9 +626,9 @@ class WorkingSet(object): to_activate.append(dist) if dist not in req: # Oops, the "best" so far conflicts with a dependency - raise VersionConflict( - "%s is installed but %s is required by %s" - % (dist, req, list(required_by.get(req)))) + tmpl = "%s is installed but %s is required by %s" + args = dist, req, list(required_by.get(req)) + raise VersionConflict(tmpl % args) new_requirements = dist.requires(req.extras)[::-1] requirements.extend(new_requirements) for new_requirement in new_requirements: -- cgit v1.2.3 From 0f27d17414b5a523614f16e6129ce426df3c3e66 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 11 Oct 2014 13:06:54 -0400 Subject: Update comment --- pkg_resources.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index ac72d71f..a5b02223 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -589,8 +589,9 @@ class WorkingSet(object): # key -> dist best = {} to_activate = [] - # key with req -> set of things that required it - # useful for reporting info about conflicts + + # Mapping of requirement to set of distributions that required it; + # useful for reporting info about conflicts. required_by = collections.defaultdict(set) while requirements: -- cgit v1.2.3 From f110f30df540d21c4fe7870460c07d70c6c8cd0b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 11 Oct 2014 13:20:12 -0400 Subject: Add a couple of comments to help me understand. --- pkg_resources.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index a5b02223..de50c4b0 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -630,10 +630,15 @@ class WorkingSet(object): tmpl = "%s is installed but %s is required by %s" args = dist, req, list(required_by.get(req)) raise VersionConflict(tmpl % args) + + # push the new requirements onto the stack new_requirements = dist.requires(req.extras)[::-1] requirements.extend(new_requirements) + + # Register the new requirements needed by req for new_requirement in new_requirements: required_by[new_requirement].add(req.project_name) + processed[req] = True # return list of distros to activate -- cgit v1.2.3 From c4bc8b21d203668645ab551318aef5859e3acb9e Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Sat, 11 Oct 2014 15:42:24 -0700 Subject: Fix VersionConflict test failure Fixes `TypeError: 'NoneType' object is not iterable` error at pkg_resources.py:632 Fixes issue #270 --HG-- branch : BB-270_fix_VersionConflict_test_failure_2 --- pkg_resources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkg_resources.py') diff --git a/pkg_resources.py b/pkg_resources.py index de50c4b0..511068a6 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -628,7 +628,7 @@ class WorkingSet(object): if dist not in req: # Oops, the "best" so far conflicts with a dependency tmpl = "%s is installed but %s is required by %s" - args = dist, req, list(required_by.get(req)) + args = dist, req, list(required_by.get(req, [])) raise VersionConflict(tmpl % args) # push the new requirements onto the stack -- cgit v1.2.3