From 52a29c26d7c12fcac8c86d20513b7e4190541a31 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Sat, 17 Oct 2020 15:01:21 -0300 Subject: [PATCH] Implemented `de_activate` in mcpyrate.activate This disables macros after loading the plug-ins. Now the timing is 160 ms, 30% faster than `mcpy` and 4 times faster than `macropy` --- kibot/mcpyrate/activate.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/kibot/mcpyrate/activate.py b/kibot/mcpyrate/activate.py index f1893b81..1ffe2612 100644 --- a/kibot/mcpyrate/activate.py +++ b/kibot/mcpyrate/activate.py @@ -26,10 +26,23 @@ the `PYTHONDONTWRITEBYTECODE` environment variable, and the attribute ''' from importlib.machinery import SourceFileLoader, FileFinder - from .importer import source_to_xcode, path_xstats, invalidate_xcaches -SourceFileLoader.source_to_code = source_to_xcode -# we could replace SourceFileLoader.set_data with a no-op to force-disable pyc caching. -SourceFileLoader.path_stats = path_xstats -FileFinder.invalidate_caches = invalidate_xcaches + +def activate(): + SourceFileLoader.source_to_code = source_to_xcode + # we could replace SourceFileLoader.set_data with a no-op to force-disable pyc caching. + SourceFileLoader.path_stats = path_xstats + FileFinder.invalidate_caches = invalidate_xcaches + + +def de_activate(): + SourceFileLoader.source_to_code = old_source_to_code + SourceFileLoader.path_stats = old_path_stats + FileFinder.invalidate_caches = old_invalidate_caches + + +old_source_to_code = SourceFileLoader.source_to_code +old_path_stats = SourceFileLoader.path_stats +old_invalidate_caches = FileFinder.invalidate_caches +activate()