diff mbox series

[03/18] python3: hide stdout when importing modules during module dependency generation

Message ID 20261125163927.1835785-3-ross.burton@arm.com
State Under Review
Headers show
Series [01/18] python3: fix packaging of libdir/python3.15/config/ | expand

Commit Message

Ross Burton Nov. 25, 2026, 4:39 p.m. UTC
gen_module_deps3.py imports modules and prints to stdout the list of
dependencies. Some modules, such as this.py, also print to stdout. This
results in garbage dependencies, so hide stdout when importing to avoid
this problem.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 meta/recipes-devtools/python/python3/get_module_deps3.py | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/meta/recipes-devtools/python/python3/get_module_deps3.py b/meta/recipes-devtools/python/python3/get_module_deps3.py
index f26d9b20b4b..08c2d28feb7 100644
--- a/meta/recipes-devtools/python/python3/get_module_deps3.py
+++ b/meta/recipes-devtools/python/python3/get_module_deps3.py
@@ -50,11 +50,15 @@  def fix_path(dep_path):
 
 # Module to import was passed as an argument
 current_module =  str(sys.argv[1]).rstrip()
+
 if debug == True:
     log = open('temp/log_%s' % current_module.strip('.*'),'w')
     log.write('Module %s generated the following dependencies:\n' % current_module)
 try:
+    real_stdout = sys.stdout
+    sys.stdout = None
     m = importlib.import_module(current_module)
+
     # handle python packages which may not include all modules in the __init__
     if hasattr(m, '__file__') and os.path.basename(m.__file__) == "__init__.py":
         modulepath = os.path.dirname(m.__file__)
@@ -70,6 +74,8 @@  except ImportError as e:
     if debug == True:
         log.write('Module was not found\n')
     pass
+finally:
+    sys.stdout = real_stdout
 
 
 # Get current module dependencies, dif will contain a list of specific deps for this module