Skip to content

fix: quote the default {python} run substitution for the shell - #797

Open
yarikoptic-gitmate wants to merge 2 commits into
mainfrom
claude/sharp-cori-nnzq30-run-python-quote
Open

yarikoptic-gitmate wants to merge 2 commits into
mainfrom
claude/sharp-cori-nnzq30-run-python-quote

Conversation

@yarikoptic-gitmate

Copy link
Copy Markdown
Collaborator

datalad run '{python} -c "True"' fails with exit code 127 when the interpreter path contains a space. Examples are hatch's environments under ~/Library/Application Support/... on macOS, or C:\Program Files\... on Windows.

run hands the formatted command to the shell as one string, but the default of datalad.run.substitutions.python was the bare sys.executable, so the shell split the path. This showed in the new GitHub workflow's macOS job as a test_substitution_config_default failure. #796 worked around it there by setting HATCH_DATA_DIR, as AppVeyor does.

Changes

  • fix: patches/run.py: the default is now quote_cmdlinearg(sys.executable), as format_command() already does for {inputs}/{outputs}, and as core's run_procedure does for sys.executable.
    • On POSIX that is shlex.quote(), a no-op for paths without special characters.
    • On Windows it is double quotes, since cmd.exe runs the string.
    • Values that users configure are still inserted verbatim, like any substitution. The config's description now says so.
  • ci: .github/workflows/test.yml: drops the now-stale reason given for HATCH_DATA_DIR. The variable is still set, because .appveyor.yml sets it on all three platforms.

Behaviour change

Commands that worked around the bug by writing "{python}" in quotes now get the default quoted twice. That includes run records re-executed by rerun.

  • POSIX: such a command now fails for an interpreter path that needs quoting, where it worked before.
  • Windows: the default is always double-quoted, so such a command gets doubled quotes, which cmd.exe may not run.

Testing

  • test_substitution_config_default fails on main and passes with this PR, run from a venv under a path with a space. CI has no such path.
  • cz check is clean.

Three independent AI reviewers approved this change.


Generated by Claude Code

@yarikoptic-gitmate yarikoptic-gitmate added the semver-patch PR implies patch-level version increment (API stable) label Nov 10, 2026 — with Claude
yarikoptic and others added 2 commits November 11, 2026 09:22
`run` hands the formatted command to the shell as a single string, but
the default value of `datalad.run.substitutions.python` was the bare
`sys.executable`.  An interpreter path containing a space (e.g. hatch's
"~/Library/Application Support/..." on macOS, or "C:\Program Files\..."
on Windows) was split by the shell, and the command failed with exit
code 127.

Quote the default with `quote_cmdlinearg()`, as `format_command()`
already does for `{inputs}` and `{outputs}`: `shlex.quote()` on POSIX
(a no-op for paths without special characters), double quotes on
Windows, where the string is run by cmd.exe.  Values that users
configure are still inserted verbatim, like any other substitution,
hence are not double-quoted.

Commands that worked around the bug by putting `{python}` in double
quotes themselves now get the default quoted twice; this includes run
records that `rerun` executes again.  On POSIX, such a command now
fails for an interpreter path that needs quoting, where it worked
before.  On Windows, where the default is always double-quoted, it now
gets doubled quotes, which cmd.exe may not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PvaGRXnrnSEHAKqfFZHw7Z
With the default `{python}` substitution quoted, a space in the path of
hatch's environments ("~/Library/Application Support" on macOS) no
longer breaks `run`.  HATCH_DATA_DIR is still set as on AppVeyor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PvaGRXnrnSEHAKqfFZHw7Z
@yarikoptic
yarikoptic force-pushed the claude/sharp-cori-nnzq30-run-python-quote branch from 575b118 to e7d4aa1 Compare November 11, 2026 14:22
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.53%. Comparing base (0bd6181) to head (e7d4aa1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #797      +/-   ##
==========================================
- Coverage   90.89%   90.53%   -0.36%     
==========================================
  Files         182      182              
  Lines       12218    12218              
  Branches     1252     1252              
==========================================
- Hits        11105    11062      -43     
- Misses        869      894      +25     
- Partials      244      262      +18     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver-patch PR implies patch-level version increment (API stable)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants