Skip to content

Commit

Permalink
Fixes #7 - ignore any exceptions raised when importing from pip
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Oct 27, 2019
1 parent fce0be8 commit 1f42567
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
Unreleased Changes
------------------

**Important:**

* Fix `Issue #7 <https://github.com/jantman/versionfinder/issues/7>`_ where certain new versions of pip throw an AttributeError on import if running in Lambda (or other environments where ``sys.stdin`` is ``None``).
* Stop testing Python 3.3 and drop official support for it.
* Multiple pip10 fixes.
* Test fixes:
Expand Down
18 changes: 12 additions & 6 deletions versionfinder/versionfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,33 @@

from .versioninfo import VersionInfo

# Note: we catch all exceptions here because of
# https://github.com/jantman/versionfinder/issues/7 - some pip versions
# throw an import-time AttributeError when running in Lambda, or other
# environments where sys.stdin is None. Per that issue, the right thing to
# do is never fail if pip can't be imported.
# This was fixed in https://github.com/pypa/pip/pull/7118 / pip 19.3
try:
from pip._internal.operations.freeze import FrozenRequirement
except (ImportError, KeyError):
except Exception:
try:
from pip._internal import FrozenRequirement
except (ImportError, KeyError):
except Exception:
try:
from pip import FrozenRequirement
except (ImportError, KeyError):
except Exception:
# this is used within try blocks; NBD if they fail
pass

try:
from pip._internal.utils.misc import get_installed_distributions
except (ImportError, KeyError):
except Exception:
try:
from pip._internal import get_installed_distributions
except (ImportError, KeyError):
except Exception:
try:
from pip import get_installed_distributions
except (ImportError, KeyError):
except Exception:
# this is used within try blocks; NBD if they fail
pass

Expand Down

0 comments on commit 1f42567

Please sign in to comment.