From 5ab14f1e4efa3f4e21a5d6618597af50cefb46e2 Mon Sep 17 00:00:00 2001 From: Andrej Date: Wed, 28 May 2025 16:55:21 +0500 Subject: [PATCH] Fix Ruff UP022 (replace-stdout-stderr) https://docs.astral.sh/ruff/rules/replace-stdout-stderr/ --- src/bonsai/bonsai/tool/ifcgit.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/bonsai/bonsai/tool/ifcgit.py b/src/bonsai/bonsai/tool/ifcgit.py index 6b1c8c309d..6cf4760c4d 100644 --- a/src/bonsai/bonsai/tool/ifcgit.py +++ b/src/bonsai/bonsai/tool/ifcgit.py @@ -564,7 +564,7 @@ class IfcGit: """Command to install Git on Windows using winget""" command = ["winget", "install", "--id", "Git.Git", "-e", "--source", "winget"] try: - subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + subprocess.check_output(command) except subprocess.CalledProcessError as e: operator.report({"ERROR"}, f"Called Process Error occurred: {e}") except FileNotFoundError: @@ -577,21 +577,20 @@ class IfcGit: ifc_str = ifc_file.to_string() # Avoid `text=True` as it's causing issues with colorful output. - result = subprocess.run( - ("git", "diff", "--no-index", "--color=always", "--", path, "-"), - input=ifc_str.encode(), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - if result.returncode == 0: - operator.report({"INFO"}, "No changes since last save.") - return - elif result.returncode == 1: - print(result.stdout.decode()) - operator.report({"INFO"}, "See system console for git diff output.") - return - print(result) - raise Exception("Error running git diff, see system console.") + try: + subprocess.check_output( + ("git", "diff", "--no-index", "--color=always", "--", path, "-"), + input=ifc_str.encode(), + ) + except subprocess.CalledProcessError as e: + if e.returncode == 1: + print(e.stdout.decode()) + operator.report({"INFO"}, "See system console for git diff output.") + return + print(e.output) + raise Exception("Error running git diff, see system console.") + + operator.report({"INFO"}, "No changes since last save.") class IfcGitRepo: