Skip to content

Commit 7d2e080

Browse files
ctruedenclaude
andcommitted
Fix Tool exec failing on Windows paths with parentheses
When the appose base envs dir contains parentheses (e.g. Fiji(1)/envs), cmd.exe /c misinterprets the parentheses as shell metacharacters, causing pixi.exe invocation to fail and is_installed() to return False. Fix by invoking absolute-path executables directly via subprocess instead of wrapping them in cmd.exe /c -- native .exe files don't need shell wrapping, and bypassing cmd.exe avoids all metacharacter issues. Also improve the "not installed" error message to distinguish between "executable not found" and "executable exists but failed to run", and include the expected path in both cases. As per apposed/appose-java@bc86914 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7212b70 commit 7d2e080

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/appose/tool/__init__.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,17 @@ def exec(self, *args: str, cwd: Path | None = None) -> None:
167167
RuntimeError: If the tool has not been installed.
168168
"""
169169
if not self.is_installed():
170-
raise RuntimeError(f"{self.name} is not installed")
170+
command_path = Path(self.command)
171+
if command_path.is_file():
172+
raise RuntimeError(
173+
f'{self.name} is installed at "{self.command}"'
174+
" but could not be run -- the path may contain characters"
175+
" that are special to the shell (e.g. parentheses on Windows)"
176+
)
177+
raise RuntimeError(
178+
f"{self.name} is not installed"
179+
f' (expected executable at "{self.command}")'
180+
)
171181

172182
self._do_exec(cwd=cwd, silent=False, include_flags=True, args=args)
173183

@@ -278,8 +288,16 @@ def _do_exec(
278288
self._captured_output.clear()
279289
self._captured_error.clear()
280290

281-
# Build command
282-
cmd = platform.base_command()
291+
# Build command.
292+
# On Windows, cmd.exe /c is needed for shell scripts and PATH resolution,
293+
# but absolute paths to native executables must be invoked directly:
294+
# cmd.exe treats parentheses and other characters as shell metacharacters,
295+
# so a path like C:\Users\foo\Fiji(1)\bin\pixi.exe would be misinterpreted.
296+
cmd = (
297+
[]
298+
if platform.is_windows() and Path(self.command).is_absolute()
299+
else platform.base_command()
300+
)
283301
cmd.append(self.command)
284302
if include_flags:
285303
cmd.extend(self._flags)

0 commit comments

Comments
 (0)