From c5ab73fd4d8e816e21a89d48c8d0c8095ef5a49c Mon Sep 17 00:00:00 2001 From: Markus Kaiserswerth Date: Thu, 1 Dec 2016 02:58:33 +0100 Subject: [PATCH] Adjusted FileFinder import to work with Python 3.6 (#318) 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+). --- pex/finders.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pex/finders.py b/pex/finders.py index eb3be61f5..872bf5574 100644 --- a/pex/finders.py +++ b/pex/finders.py @@ -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): @@ -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 @@ -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