Skip to content

Commit

Permalink
Gracefully ignore KeyError on isort import
Browse files Browse the repository at this point in the history
This is a workaround for `pip` 9.0.2, which is the version that runs on
Heroku.  For some reason, importing `isort` import imports `requests`,
and if we import `requests` before/without importing `pip`, we get a
`KeyError`.

We only need for this import to succeed locally and on CI (basically,
anywhere where we want to run our test suite), so it's ok for this to
fail on production.

For more info:
  pypa/pip#5079 (comment)
  • Loading branch information
brainix committed Feb 26, 2019
1 parent b0bdb7f commit e3658eb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pottery/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ def _correctly_sorted(self):
return not self.incorrectly_sorted

import contextlib
with contextlib.suppress(ImportError):

# XXX: This is a workaround for pip 9.0.2, which is the version that runs on
# Heroku. For some reason, the following isort import imports requests, and if
# we import requests before/without importing pip, we get a KeyError.
#
# For more info:
# https://github.com/pypa/pip/issues/5079#issuecomment-373927413
with contextlib.suppress(ImportError, KeyError):
from isort import SortImports
SortImports.correctly_sorted = _correctly_sorted

Expand Down

0 comments on commit e3658eb

Please sign in to comment.