🧹 [Code Health Improvement] Refactor subprocess.run usage in TextureProcessor#101
Conversation
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
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 encapsulatestartupinfo/creationflagsand consistentsubprocess.runarguments. - Updated
convert_dds_to_pngandunwrap_mesh_with_blenderto call the new helper instead of inlining the subprocess configuration.
| 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)}") |
| 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.") |
🎯 What: Extracted the platform-specific subprocess boilerplate (STARTUPINFO, CREATE_NO_WINDOW) into a reusable static method
_run_subprocessinTextureProcessor.💡 Why: Improves readability and maintainability by deduplicating the setup code for
texconvandBlendercommands, 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.pyis cleaner, DRYer, and maintains all functional requirements for texture conversion and auto-unwrapping.PR created automatically by Jules for task 2691061646176015901 started by @skurtyyskirts