Skip to content

Fix Python transforms on Windows (resolve interpreter from PATH candidates) - #116

Merged
ikraamg merged 3 commits into
usetrmnl:mainfrom
vadimitri:windows-python-interpreter
Jun 29, 2026
Merged

Fix Python transforms on Windows (resolve interpreter from PATH candidates)#116
ikraamg merged 3 commits into
usetrmnl:mainfrom
vadimitri:windows-python-interpreter

Conversation

@vadimitri

Copy link
Copy Markdown
Contributor

Problem

Serverless transforms fail on Windows whenever the transform is Python (src/transform.py). Subprocess hardcodes the interpreter command as python3:

INTERPRETERS = {
  'python' => { cmd: 'python3', ext: 'py' },
  ...
}.freeze

The python.org Windows installer provides python.exe and the py launcher but no python3 on PATH (only the Microsoft Store build registers a python3 alias). So Open3.popen3('python3', ...) raises Errno::ENOENT, which surfaces to the user as "interpreter not available", and there's no config to point it at python.

Fix

Make each language's interpreter a list of command candidates in priority order, and run the first one found on PATH:

'python' => { cmds: %w[python3 python], ext: 'py' },

Resolution uses a small cross-platform which that honors PATHEXT on Windows (.EXE/.BAT/…) and bare names on POSIX. Behavior is unchanged on macOS/Linux (python3 still wins); Windows now falls back to python. A genuinely missing interpreter falls back to the first candidate, so the existing "interpreter not available" error path is preserved.

No new dependencies, no config knobs — transforms just work across platforms.

Tests

  • Updated the existing PATH-failure spec to the new cmds: shape.
  • Added a spec proving candidate fallback: first candidate missing → next one runs.

bundle exec rspec spec/lib/trmnlp/transform_backend/subprocess_spec.rb passes (the unrelated php example needs php installed locally); rubocop clean on both files.

vadimitri and others added 3 commits June 29, 2026 20:43
The local transform subprocess backend hardcoded `python3` as the Python
interpreter. On Windows the python.org installer provides `python` and the
`py` launcher but no `python3` on PATH, so every Python transform failed
with "interpreter not available" (Errno::ENOENT).

INTERPRETERS now lists command candidates per language in priority order,
and the backend runs the first one found on PATH via a small cross-platform
`which` that honors PATHEXT on Windows and bare names on POSIX. Python
resolves `python3` first, then `python`, so existing POSIX setups are
unchanged while Windows works out of the box. A missing interpreter still
falls back to the first candidate so the "not available" error is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The Windows fix shipped python3-then-python candidates, but the python.org
installer also registers the `py` launcher and keeps it on PATH even when the
optional "Add to PATH" step is skipped. Add `py` as a final candidate so
Python transforms resolve in that install too.

Move the PATH lookup out of Subprocess into TransformBackend::Which.
Resolution is a separate responsibility and was previously reachable only by
spawning a real interpreter; on its own it is unit-tested directly.

Bump the version to 0.8.10 to match the CHANGELOG entry for this fix.
@ikraamg
ikraamg merged commit a9dce22 into usetrmnl:main Jun 29, 2026
3 checks passed
@trmnl-bot

trmnl-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

👋 Thanks for contributing, @vadimitri!

TRMNL operates a Creator Fund that pays a revenue share to OSS contributors.
We couldn't find a TRMNL account linked to @vadimitri — if you have one, add your GitHub username at https://trmnl.com/account.

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