X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=bootstrap.py;h=c445aef59895cda7147bccf556095de3a5c911a0;hb=44a7740bf6fe18673f8636658256a227e0622880;hp=045411ae257116db18b2bb56b61cfe95cd14f762;hpb=aad84a3abe06d127918d09f2ad3b8f4264a9d02b;p=python_utils.git diff --git a/bootstrap.py b/bootstrap.py index 045411a..c445aef 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import functools -import importlib import logging import os from inspect import stack @@ -55,6 +54,7 @@ args.add_argument( original_hook = sys.excepthook + def handle_uncaught_exception(exc_type, exc_value, exc_tb): """ Top-level exception handler for exceptions that make it past any exception @@ -87,7 +87,7 @@ def handle_uncaught_exception(exc_type, exc_value, exc_tb): original_hook(exc_type, exc_value, exc_tb) -class ImportInterceptor(importlib.abc.MetaPathFinder): +class ImportInterceptor(object): def __init__(self): import collect.trie self.module_by_filename_cache = {} @@ -141,10 +141,16 @@ class ImportInterceptor(importlib.abc.MetaPathFinder): return [] -# TODO: test this with python 3.8+ -def audit_import_events(event, args): - print(event) - print(args) +# # TODO: test this with python 3.8+ +# def audit_import_events(event, args): +# if event == 'import': +# module = args[0] +# filename = args[1] +# sys_path = args[2] +# sys_meta_path = args[3] +# sys_path_hooks = args[4] +# logger.debug(msg) +# print(msg) # Audit import events? Note: this runs early in the lifetime of the @@ -158,15 +164,14 @@ def audit_import_events(event, args): import_interceptor = None for arg in sys.argv: if arg == '--audit_import_events': - if not hasattr(sys, 'frozen'): - if ( - sys.version_info[0] == 3 - and sys.version_info[1] < 8 - ): - import_interceptor = ImportInterceptor() - sys.meta_path = [import_interceptor] + sys.meta_path - else: - sys.addaudithook(audit_import_events) + import_interceptor = ImportInterceptor() + sys.meta_path = [import_interceptor] + sys.meta_path + # if not hasattr(sys, 'frozen'): + # if ( + # sys.version_info[0] == 3 + # and sys.version_info[1] >= 8 + # ): + # sys.addaudithook(audit_import_events) def dump_all_objects() -> None: