From 5b9c8feba6fd867db93d218ae19f9f7ba2038d37 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Fri, 17 Jan 2020 02:14:22 +0000 Subject: [PATCH] General: Improve import warning for volatility.framework.plugins --- volatility/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/volatility/__init__.py b/volatility/__init__.py index 3377edcce..5b70678c8 100644 --- a/volatility/__init__.py +++ b/volatility/__init__.py @@ -2,6 +2,7 @@ # which is available at https://www.volatilityfoundation.org/license/vsl-v1.0 # """Volatility 3 - An open-source memory forensics framework""" +import inspect import sys from importlib import abc from typing import List, TypeVar, Callable, Any, Optional @@ -36,9 +37,9 @@ class WarningFindSpec(abc.MetaPathFinder): first.""" if fullname.startswith("volatility.framework.plugins."): warning = "Please do not use the volatility.framework.plugins namespace directly, only use volatility.plugins" - # Pyinstaller uses pkgutil to import, but needs to read the modules to figure out dependencies - # As such, we only print the warning when directly imported rather than being run from a script - if 'pkgutil' not in sys.modules: + # Pyinstaller uses walk_packages 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 + if inspect.stack()[-2].function != 'walk_packages': raise Warning(warning)