Skip to content

Commit

Permalink
Fixing VersionConflict and DistributionNotFound exceptions
Browse files Browse the repository at this point in the history
These are due to packages being upgraded beyond what some depending package specifies (e.g. if you tend to do `pip list --outdated | xargs pip install --upgrade` or anything similar.)
To deal with this, we ignore version requirement if VersionConflict.

Not sure how we can end up in a DistributionNotFound scenario, but plenty of bug reports about it, so just ignoring those outright.

Fixes invl#7, invl#9, invl#10, invl#11.
  • Loading branch information
tresni committed May 1, 2018
1 parent 5cddd09 commit 21fd114
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pip_autoremove.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import optparse

import pip
from pkg_resources import working_set, get_distribution
from pkg_resources import working_set, get_distribution, VersionConflict, DistributionNotFound


__version__ = '0.9.0'
Expand Down Expand Up @@ -104,7 +104,18 @@ def get_graph():


def requires(dist):
return map(get_distribution, dist.requires())
required = []
for pkg in dist.requires():
try:
required.append(get_distribution(pkg))
except VersionConflict as e:
print(e.report())
print("Redoing requirement with just package name...")
required.append(get_distribution(pkg.project_name))
except DistributionNotFound as e:
print(e.report())
print("Skipping %s", pkg.project_name)
return required


def main(argv=None):
Expand Down

0 comments on commit 21fd114

Please sign in to comment.