From a74f63a0e6f1c050748266ea463ab7850504a856 Mon Sep 17 00:00:00 2001 From: Kris Wilson Date: Thu, 15 Nov 2018 12:35:08 -0800 Subject: [PATCH] Repair unhandled AttributeError during pex bootstrapping. (#599) A quick, surface level fix for #598. --- pex/environment.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pex/environment.py b/pex/environment.py index fbe72d1db..741aee5fa 100644 --- a/pex/environment.py +++ b/pex/environment.py @@ -58,10 +58,21 @@ def update_module_paths(cls, new_code_path): TRACER.log('Adding to the head of sys.path: %s' % new_code_path) sys.path.insert(0, new_code_path) for name, module in sys.modules.items(): - if hasattr(module, "__path__"): + if hasattr(module, '__path__'): module_dir = os.path.join(new_code_path, *name.split(".")) TRACER.log('Adding to the head of %s.__path__: %s' % (module.__name__, module_dir)) - module.__path__.insert(0, module_dir) + try: + module.__path__.insert(0, module_dir) + except AttributeError: + # TODO: This is a temporary bandaid for an unhandled AttributeError which results + # in a startup crash. See https://github.com/pantsbuild/pex/issues/598 for more info. + TRACER.log( + 'Failed to insert %s: %s.__path__ of type %s does not support insertion!' % ( + module_dir, + module.__name__, + type(module.__path__) + ) + ) @classmethod def write_zipped_internal_cache(cls, pex, pex_info):