From 317f565685c4d63b26d315cc77f74afcb65a525b Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Sun, 30 Apr 2023 08:28:22 +0100 Subject: [PATCH] Core: Renable the import protection for volatility3.framework.plugins In commit 21d916b (about 10 months ago) the logic for the warning about volatility3.framework importing was disabled. This re-enables it. Also updates to support pyinstaller 5.10 function stack depth. Closes #944 --- volatility3/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/volatility3/__init__.py b/volatility3/__init__.py index 28df7da5a..94a6721e1 100644 --- a/volatility3/__init__.py +++ b/volatility3/__init__.py @@ -38,10 +38,13 @@ class WarningFindSpec(abc.MetaPathFinder): """Mock find_spec method that just checks the name, this must go first.""" if fullname.startswith("volatility3.framework.plugins."): - warning = "Please do not use the volatility3.framework.plugins namespace directly, only use volatility3.plugins" + warning = f"Import {fullname}: Please do not use the volatility3.framework.plugins namespace directly, only use volatility3.plugins" # Pyinstaller uses walk_packages/_collect_submodules to import, but needs to read the modules to figure out dependencies # As such, we only print the warning when directly imported rather than from within walk_packages/_collect_submodules - if inspect.stack()[-2].function in ["walk_packages", "_collect_submodules"]: + if inspect.stack()[-2].function not in [ + "walk_packages", + "_collect_submodules", + ] and inspect.stack()[-3].function not in ["_collect_submodules"]: raise Warning(warning)