From f81c6c36c062d40834cee8add4947c211e5e152c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 2 Jan 2016 16:30:44 -0500 Subject: Extract variable for extant name. Add comment about the hack. --HG-- branch : feature/issue-229 --- pkg_resources/extern/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'pkg_resources/extern') diff --git a/pkg_resources/extern/__init__.py b/pkg_resources/extern/__init__.py index 2d338426..5e81c0bb 100644 --- a/pkg_resources/extern/__init__.py +++ b/pkg_resources/extern/__init__.py @@ -38,11 +38,17 @@ class VendorImporter: root, base, target = fullname.partition(self.root_name + '.') for prefix in self.search_path: try: - __import__(prefix + target) - mod = sys.modules[prefix + target] + extant = prefix + target + __import__(extant) + mod = sys.modules[extant] sys.modules[fullname] = mod + # mysterious hack: + # Remove the reference to the extant package/module + # on later Python versions to cause relative imports + # in the vendor package to resolve the same modules + # as those going through this importer. if sys.version_info > (3, 3): - del sys.modules[prefix + target] + del sys.modules[extant] return mod except ImportError: pass -- cgit v1.2.3