Skip to content

🧹 [Code Health Improvement] Refactor subprocess.run usage in TextureProcessor#101

Open
skurtyyskirts wants to merge 1 commit into
mainfrom
jules/refactor-texture-processor-subprocess-2691061646176015901
Open

🧹 [Code Health Improvement] Refactor subprocess.run usage in TextureProcessor#101
skurtyyskirts wants to merge 1 commit into
mainfrom
jules/refactor-texture-processor-subprocess-2691061646176015901

Conversation

@skurtyyskirts

Copy link
Copy Markdown
Owner

🎯 What: Extracted the platform-specific subprocess boilerplate (STARTUPINFO, CREATE_NO_WINDOW) into a reusable static method _run_subprocess in TextureProcessor.
💡 Why: Improves readability and maintainability by deduplicating the setup code for texconv and Blender commands, while maintaining proper platform handling for Windows window suppression.
✅ Verification: Ran the full unittest suite (python3 -m unittest discover tests), which includes mocks verifying the correct handling of success, failures, and timeouts.
✨ Result: texture_processor.py is cleaner, DRYer, and maintains all functional requirements for texture conversion and auto-unwrapping.


PR created automatically by Jules for task 2691061646176015901 started by @skurtyyskirts

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors TextureProcessor to centralize platform-specific subprocess.run setup (Windows window suppression flags) into a reusable helper, reducing duplicated boilerplate for texconv and Blender command execution.

Changes:

  • Added TextureProcessor._run_subprocess(...) to encapsulate startupinfo / creationflags and consistent subprocess.run arguments.
  • Updated convert_dds_to_png and unwrap_mesh_with_blender to call the new helper instead of inlining the subprocess configuration.

Comment thread texture_processor.py
Comment on lines 105 to +108
try:
startupinfo, creationflags = None, 0
if sys.platform == "win32":
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
creationflags = subprocess.CREATE_NO_WINDOW

try:
result = subprocess.run(
command, capture_output=True, text=True, check=False,
startupinfo=startupinfo, creationflags=creationflags,
encoding='utf-8', errors='ignore',
timeout=TEXCONV_TIMEOUT_SECONDS,
)
except subprocess.TimeoutExpired:
raise RuntimeError(f"texconv timed out after {TEXCONV_TIMEOUT_SECONDS}s on {self.safe_basename(dds_file)}")

if result.returncode != 0:
stdout = (result.stdout or "").strip()
stderr = (result.stderr or "").strip()
err_msg = (
f"texconv failed (Code {result.returncode}). "
f"Stdout: {stdout} "
f"Stderr: {stderr}"
)
self._log_error(err_msg)
raise RuntimeError(err_msg)

if not os.path.exists(expected_output_path):
raise RuntimeError(f"texconv reported success but output missing: {expected_output_path}")

return expected_output_path
except RuntimeError:
raise
except Exception as e:
raise RuntimeError(f"Error running texconv: {e}")
result = self._run_subprocess(command, TEXCONV_TIMEOUT_SECONDS)
except subprocess.TimeoutExpired:
raise RuntimeError(f"texconv timed out after {TEXCONV_TIMEOUT_SECONDS}s on {self.safe_basename(dds_file)}")
Comment thread texture_processor.py
Comment on lines 169 to +173
try:
startupinfo, creationflags = None, 0
if sys.platform == "win32":
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
creationflags = subprocess.CREATE_NO_WINDOW

try:
result = subprocess.run(
command, capture_output=True, text=True, check=False,
startupinfo=startupinfo, creationflags=creationflags,
encoding='utf-8', errors='ignore',
timeout=BLENDER_TIMEOUT_SECONDS,
)
except subprocess.TimeoutExpired:
self._log_error(f"Blender unwrap timed out after {BLENDER_TIMEOUT_SECONDS}s.")
self._display_message("Error: Blender auto-unwrap timed out.")
return None

stderr_text = result.stderr or ""
if result.returncode != 0 or "Error: Python script fail" in stderr_text:
self._log_error(f"Blender failed (Code {result.returncode}). Stderr: {stderr_text}")
detail = self._truncate(stderr_text) or f"exit code {result.returncode}"
self._display_message(f"Blender auto-unwrap failed: {detail}")
return None

if os.path.exists(output_mesh_path):
self._log_info(f"Blender unwrap success: {output_mesh_path}")
return output_mesh_path

self._log_error("Blender finished but output missing.")
result = self._run_subprocess(command, BLENDER_TIMEOUT_SECONDS)
except subprocess.TimeoutExpired:
self._log_error(f"Blender unwrap timed out after {BLENDER_TIMEOUT_SECONDS}s.")
self._display_message("Error: Blender auto-unwrap timed out.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants