Skip to content

Commit

Permalink
Adjusted FileFinder import to work with Python 3.6 (#318)
Browse files Browse the repository at this point in the history
In CPython 3.6, FileFinder has been moved from importlib._bootstrap to
a new importlib._bootstrap_external module.

To account for this, this commit switches to importing the more general
importlib.machinery module instead of importlib._bootstrap, which also
works with older CPython version (3.3+).
  • Loading branch information
mkai authored and kwlzn committed Dec 1, 2016
1 parent ae3f225 commit c5ab73f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pex/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import pkg_resources

if sys.version_info >= (3, 3) and sys.implementation.name == "cpython":
import importlib._bootstrap as importlib_bootstrap
import importlib.machinery as importlib_machinery
else:
importlib_bootstrap = None
importlib_machinery = None


class ChainedFinder(object):
Expand Down Expand Up @@ -214,8 +214,8 @@ def register_finders():
# append the wheel finder
_add_finder(pkgutil.ImpImporter, find_wheels_on_path)

if importlib_bootstrap is not None:
_add_finder(importlib_bootstrap.FileFinder, find_wheels_on_path)
if importlib_machinery is not None:
_add_finder(importlib_machinery.FileFinder, find_wheels_on_path)

__PREVIOUS_FINDER = previous_finder

Expand All @@ -230,8 +230,8 @@ def unregister_finders():
pkg_resources.register_finder(zipimport.zipimporter, __PREVIOUS_FINDER)
_remove_finder(pkgutil.ImpImporter, find_wheels_on_path)

if importlib_bootstrap is not None:
_remove_finder(importlib_bootstrap.FileFinder, find_wheels_on_path)
if importlib_machinery is not None:
_remove_finder(importlib_machinery.FileFinder, find_wheels_on_path)

__PREVIOUS_FINDER = None

Expand Down

0 comments on commit c5ab73f

Please sign in to comment.