Fix Ruff UP022 (replace-stdout-stderr)

https://docs.astral.sh/ruff/rules/replace-stdout-stderr/
This commit is contained in:
Andrej
2025-05-28 16:55:21 +05:00
parent f289b55766
commit 5ab14f1e4e
+9 -10
View File
@@ -564,7 +564,7 @@ class IfcGit:
"""Command to install Git on Windows using winget""" """Command to install Git on Windows using winget"""
command = ["winget", "install", "--id", "Git.Git", "-e", "--source", "winget"] command = ["winget", "install", "--id", "Git.Git", "-e", "--source", "winget"]
try: try:
subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) subprocess.check_output(command)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
operator.report({"ERROR"}, f"Called Process Error occurred: {e}") operator.report({"ERROR"}, f"Called Process Error occurred: {e}")
except FileNotFoundError: except FileNotFoundError:
@@ -577,22 +577,21 @@ class IfcGit:
ifc_str = ifc_file.to_string() ifc_str = ifc_file.to_string()
# Avoid `text=True` as it's causing issues with colorful output. # Avoid `text=True` as it's causing issues with colorful output.
result = subprocess.run( try:
subprocess.check_output(
("git", "diff", "--no-index", "--color=always", "--", path, "-"), ("git", "diff", "--no-index", "--color=always", "--", path, "-"),
input=ifc_str.encode(), input=ifc_str.encode(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
) )
if result.returncode == 0: except subprocess.CalledProcessError as e:
operator.report({"INFO"}, "No changes since last save.") if e.returncode == 1:
return print(e.stdout.decode())
elif result.returncode == 1:
print(result.stdout.decode())
operator.report({"INFO"}, "See system console for git diff output.") operator.report({"INFO"}, "See system console for git diff output.")
return return
print(result) print(e.output)
raise Exception("Error running git diff, see system console.") raise Exception("Error running git diff, see system console.")
operator.report({"INFO"}, "No changes since last save.")
class IfcGitRepo: class IfcGitRepo:
repo: git.Repo = None repo: git.Repo = None