From a1e290350f1eac36217fe01d396b90024f8f97ae Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Fri, 4 Aug 2023 13:30:36 -0700 Subject: [PATCH] Enable deprecation warnings on external code edk2 invocables consume and execute external code. This includes the settings file and the plugins. These changes enable deprecation warnings for those imported modules so that developers can see when they are using deprecated code. --- edk2toolext/edk2_invocable.py | 4 ++++ edk2toolext/environment/plugin_manager.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/edk2toolext/edk2_invocable.py b/edk2toolext/edk2_invocable.py index 36fd5bda..41e3b2f2 100644 --- a/edk2toolext/edk2_invocable.py +++ b/edk2toolext/edk2_invocable.py @@ -21,6 +21,7 @@ import logging import os import sys +import warnings from random import choice from string import ascii_letters from textwrap import dedent @@ -391,6 +392,9 @@ def ParseCommandLineOptions(self): print(e) sys.exit(2) + # Turn on Deprecation warnings for code in the module + warnings.filterwarnings("default", category=DeprecationWarning, module=self.PlatformModule.__name__) + # instantiate the second argparser that will get passed around parserObj = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,) diff --git a/edk2toolext/environment/plugin_manager.py b/edk2toolext/environment/plugin_manager.py index ffb2c5a1..a016c7d7 100644 --- a/edk2toolext/environment/plugin_manager.py +++ b/edk2toolext/environment/plugin_manager.py @@ -11,6 +11,7 @@ import logging import os import sys +import warnings from edk2toolext.environment import shell_environment @@ -101,6 +102,9 @@ def _load(self, PluginDescriptor): if py_module_dir not in sys.path: sys.path.append(py_module_dir) + # Turn on Deprecation warnings for code in the plugin + warnings.filterwarnings("default", category=DeprecationWarning, module=module.__name__) + spec.loader.exec_module(module) except Exception: exc_info = sys.exc_info()