From 5b87769e2e02da9419d7e765fc805e7903b55a0d Mon Sep 17 00:00:00 2001 From: Mathieu Benoit Date: Wed, 26 Nov 2025 22:20:43 -0500 Subject: [PATCH] [UPD] script replace subprocess.check_output to subprocess.run --- .../transform_python_to_code_writer.py | 10 ++++++---- script/database/db_drop_all.py | 10 ++++++++-- script/maintenance/format_file_to_commit.py | 16 +++++++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/script/code_generator/transform_python_to_code_writer.py b/script/code_generator/transform_python_to_code_writer.py index d60ac6a..7f80723 100755 --- a/script/code_generator/transform_python_to_code_writer.py +++ b/script/code_generator/transform_python_to_code_writer.py @@ -74,13 +74,15 @@ def main(): no_tab = 0 # Validate file format - out = subprocess.check_output( + out = subprocess.run( f"python -m tabnanny {config.file}", - stderr=subprocess.STDOUT, shell=True, + capture_output=True, + text=True, ) - if out: - print(out) + result = (out.stdout or "") + (out.stderr or "") + if result: + print(result) sys.exit(1) # with tokenize.open(config.file) as f: diff --git a/script/database/db_drop_all.py b/script/database/db_drop_all.py index ed0fd77..ecd9b27 100755 --- a/script/database/db_drop_all.py +++ b/script/database/db_drop_all.py @@ -12,8 +12,14 @@ _logger = logging.getLogger(__name__) def execute_shell(cmd): - out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) - return out.decode().strip() if out else "" + result = subprocess.run( + cmd, + shell=True, + capture_output=True, + text=True, + ) + output = (result.stdout or "") + (result.stderr or "") + return result.returncode, output.strip() def get_config(): diff --git a/script/maintenance/format_file_to_commit.py b/script/maintenance/format_file_to_commit.py index 27862a5..ad8d3d5 100755 --- a/script/maintenance/format_file_to_commit.py +++ b/script/maintenance/format_file_to_commit.py @@ -4,14 +4,21 @@ import os import subprocess +import sys IGNORE_EXTENSION = [] IGNORE_FILE_NAME = ["Makefile"] def execute_shell(cmd): - out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) - return out.decode().strip() if out else "" + result = subprocess.run( + cmd, + shell=True, + capture_output=True, + text=True, + ) + output = (result.stdout or "") + (result.stderr or "") + return result.returncode, output.strip() def get_modified_files(): @@ -152,4 +159,7 @@ if __name__ == "__main__": has_file = True if has_file: print(cmd_format) - execute_shell(cmd_format) + status, output = execute_shell(cmd_format) + if status != 0: + print(output) + sys.exit(status)