Skip to content

fix: use sys.version_info instead of platform.python_version() in conda decorator#3177

Merged
npow merged 1 commit intomasterfrom
fix/conda-forge-python-version-parse
May 6, 2026
Merged

fix: use sys.version_info instead of platform.python_version() in conda decorator#3177
npow merged 1 commit intomasterfrom
fix/conda-forge-python-version-parse

Conversation

@npow
Copy link
Copy Markdown
Collaborator

@npow npow commented May 6, 2026

Summary

  • Replace platform.python_version() with "%d.%d.%d" % sys.version_info[:3] in conda_decorator.py
  • Remove unused import platform

Problem

On Python 3.10 installed from conda-forge, sys.version contains | packaged by conda-forge | (e.g., 3.10.20 | packaged by conda-forge | (main, Mar 5 2026, 16:53:43) [GCC 14.3.0]).

Python 3.10's platform.py stdlib uses a regex that can't parse this format, causing:

ValueError: failed to parse CPython sys.version: '3.10.20 | packaged by conda-forge | ...'

This crashes any @conda/@pypi/@pypi_base decorated flow during decorator init on conda-forge Python 3.10. The regex was fixed in CPython 3.11+ but never backported to 3.10.

Fix

sys.version_info is a struct_sequence populated at interpreter startup — it doesn't parse sys.version at all, so it works regardless of the version string format.

Test plan

  • Verified "%d.%d.%d" % sys.version_info[:3] produces identical output to platform.python_version() on standard CPython
  • Verified the old regex fails on conda-forge version strings (Python 3.10)
  • Verified sys.version_info is unaffected by conda-forge's sys.version format

🤖 Generated with Claude Code

platform.python_version() calls platform._sys_version() which parses
sys.version with a regex. On Python 3.10 from conda-forge, sys.version
contains '| packaged by conda-forge |' which the 3.10 regex can't
handle (fix was only in 3.11+). This causes a ValueError during
@conda/@pypi decorator init on any conda-forge Python 3.10 environment.

sys.version_info is a struct_sequence populated at interpreter startup
and doesn't require parsing sys.version.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 6, 2026

Greptile Summary

Fixes a crash in @conda/@pypi/@pypi_base decorated flows on Python 3.10 installed from conda-forge, where platform.python_version() raises a ValueError due to a regex in platform.py that cannot parse conda-forge's extended sys.version string (e.g. 3.10.20 | packaged by conda-forge | ...). The fix was never backported to 3.10 in CPython.

  • Replaces platform.python_version() with "%d.%d.%d" % sys.version_info[:3], which reads pre-parsed integers directly from the interpreter and produces identical output on all CPython builds.
  • Removes the now-unused import platform.

Confidence Score: 5/5

Safe to merge — the one-line fix is a well-understood substitution with no behavioural change on standard CPython and a clear improvement on conda-forge Python 3.10.

The change is a single-site substitution that produces byte-for-byte identical output on every standard CPython build and avoids a documented crash on conda-forge 3.10. The removed import was genuinely unused after the change, and no other call sites for platform remain in the file.

No files require special attention.

Important Files Changed

Filename Overview
metaflow/plugins/pypi/conda_decorator.py Replaces platform.python_version() with "%d.%d.%d" % sys.version_info[:3] to avoid a Python 3.10 regex parse failure on conda-forge version strings; removes the now-unused import platform.

Reviews (1): Last reviewed commit: "fix: use sys.version_info instead of pla..." | Re-trigger Greptile

@npow npow merged commit b9342c2 into master May 6, 2026
45 checks passed
@npow npow deleted the fix/conda-forge-python-version-parse branch May 6, 2026 17:05
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